I had an incompatibility issue with PyTorch
tensor shape. Hence, I need to convert one tensor from shape [24, 512, 768, 1]
to [24, 512, 14, 14]
.
What is the best way while trying to preserve as much info as possible about the original tensor representation?
CodePudding user response:
I think this is an optimal solution, regardless of the data preservation you want to include:
import tensorflow as tf
t = tf.constant([[[[1]]*768]*512]*24)
t = tf.reshape(tf.constant(t.numpy()[:, :, :196]), (24, 512, 14, 14))
print(t.shape)
Output:
(24, 512, 14, 14)