ImageClassifierData.from_paths with sub folders

I am trying to use path with subfolders. For example, i a training folder, we have two classes: Forest and Water. Each of this class folder has subclasses. For example, the water folder, we have two subclasses Lake folder, and Sea folder. The same applies to the forest folder.

Although I think I could train separately the forest and water one at a time, is there a way to loop through subfolders using ImageClassifierData.from_paths with sub folders?

If I’m reading your post correctly, you’re trying to train all the subclasses while ignoring the superclasses. I’m not so familiar with fastai but there are easy ways to do this with bash. The easiest way to do this without modifying the existing structure is to create symlinks.

  1. make a directory with mk train_ subclasses somewhere
  2. cd into that directory
  3. link all of the subclasses of a given superclass with ln -s path/to/superclass/*/ .
  4. check that the links are there and they work (ls subclass)
  5. repeat for all superclasses
2 Likes

Thanks Arijun. I was looking a way to train this with fastai not running through command line. I was actually overthinking. I just needed to move the sub classes to the super class directory.