0

我正在尝试使用 Pytorch 预测来自 MNIST 的一些图像,但我无法选择 0-60,000 之间的任何索引。首先我添加了“drop_last=True”,因为我注意到最后一个不完整的批次没有被丢弃,我认为这可以解决问题,但事实并非如此。如果我的批量大小为 256,我可以选择预测的最大索引为 255。我应该如何解决这个问题?这是我获取图像的方式:

images = MNIST('mnist_data',transform=T, download=True, train=True)
image_loader = torch.utils.data.DataLoader(images,batch_size=256, drop_last=True, shuffle=True)

以及我如何尝试做出预测:

image_index = 258
value = (images[image_index])
prediction = Net().forward(value)

然后我得到 IndexError: index 258 is out of bounds for dimension 0 with size 256

4

1 回答 1

0

这主要是因为您试图索引一个大于数组/张量长度的值。你会想要增加批量大小来修复它

于 2020-08-15T06:13:56.430 回答