我在 Pytorch v1.3、torchvision v0.4.2 上有一个预训练模型,如下所示:
import PIL, torch, torchvision
# Load and normalize the image
img_file = "./robot_image.jpg"
img = PIL.Image.open(img_file)
img = torchvision.transforms.ToTensor()((img))
img = 0.5 + 0.5 * (img - img.mean()) / img.std()
# Load a pre-trained network and compute its prediction
alexnet = torchvision.models.alexnet(pretrained=True)
我想测试这个单一的图像,但我得到一个错误:
alexnet(img)
RuntimeError: Expected 4-dimensional input for 4-dimensional weight 64 3 11 11, but got 3-dimensional input of size [3, 741, 435] instead
让模型评估单个数据点的最简单和惯用的方法是什么?