[AssertionError: nput tensor input format are different]

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

问题描述


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数据了

目录
相关文章
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
2589 0
|
1月前
|
Linux Windows
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
|
8月前
|
算法框架/工具
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
122 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
723 0
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
272 0
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2497 0
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
241 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for
解决AssertionError: size of input tensor and input format are different.tensor shape: (3, 138input_for
334 0
|
Python
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
714 0
|
Linux Python
ValueError: empty range for randrange() (0, 0, 0)
ValueError: empty range for randrange() (0, 0, 0)