Some questions in Lesson 2 (UserWarning: Your generator is empty.)

hi,friends.I’m a Chinese student. Recently, I’m learning fastai lesson 2, and I have some questions.I need your help!
(1)when I run this code
for c in classes:
print©
verify_images(path/c, delete=True, max_size=600)
why the result show me:C:\Users\dell\Anaconda3\lib\site-packages\fastprogress\fastprogress.py:105: UserWarning: Your generator is empty.
warn(“Your generator is empty.”)
(2)and when I this code:
np.random.seed(42)
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,
ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)
the result is:
C:\Users\dell\Anaconda3\lib\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.”)
C:\Users\dell\Anaconda3\lib\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.""")

IndexError Traceback (most recent call last)
in
1 np.random.seed(42)
2 data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,
----> 3 ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)

~\Anaconda3\lib\site-packages\fastai\vision\data.py in from_folder(cls, path, train, valid, test, valid_pct, seed, classes, **kwargs)
108 if valid_pct is None: src = il.split_by_folder(train=train, valid=valid)
109 else: src = il.split_by_rand_pct(valid_pct, seed)
–> 110 src = src.label_from_folder(classes=classes)
111 return cls.create_from_ll(src, test=test, **kwargs)
112

~\Anaconda3\lib\site-packages\fastai\data_block.py in _inner(*args, **kwargs)
473 assert isinstance(fv, Callable)
474 def _inner(*args, **kwargs):
–> 475 self.train = ft(*args, from_item_lists=True, **kwargs)
476 assert isinstance(self.train, LabelList)
477 kwargs[‘label_cls’] = self.train.y.class

~\Anaconda3\lib\site-packages\fastai\data_block.py in label_from_folder(self, label_cls, **kwargs)
302 “Give a label to each filename depending on its folder.”
303 return self.label_from_func(func=lambda o: (o.parts if isinstance(o, Path) else o.split(os.path.sep))[-2],
–> 304 label_cls=label_cls, **kwargs)
305
306 def label_from_re(self, pat:str, full_path:bool=False, label_cls:Callable=None, **kwargs)->‘LabelList’:

~\Anaconda3\lib\site-packages\fastai\data_block.py in label_from_func(self, func, label_cls, **kwargs)
297 def label_from_func(self, func:Callable, label_cls:Callable=None, **kwargs)->‘LabelList’:
298 “Apply func to every input to get its label.”
–> 299 return self._label_from_list([func(o) for o in self.items], label_cls=label_cls, **kwargs)
300
301 def label_from_folder(self, label_cls:Callable=None, **kwargs)->‘LabelList’:

~\Anaconda3\lib\site-packages\fastai\data_block.py in _label_from_list(self, labels, label_cls, from_item_lists, **kwargs)
272 raise Exception(“Your data isn’t split, if you don’t want a validation set, please use split_none.”)
273 labels = array(labels, dtype=object)
–> 274 label_cls = self.get_label_cls(labels, label_cls=label_cls, **kwargs)
275 y = label_cls(labels, path=self.path, **kwargs)
276 res = self._label_list(x=self, y=y)

~\Anaconda3\lib\site-packages\fastai\data_block.py in get_label_cls(self, labels, label_cls, label_delim, **kwargs)
261 if self.label_cls is not None: return self.label_cls
262 if label_delim is not None: return MultiCategoryList
–> 263 it = index_row(labels,0)
264 if isinstance(it, (float, np.float32)): return FloatList
265 if isinstance(try_int(it), (str, Integral)): return CategoryList

~\Anaconda3\lib\site-packages\fastai\core.py in index_row(a, idxs)
274 if isinstance(res,(pd.DataFrame,pd.Series)): return res.copy()
275 return res
–> 276 return a[idxs]
277
278 def func_args(func)->bool:

IndexError: index 0 is out of bounds for axis 0 with size 0
Ask for your help!

From the error it seems like there is no data in the path. Have you checked if your ‘path’ is set correctly? Can you share the folder structure for your data?

I uploaded the files(‘urls_black.txt’,‘urls_teddy.txt’,‘urls_grizzly.txt’) to each folder separately, and then run the code.I don’t know is that correct

OK!
step.pdf (103.9 KB)
I show you the step, is that correct?

I have the same quesitons, please help.

你好,我也是中国人,也遇到了你的问题,能加个微信吗,一起学习

好,可以 微信号:hqw286019970113

Can you see any images inside your folders? Sometime, the links break and there maybe no images downloaded.


I am very confused :worried:

I can see the images in my folders.But, indeed, pictures download interrupted.

Before uploading the picture, I deleted the interruption manually.

Thanks for sharing the screenshot. One thing that makes me curious is that these downloaded image files don’t have an image file extension (.jpg, .png, etc.). Are you sure you can open them in a file viewer?

If you have your setup on github or something, I can maybe try to see what’s going on in the code to get a better understanding. Can you share your notebook and the csv files you are using to download the images on github?

These downloaded image files actually don’t have an image file extension, but I can open them.
image

I think the problem is without file extension. I suggest trying to add an extension like jpg for 10 files at least.

Thank you for helping me solve the problem all the time.Actually, I don’t know how to use github, I didn’t use it before :joy:. so can we use other way ? can I send you Email or whatever you think is convenient?

from the stack trace shared by @Han1 looks like the UserWarning: Your generator is empty occurs with the verify_images method. I went into the code for this method…

It internally calls get_image_files method. And if you look at the code for that, it expects images with image_extensions as the check_ext=True by default.

This suggests that your downloaded images probably need to have image file extensions - .jpg, .png, etc. Can you try adding extensions to files and see if that resolves your issue? I would probably start with 2-3 files first to make sure this approach is working.

Please check my latest response to @Edmond and I hope that is the issue in your situation too. Maybe you can follow the same steps as suggested there and try again.

Ok,thanks I’ll try :smiley:

Thank you for your attention, I will try that way.