MNIST Dataset

train_dataset=datasets.MNIST(root='../data/',train=True,transform=transforms.ToTensor(),download=True)# change it to False after you have downloaded the datatest_dataset=datasets.MNIST(root='../data/',train=False,transform=transforms.ToTensor())

importnumpyasnpimporttorchvision# functions to show an imagedefimshow(img):img=img/2+0.5# unnormalizenpimg=img.numpy()plt.imshow(np.transpose(npimg,(1,2,0)))# get some random training imagesdataiter=iter(train_loader)images,labels=dataiter.next()# show imagesimshow(torchvision.utils.make_grid(images[:5]))# print labelsprint(' '.join('%5s'%labels[j]forjinrange(5)))