0
点赞
收藏
分享

微信扫一扫

成功解决[AssertionError: Input tensor input format are different]


在使用tensorboard writer.add_image时

writer.add_image('img/fixed_img', denorm(fixed_img.data), 0)

报如下错误

assert(len(tensor.shape) == len(input_format)), "size of input tensor and input format are different.

AssertionError: size of input tensor and input format are different. tensor shape: (128, 3, 64, 64), input_format: CHW

从报错信息来看, input tensor的维度是(128, 3, 64, 64),而 input_format的格式需要是 CHW。两者不匹配。

分析到这儿就明白了。input tensor虽然格式也是CHW, 但它还有一个batch维度,所以报错。

add_image只接收单一图像,你给它传一个batch数据自然是不行的

解决办法

add_images 替换add_image。就可以显示batch数据了

有人说,你这也太简单了嘛,还废话那么多。

但是,我更希望分享解决bug的过程,而不是结果。

我是Tina, 我们下篇博客见~

举报

相关推荐

0 条评论