将张量从[24,512,768,1]转换为[24,512,14,14]的最佳方法



我有一个与PyTorch张量形状不兼容的问题。因此,我需要将一个张量从形状[24, 512, 768, 1]转换成[24, 512, 14, 14]。在尽可能多地保留原始张量表示信息的同时,最好的方法是什么?

我认为这是一个最佳的解决方案,无论数据保存你想包括:

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)

输出:

(24, 512, 14, 14)

最新更新