NotADirectoryError: [Errno 20] Not a directory

I moved my libraries to a different machine and noticed this error popping up in the first few lines of day 1 code.

---------------------------------------------------------------------------
NotADirectoryError                        Traceback (most recent call last)
<ipython-input-11-dc79c3421c2e> in <module>()
      1 tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on, max_zoom=1.1)
----> 2 data = ImageClassifierData.from_paths(PATH, tfms=tfms, bs=bs, num_workers=1)
      3 learn = ConvLearner.pretrained(arch, data, precompute=True, ps=0.5)

/dgxdata/fastai/courses/dl1/fastai/dataset.py in from_paths(cls, path, bs, tfms, trn_name, val_name, test_name, num_workers)
    317             ImageClassifierData
    318         """
--> 319         trn,val = [folder_source(path, o) for o in (trn_name, val_name)]
    320         test_fnames = read_dir(path, test_name) if test_name else None
    321         datasets = cls.get_ds(FilesIndexArrayDataset, trn, val, tfms, path=path, test=test_fnames)

/dgxdata/fastai/courses/dl1/fastai/dataset.py in <listcomp>(.0)
    317             ImageClassifierData
    318         """
--> 319         trn,val = [folder_source(path, o) for o in (trn_name, val_name)]
    320         test_fnames = read_dir(path, test_name) if test_name else None
    321         datasets = cls.get_ds(FilesIndexArrayDataset, trn, val, tfms, path=path, test=test_fnames)

/dgxdata/fastai/courses/dl1/fastai/dataset.py in folder_source(path, folder)
     52 
     53 def folder_source(path, folder):
---> 54     fnames, lbls, all_labels = read_dirs(path, folder)
     55     label2idx = {v:k for k,v in enumerate(all_labels)}
     56     idxs = [label2idx[lbl] for lbl in lbls]

/dgxdata/fastai/courses/dl1/fastai/dataset.py in read_dirs(path, folder)
     41     for label in sorted(os.listdir(full_path)):
     42         all_labels.append(label)
---> 43         for fname in os.listdir(os.path.join(full_path, label)):
     44             filenames.append(os.path.join(folder, label, fname))
     45             labels.append(label)

NotADirectoryError: [Errno 20] Not a directory: '/dgxdata/data/99. Kaggle/dogs-vs-cats-redux-kernels-edition/train/cat.0.jpg'

Some one had posted the error before (see here) but this one comes up on the image.

This method expects to see cats and dogs folders inside your train folder

1 Like

thanks. that works. For validation, do we randomly pick and create asimilar folder?

That is one way. Another one is to use from_csv method and pass indexes of validation images.

2 Likes

thank you @sermakarevich