Training my model on a new classes of data

I’ve already trained my model to classify images on 2 classes. I exported this model and saved the weight though. Now I want to train this entire model to recognise 2 additional classes. I’ve been trying to

learn = cnn_learner(data, models.resnet50, metrics, pretrained=True)
learn.load("stage1-rn50")
learn.fit_one_cycle(5)

But this not worked. So now I have a question, how can I train my classifier to recognise new classes??

You would have to replace the final layer to output a different number of classes. Your last model will have 2 output nodes but your new model should have 4 so you should use .split() and replace your final layer with a create_head()

1 Like

In which lesson can I find how to do that?

I am unsure if there is an exact lesson on this. Refer to the learner And basic_train Part of the documentation to see how you can use the methods I mentioned to replace the head of your network.

Otherwise, you could train your model with 2 classes together with the dataset with the 2 additional classes. In this way you just have no labels of the two additional classes in the first part of your dataset. Try both and see what works!

See here:

And here:

Basically change the outputs after you load the weights