Lesson2(v3) IndexError: index 0 is out of bounds for axis 0 with size 0

(Somraj) #1

I’ve a image dataset properly labeled and split into train, test and valid folders but when I create an ImageDataBunch I’m prompted with the this error;

IndexError: index 0 is out of bounds for axis 0 with size 0

Although there’s another post in the forums about this same issue and there a possible solution to it but there’s no explanation to the error. Here’s the link to the other forum post.

0 Likes

#2

I have the same problem on Kaggle

1 Like

(Sasi Kiran Gaddipati) #3

For me it worked when i changed the path specification from ‘content…’ to ‘\content…’

1 Like

#4

In my case, it is about the file name.

MNIST use the folder name ‘training’ and ‘testing’ instead of ‘train’ and ‘valid’ which is the default of from_folder.

It worked after I assign the folder name:
ImageDataBunch.from_folder(path, train=‘training’, valid=‘testing’, ds_tfms=tfms, size=26)

Reference from help(ImageDataBunch.from_folder):
from_folder(path: Union[pathlib.Path, str], train: Union[pathlib.Path, str] = ‘train’, valid: Union[pathlib.Path, str] = ‘valid’, valid_pct=None, classes: Collection = None, **kwargs: Any) -> ‘ImageDataBunch’ method of builtins.type instance
Create from imagenet style dataset in path with train,valid,test subfolders (or provide valid_pct).

1 Like

(marco) #5

What worked for me is I specified my path as follow (working on colab):

root_dir = ‘/content/drive/My Drive/fastai/’
path = Path(root_dir)
path = root_dir + ‘sleeves_lenghts/train’

0 Likes