Odiel_Hooybergs:

re them automatically. so you still have to assign it yourself.


Yes. tf.Tensor objects are immutable.
    for img_idx in range(num_images):
      # print(tf.rank(out))
      for j in range(0, h_in, self.stride):
        for k in range(0, w_in, self.stride):
            ...
            for ch in range*(...):
                out = tf.tensor_scatter_nd_update(...)

Ouch, a quadruple loop.
Remember TensorFlow is way more efficient if you can express things in vectorized terms.
If there’s any way to make the self.quantum_circuit run on a batch of items, you should consider using tf.image.extract_patches and then run this once over the batch of patches. tf.map_fn or tf.vectorized_map may do it.
Similarly, out = tf.tensor_scatter_nd_update(out, ...) makes a complete copy of the image, for each color channel of each pixel. Ooof. tf.map_fn or tf.vectorized_map would address this too, as it collects all the results, and then stacks them.

  
      

      TensorFlow
  

  
    

tf.map_fn  |  TensorFlow Core v2.7.0 1

  Transforms elems by applying fn to each element unstacked on axis 0. (deprecated arguments)


  

  
    
    
  

  


  
      

      TensorFlow
  

  
    

tf.vectorized_map  |  TensorFlow Core v2.7.0 2

  Parallel map on the list of tensors unpacked from elems on dimension 0.