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

目录
打赏
0
0
0
0
691
分享
相关文章
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,
3019 0
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
Keras报错:TypeError: (‘Keyword argument not understood:‘, ‘offset‘)
231 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
985 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
299 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决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
669 0
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following
pytorch报错 RuntimeError: The size of tensor a (25) must match the size of tensor b (50) at non-singleton dimension 1 怎么解决?
这个错误提示表明,在进行某个操作时,张量a和b在第1个非单例维(即除了1以外的维度)上的大小不一致。例如,如果a是一个形状为(5, 5)的张量,而b是一个形状为(5, 10)的张量,则在第二个维度上的大小不匹配。
4426 0
解决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
491 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等