[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,
2980 0
|
5月前
|
PyTorch 算法框架/工具 机器学习/深度学习
|
机器学习/深度学习 Windows
raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}‘.format( RuntimeError: Error(s)..报错
即load_state_dict(fsd,strict=False) 属性strict;当strict=True,要求预训练练权重层数的键值与新构建的模型中的权重层数名称完全吻合;
1567 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
934 0
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2731 0
|
Python
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
650 0
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
286 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
469 0
|
Python
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
完美解决 TypeError: Invalid shape (3, 224, 224) for image data
933 0
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects