Adding new data to existing model

I am curious to know if it is possible to add new data category to already trained model. That is without invoking old training data.

For instance, we create a CNN based on [teddy, black, brown], we train the classifier and deploy it. Now, we decided to add another class (e.g. grizzly) into the existing model.

Would it be possible to do so? It seems counterintuitive that it would be possible, but felt like it’s worth asking anyway!

Another question is, would it be possible to add new data to existing categories?

Yes! Try using learn.model[-1][-1]=nn.Linear(in_features=512,out_features=data.c, bias=True)
What this line does is it takes that last layer (-1) and changes its output to data.c classes instead of whatever number it used to be. IIRC you might need to change the in_features argument depending one what learn.model[-1][-1] gives you before the change.

Also yes, you can add new data and train again along with the new classes and new data.

2 Likes

I agree that it is possible to replace the last layer to accommodate the extra category, as you asked and Mike answered. But you would lose the existing training during the initialization of the new last layer. You would have to retrain it completely using examples from all 4 categories.

However, do you actually mean…

  • take an already trained model
  • append a new “grizzly” category
  • train further only on “grizzly” photos (or on a mix of all 4 categories?)
  • while retaining the training that was already done
  • now recognize 4 categories

If this is what you are asking (or maybe something else?), I’ll mull it over. There may be a way to kinda sorta do it by retaining the old weight matrix and/or training only the new column. But probably not, if all you have to train with is grizzlies.