【问题标题】:Reshaping of a tensor with adaptive shape results in unexpected resulting shape使用自适应形状重塑张量会导致意外的形状
【发布时间】:2019-06-04 13:12:29
【问题描述】:

我正在尝试用形状 (?, 32, 32, 64) 重塑张量。 生成的张量应该类似于 (? * 32 * 32, 64)。 Tensorflow 给了我类似 (?, ?) 的东西,这在我看来是出乎意料的,因为最后一个轴的维度定义明确。

def function(x):
    shape = tf.shape(x)
    x = tf.reshape(x, (shape[0] * shape[1] * shape[2], shape[3]))

重新整形 (?, 32, 32, 64) 得到 (?,?)

有没有办法解决这个问题? 非常感谢!

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    我相信这是因为您正在使用 tf.shape(x) 返回动态形状。如果您使用 x.get_shape() 这应该返回静态形状。但是,您需要提供或定义批量大小才能执行整形操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多