Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'torchvision.datasets.mnist'

Even after installing pytorch, this error is coming for this line.

from torchvision import datasets
like image 762
Nehal Ahuja Avatar asked Sep 11 '25 21:09

Nehal Ahuja


1 Answers

If you're using anaconda distribution, first install torchvision using:

$ conda install -c conda-forge torchvision

If the package is not installed, then it will be installed. Else, it will throw the message

# All requested packages already installed.

After this, try to import the torchvision.datasets as you mentioned.

In [1]: from torchvision import datasets 

In [2]: dir(datasets)  
Out[2]: 
['CIFAR10',
 'CIFAR100',
 'CocoCaptions',
 'CocoDetection',
 'DatasetFolder',
 'EMNIST',
 'FakeData',
 'FashionMNIST',
 'ImageFolder',
 'LSUN',
 'LSUNClass',
 'MNIST',
 'Omniglot',
 'PhotoTour',
 'SEMEION',
 'STL10',
 'SVHN',
 ....,
 ....
]

As you can see from above listing of dir(datasets), the dataset class for MNIST is listed which will be the case when the torchvision package is installed correctly.

like image 185
kmario23 Avatar answered Sep 13 '25 09:09

kmario23