"Your training set is empty." (SOLVED)

SOLVED thanks to TomB.

Hey guys !
I’m working on a artistic movement recognition algorithm next to the first lesson and i collected some images for my database.
The folder structure is this one : database/images/train and database/images/validation_set, in those two folder, there is a folder for each artistic movement and images in it. When i run this code

bs = 64
path = datapath4file("/home/affect/my_50cts/whart?")
path_train = path/‘images’/‘train’
path_valid_set = path/‘images’/‘validation_set’
ImageList.from_folder(path_train)
data = ImageDataBunch.from_folder(f’{path_train}’, size=224, ds_tfms=get_transforms(), bs=bs)
data.normalize(imagenet_stats)
learn = cnn_learner(data, models.resnet34, metrics=error_rate)
learn.fit_one_cycle(4)
learn.save(‘stage-1’)

I have this error (at date = ImageDataBunch…) :

/data/anaconda/lib/python3.7/site-packages/fastai/data_block.py:451: 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.”)

Any advice to solve my problem ? <3
Have a good day guys !

If you look at the help for ImageDataBunch.from_folder you see:

>>> ImageDataBunch.from_folder?
Signature:
ImageDataBunch.from_folder(
    path: Union[pathlib.Path, str],
    train: Union[pathlib.Path, str] = 'train',
    valid: Union[pathlib.Path, str] = 'valid',
    valid_pct=None,
    seed: int = None,
    classes: Collection = None,
    **kwargs: Any,
) -> 'ImageDataBunch'

So, instead of passing path_train you should instead pass path (and you don’t need to make it a string with f'{path_train}', it will take a Path). Then you specify the names of the sub-folders for train and validation. So you likely want something like:

path= Path("/home/affect/my_50cts/whart?/images")
data = ImageDataBunch(path, 'train', 'validation_set') # With other arguments for transforms etc

Or as the default for the train parameter is ‘train’ like in your data you could just have:

data = ImageDataBunch(PATH, valid='validation_set')

As a general thing, is the question mark really in the folder name? If so, I would suggest that is not a good idea, the question mark is a special character in linux shells, so best not used in paths.

3 Likes

Well Explained. My problem solved.
Thank you so much.
May Allah reward you.

Thanks for the answer. I was doing everything fine but my error was that I was not aware of the validation. Thanks to this I understand.

If you are like me and you are doing all fine but still get an error. Read this article. https://www.fast.ai/2017/11/13/validation-sets/