报错如下
Traceback (most recent call last):
File "C:\Users\杨颖\Downloads\12805831_IPPkFxJhRMBDIRWZxeeecJnzZ.py", line 79, in
imshow(torchvision.utils.make_grid(iter(train_loader).next()[0]))
File "D:\python\lib\site-packages\torch\utils\data\dataloader.py", line 521, in next
data = self._next_data()
File "D:\python\lib\site-packages\torch\utils\data\dataloader.py", line 561, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "D:\python\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\python\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\python\lib\site-packages\torchvision\datasets\mnist.py", line 126, in getitem
img, target = self.data[index], int(self.targets[index])
IndexError: index 25934 is out of bounds for dimension 0 with size 10000
**代码如下
```python
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import os
#load data
transform = torchvision.transforms.ToTensor() #定义数据预处理方式:转换 PIL.Image 成 torch.FloatTensor
train_data = torchvision.datasets.MNIST(root="F:\python_mnist", #数据目录,这里目录结构要注意。
train=True, #是否为训练集
transform=transform, #加载数据预处理
download=False) #是否下载
test_data = torchvision.datasets.MNIST(root="F:\python_mnist",
train=False,
transform=transform,
download=False)
#数据加载器:组合数据集和采样器;batch_size=64:同时并行处理64张图片
train_loader = torch.utils.data.DataLoader(dataset = train_data,batch_size = 64,shuffle = True)
test_loader = torch.utils.data.DataLoader(dataset = test_data,batch_size = 64,shuffle = False)
#展示数据/图像
import numpy as np
import matplotlib.pyplot as plt
def imshow(img):
img = img / 2 + 0.5 # unnormalize
npimg = img.numpy()
plt.imshow(np.transpose(npimg, (1, 2, 0)))
plt.show()
torchvision.utils.make_grid 将图片进行拼接
imshow(torchvision.utils.make_grid(iter(train_loader).next()[0]))
```:**
在最后一句报错,,是不是应该打开mnist.py 把index的范围扩大啊,可是应该怎么改