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.
It appears this thread has been gaining a lot of attention lately. Although I’m not actively developing on fastai for now or probably until v3 is live but hopefully I can share my inputs into these problem people are facing.
You see ImageDataBunch creates train, test & valid sets automatically but at times, datasets like MNIST already comes preprocessed in separate folders like Train & Test. If that’s the case, ImageDataBunch will thow an error.
Besides, you can try troubleshooting by checking the path to the dataset or like mentioned previously, check if the “Train” & “Test” folders exists already. Then you’ll have to manually create a Valid set from the “Test” set.
Anyway, if there’s something missing out, do let me know, I’ll update the post accordingly, since I’m not caught up with the fastai library for a while.
Although I can understand reading documentations can be confusing but please make a habit of doing so. The fast.ai docs are probably one of the best out there among many but you’re still welcome to ask for help.
So in order for us to help you out better, you need to provide us with a minimal reproducible code snippet that you got working until stuck at some point. That way it’s efficient for us to guide you through & it’s a good practice for you in the long run too. So I request you to please share a code snippet that you got working until being stuck.
Besides, you should probably check out the snippets showcased in the Quickly get your data ready for training section of the vision.data documentation. I assume you’re a beginner, hence I’m obliged to mention that you can check out a plethora of techniques to load in an image dataset into the DataBunch class.
It’s understandable if it was a mouthful to pick up but don’t hesitate to questions on this thread or create a new thread if it’s something else that you’re confused with.
I couldn’t get it working either. Looks like lot needs to be learning about how data_block object work but couldn’t it be simpler like sklearn style.
As seen in the code bellow:
df_train = pd.read_csv(’/home/gkarmakar4969/data/fashion/training/fashion-mnist.csv’)
df_train.head()
data = ImageDataBunch.from_folder(PATH, train=‘training’, ds_tfms=tfms, valid_pct=0.2).normalize(imagenet_stats)
/anaconda/envs/py37_pytorch/lib/python3.7/site-packages/fastai/data_block.py:454: UserWarning: Your training set is empty. If this is by design, pass ignore_empty=True to remove this warning.
warn(“Your training set is empty. If this is by design, pass ignore_empty=True to remove this warning.”)
/anaconda/envs/py37_pytorch/lib/python3.7/site-packages/fastai/data_block.py:457: UserWarning: Your validation set is empty. If this is by design, use split_none()
or pass ignore_empty=True when labelling to remove this warning.
or pass ignore_empty=True when labelling to remove this warning.""")
Hi Jarmos,
I stuck in this error :“IndexError: index 0 is out of bounds for axis 0 with size 0”
worried:
I have Train and Test folders and each folder has two sub-folders ( My problem is binary classification).
Do you mind helping me with this error ? I really appreciate your help.
@azade
Welcome to the community
This error occurs usually occurs when the object through which you’re iterating is empty. If you could post the entire stack trace message, we could help you pinpoint exactly what is wrongs.
Cheers
@azade Share the entire stack trace message, as in the whole error messages. Also share the tree structure of how your files are sorted. Install tree, if it’s not installed already.
Thanks for your reply. I solved this problem by installing another version of fastai.
But unfortunately, another error comes up now when I use learn.predict(image).
Thanks for your reply. I solved this problem by installing another version of fastai.
But unfortunately, another error comes up now when I use learn.predict(image).
Can I ask my new question?