In 2021, as it turned out, PyTorch MNIST cannot be installed like before.
When I was testing the neural network, I faced an MNIST installation error.
Well, so I googled how to handle it. And I found a solution.
Reference: https://github.com/pytorch/vision/issues/1938,
from six.moves import urllib
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
I was using Google Colab, so I gave it a shot.
Well… It still didn’t work, so I kept researching it.
And I found another solution. Reference: https://stackoverflow.com/questions/66577151/http-error-when-trying-to-download-mnist-data
!wget www.di.ens.fr/~lelarge/MNIST.tar.gz
!tar -zxvf MNIST.tar.gz
Still, it didn’t work. What the heck….
Oh… As I checked the directory, there was an MNIST folder.
MNIST/processed/training.pt
MNIST/processed/test.pt
Reference: https://discuss.pytorch.org/t/how-to-read-pt-file/46996
.pt file is generated by PyTorch
Okay, so how to read the files?
from torchvision.datasets train_data = datasets.MNIST(root = "./", train = True,
download =True, transform = transforms.ToTensor())test_data = datasets.MNIST(root = "./", train = False,
download = True,transform = transforms.ToTensor())
Did it work ??? Yes, it perfectly worked.