Need help - Downloading MNIST dataset

I am downloading the MNIST dataset using

path = untar_data(URLs.MNIST);

path.ls() gives
[‘training’, ‘testing’]

When i try running the code -
data = ImageDataBunch.from_folder(path, ds_tfms=tfms, size=26)

I get the following error -
_---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
in
1 tfms = get_transforms(do_flip=False)
----> 2 data = ImageDataBunch.from_folder(path, ds_tfms=tfms, size=26)

~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/data.py in from_folder(cls, path, train, valid, test, **kwargs)
277 “Create from imagenet style dataset in path with train,valid,test subfolders.”
278 path=Path(path)
–> 279 train_ds = ImageClassificationDataset.from_folder(path/train)
280 datasets = [train_ds, ImageClassificationDataset.from_folder(path/valid, classes=train_ds.classes)]
281 if test: datasets.append(ImageClassificationDataset.from_single_folder(

~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/data.py in from_folder(cls, folder, classes, valid_pct, check_ext)
98 )->Union[‘ImageClassificationDataset’, List[‘ImageClassificationDataset’]]:
99 “Dataset of classes labeled images in folder. Optional valid_pct split validation set.”
–> 100 if classes is None: classes = [cls.name for cls in find_classes(folder)]
101
102 fns,labels = [],[]

~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/core.py in find_classes(folder)
61 def find_classes(folder:Path)->FilePathList:
62 “List of label subdirectories in imagenet-style folder.”
—> 63 classes = [d for d in folder.iterdir()
64 if d.is_dir() and not d.name.startswith(’.’)]
65 assert(len(classes)>0)

~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/core.py in (.0)
61 def find_classes(folder:Path)->FilePathList:
62 “List of label subdirectories in imagenet-style folder.”
—> 63 classes = [d for d in folder.iterdir()
64 if d.is_dir() and not d.name.startswith(’.’)]
65 assert(len(classes)>0)

~/anaconda3/envs/fastai/lib/python3.7/pathlib.py in iterdir(self)
1061 if self._closed:
1062 self._raise_closed()
-> 1063 for name in self._accessor.listdir(self):
1064 if name in {’.’, ‘…’}:
1065 # Yielding a path object for these makes little sense

FileNotFoundError: [Errno 2] No such file or directory: ‘/home/ubuntu/.fastai/data/mnist_png/train’

Any help would be appreciated.
Thanks

2 Likes

The course uses MNIST_SAMPLE, which has a different format.

1 Like

Thanks @jeremy. Am exploring the formats and trying to understand how do i use datasets from Kaggle or elsewhere with fastai v1.

Hello @Bhuvana_ka, were you able to find out about how to use the complete dataset using
path = untar_data(URLs.MNIST)

I am stuck with same problem. please share if you have worked it out…

Thanks in advance.

This appear to solve the issue: (default values for train/valid folder)

path = untar_data(URLs.MNIST)
data = ImageDataBunch.from_folder(path, train='training', valid='testing')

You could also use the DataBlock API to have full control of what you are doing.

il = (ImageList.from_folder(path)
      .split_by_folder('training', 'testing')
      .label_from_folder())
7 Likes

Thank you so much! I’ve been trying to solve it for over an hour! How’d you figure it out?

If you use the from_folder method to create your ImageDataBunch, it appearantly looks for a folder called “train” (see Error: FileNotFoundError: [Errno 2] No such file or directory: ‘/home/ubuntu/.fastai/data/mnist_png/train’). Calling untar_data(URLs.MNIST) creates the folder “training” and not “train”, hence the error. You are able to tell the method from_folder where the training data lies. Just specify it to “training” and you are good to go.