@[TOC](【RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0】)
情景描述:
在使用PyTorch搭建好的Lenet图像分类网络进行预测时候,输入的一张预测照片不是32×32的大小
im = Image.open('text.jpg') # 不是32*32像素
但是,代码中有进行resize()为32×32的步骤
transform = transforms.Compose(
[transforms.Resize((32, 32)), # 测试图片转换为 32 * 32 大小
transforms.ToTensor(), # 张量化处理
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) # 标准化处理
但是在运行时,报上述的错误:
Bug解决方法:
实际运行过程中,图片的输入大小有问题,
尝试直接更换图片大小为 32×32 的图片进行预测,运行成功。
可以具体查看内调函数哪里出现了问题。