import tensorflow as tf
import numpy as np
p3 = tf.placeholder(tf.float32, [None, 1, 2, 4])
p3_shape = p3.get_shape().as_list()
p_a = tf.contrib.layers.flatten(p3)
p_b = tf.reshape(p3, [-1, p3_shape[1] * p3_shape[2] * p3_shape[3]])
p_c = tf.reshape(p3, [tf.shape(p3)[0], -1])
print(p_a.get_shape())
print(p_b.get_shape())
print(p_c.get_shape())
with tf.Session() as sess:
i_p3 = np.arange(16, dtype=np.float32).reshape([2, 1, 2, 4])
print("a", sess.run(p_a, feed_dict={p3: i_p3}))
print("b", sess.run(p_b, feed_dict={p3: i_p3}))
print("c", sess.run(p_c, feed_dict={p3: i_p3}))
Here you can see, the above code yields the same result 3 times. But different results here are caused by something else, not by the reshaping.