-1

I currently have following tensor with dimensions [batch_size, channel, width, height] but I want to add one dimension to the above tensors at third index as [batch_size, channel, length, width, height] where length is the dimension that I want to add into my tensor. Length value will be defined as the no_of_iterations for batch size. Can you please tell me how should I add need dimension and set its value.

Barış Çiçek
  • 341
  • 2
  • 12
anonymous
  • 11
  • 1
  • 3
  • https://www.tensorflow.org/api_docs/python/tf/expand_dims, this may help – Sanchit.Jain Nov 06 '20 at 07:20
  • 2
    Is this a PyTorch or a TensorFlow question ? In PyTorch, It's quite easy to do. In TensorFlow, I'm no expert, but I think it's a much harder task to perform this dynamically. – Joseph Budin Nov 06 '20 at 08:48
  • 1
    Please, be more specific w.r.t. the framework of interest and avoid using irrelevant tags. – Berriel Nov 06 '20 at 13:20

1 Answers1

0

You could not modify your batch dynamically like that. You can hand on with static tensor only. Therefore, you have to make your tensor static at first. Then, you can accumulate the dimension by using tf.expand_dims and choose the axis that you want to expand. Here is 2 as the axis for length.

However, expand_dims just have you to create a dimension. Then you have to duplicate the tensor and tf.concatenate the tensor by axis=2.

However, I want to give you some suggestion, I think you just need to add a loop for each batch training that you want to do inside each epoch. That will be easier and handy than modify tensor like this and reduce the complexity for high dimensions

dtlam26
  • 1,410
  • 11
  • 19