I have a situation where I take a slice of a tf tensor, I convert it to numpy, I do some calculations and finally I want to place this slice back where it came from i.e. the tf tensor. To be specific this is all part of a mini-batch generation / alteration procedure.
mini_batch.shape
would produce the following tensor shape
TensorShape([#samples, 640, 1152, 3])
the np_slice that I process comes from the tensor above
np_slice = mini_batch[sample_index][:, :, 2].numpy()
and I try to re-insert it as such
mini_batch[sample_index][:, :, 2] = tf.convert_to_tensor(np_slice, dtype=tf.float32)
note that np_slice has shape (640, 1152) i.e. a one channel image
As I understand tf does not allow this kind of assignment, hence my error
TypeError: 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment
It would appear that I need to make use of tf.tensor_scatter_nd_update
This is what I tried so far but it does not work as I require
indices = tf.constant([[sample_index]])
updates = tf.convert_to_tensor(np_slice, dtype=tf.float32)
mini_batch = tf.tensor_scatter_nd_update(mini_batch, indices, updates)
Which produces the following
tensorflow.python.framework.errors_impl.InvalidArgumentError: Outer dimensions of indices and update must match. Indices shape: [1,1], updates shape:[640,1152] [Op:TensorScatterUpdate]