1

I have an image tensor of the following dimensions

TensorShape([Dimension(1), Dimension(96), Dimension(96), Dimension(3)])

I want this tensor to be in following channel first dimension

TensorShape([Dimension(1), Dimension(2), Dimension(96), Dimension(96)])

I have tried

tf.transpose (image, perm = [0,3,1,2])

but it did not work It is returning in the same as previous.

Since, this is the requirement of Facenet algorithm , please suggest the way to do it.

James Z
  • 12,209
  • 10
  • 24
  • 44
  • You can't just reshape, this will return invalid values. E.g. if your input was [[1,2,3],[4,5,6]], there is a big difference between transposing ([[1,4],[2,5],[3,6]]) and simple reshaping ([[1,2],[3,4],[5,6]]). However I suspect that OP isn't using transpose correctly since it should be doing the job. Please provide a more complete code sample. – xdurch0 May 20 '18 at 15:18
  • Possible duplicate of [Convert between NHWC and NCHW in TensorFlow](https://stackoverflow.com/questions/37689423/convert-between-nhwc-and-nchw-in-tensorflow) – P-Gn May 20 '18 at 18:56

1 Answers1

0

You can try to convert the tensor into NumPy array and then use np.rollaxis and convert back to Tensorflow tensor.

rahul kanojia
  • 57
  • 1
  • 6