Questions re: "ImageDataBunch.from_folder"

Let’s say, I have ‘train’ and ‘test’ directories each of them contains 10 subdirectories corresponding to a specific class (‘class_a’, ‘class_b’, etc.).
What if I wanted to build a classifier only from ‘class_a’, ‘class_b’ and ‘class_c’, but not the rest of them?
Removing the rest of the subdirectories is not an option.
How do I specify in “ImageDataBunch.from_folder” only use the classes I am interested in?

I tried this, and it doesn’t work:
ImageDataBunch.from_folder(…, classes=[ ‘class_a’, ‘class_b’, ‘class_c’])

Thank you!

What I would try is to create a new directory with train and test directories, each containing the specific directories you want as symlinks

fastai doesn’t seem to recognize symlinked directories.

Temporarily moving directories is not an option ?

You could also temporarily hide the directories you don’t want to be recognized

Thanks, @PierreO. I thought about all these options, and they might be my last resort.
My assumption was that “classes” parameter in “from_folder” method is support to achieve what I want.
Otherwise, I don’t see the point of this parameter. It also doesn’t seem to be well documented.
I am digging through the code right now, and might create a PR if I find out that this is a bug.

Looking at the source I think it’s only to rename classes if need be

Oh, understood. Then I guess I will write my own custom stuff, since I don’t think there is a need for this functionality from the majority of the users :slight_smile:

1 Like