empty
empty

Reputation: 5444

Reshape Tensor from shape (n, h, w, c) to (n, h * w, c)

Looking at Best way to flatten a 2D tensor containing a vector in TensorFlow? I see how to flatten a 2D tensor to a 1D tensor in TensorFlow but how do I flatten a 4D Tensor to a 3D Tensor with TensorFlow functions?

For example:

import tensorflow as tf
X = tf.random_normal([n, h, w, c], mean=1, stddev=4)
Y = ???

Upvotes: 2

Views: 352

Answers (1)

alkasm
alkasm

Reputation: 23032

The tf.reshape() function should work for you:

Y = tf.reshape(X, (n, h*w, c))

Upvotes: 4

Related Questions