Multiple models using the same training data

Let us say that I have two models: model1 and model2. Both of them have been trained on the same set of images, the difference is that they are classifying mutually exclusive things in the image. Now, after training, can I use model1 and model2 for inference and have the test images in a common directory?

Based on my simple test, data = ImageClassifierData.from_paths(PATH, bs=bs, tfms=tfms, num_workers=1, test_name=test_dir) requires the PATH to contain the train directory as well. Since both the models have different functions, having a common train directory isn’t possible.

I’m not an expert on the fastai library, but if you’re on Linux you could make a symlink from model2’s test directory to that from model1. Then model2 will load the exact same images as model1 for testing.

Sure, that sounds fine. One more similar question:

Is there a way to keep the fastai models already loaded and then just keep using them to classify images as they come? I am unable to figure out how to do that. Thank you!

Hi Vishal,
what do you mean by as “as they come”?:

  1. classifying another set of images(other datasets), or

  2. classifying incrementally single image one after another.

For the 1st, there is a method set_data that receive a data object like the one you wrote on you 1st post. So you must just set the test_name the folder containing images to classify.
For the 2nd, you can refer to this post:

Hopefully it helps.
Let us know if you get some troubles.