如何在张量流中将4-D张量填充到相同形状的其他形状?

时间:2017-07-13 14:19:30

标签: tensorflow concat

 builtins.ValueError: Dimension 0 in both shapes must be equal,
 but are 13 and 14 for 'concat' (op: 'ConcatV2') with input shapes:   
 [4,13,17,512], [4,14,18,512], [] and with computed 
 input tensors: input[2] = <0>.

正如您所见,concat2 = tf.concat([conv5_1, deconv5], axis = 0)导致上述错误,我不知道如何解决它,有人帮忙吗?非常感谢!

1 个答案:

答案 0 :(得分:0)

你的张量必须大小相同才能连接它们,这就是你得到它的原因。

有一些选项可以使张量相同,但要确保它们对您使用的数据有意义并且不会导致信息丢失:

  1. 使用tf.image.resize_images

  2. 将一个张量重塑为另一个张量的大小
  3. 使用tf.pad填充两个张量,使它们的大小相同。这是有风险的,因为当您连接它们时,某些堆叠值可能不代表相同的信息。

  4. 最后,您可以使用tf.image.crop_to_bounding_box将较大的张量裁剪为较小张量的尺寸。对于你的情况,这也许不是一个好主意,因为你的张量尺寸偏差值为1,所以你不会集中裁剪。