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

目录
相关文章
|
9月前
|
IDE Java Shell
聊聊 print 的前世今生
聊聊 print 的前世今生
82 1
|
1月前
|
TensorFlow 算法框架/工具 Python
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,
3021 0
|
5月前
|
Python
ValueError: sleep length must be non-negative
ValueError: sleep length must be non-negative
141 3
|
6月前
|
算法框架/工具
【Tensorflow+keras】解决Exception has occurred: ValueError Shape mismatch: The shape of labels (received
在使用Keras构建的图像分类模型训练过程中,因使用了sparse_categorical_crossentropy损失函数而导致标签形状与模型输出形状不匹配的错误,解决方法是更换损失函数为categorical_crossentropy。
101 0
|
7月前
|
PyTorch 算法框架/工具 机器学习/深度学习
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
986 0
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
773 0
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2785 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
669 0
解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following

热门文章

最新文章