错误:RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0
img = Image.open(path) #读入图片
img_p = transform(img).unsqueeze(0).to(device)
第二行报错
解决:
图片读入时需要转换为RGB格式,在读入时加入convert('RGB’)即可
img = Image.open(path).convert('RGB')
img_p = transform(img).unsqueeze(0).to(device)