Tensorflow合并尺寸和反向合并

Dec*_*HAN 5 python tensorflow

假设我有一个张量形状[3, 5, 200, 300, 3]。我怎样才能合并前两个暗淡在一起,以便我有张量的形状[15, 200, 300, 3]。然后,我可以反向合并操作并具有原始形状。

Ish*_*nal 3

你可以使用tf.reshape

a = tf.random_normal(shape=(3, 5, 200, 300, 3))
b = tf.reshape(a, shape=(15, 200, 300, 3))
...
c = tf.reshape(b, shape=(3, 5, 200, 300, 3))
Run Code Online (Sandbox Code Playgroud)

  • 当我们不知道确切的形状时,有没有办法改变维数?(或者我们应该调用 tf.reshape 并将 tf.shape 放入其中?) (4认同)