How to add a new class to an existing classifier in deep learning?
Asked Answered
A

3

8

I trained a deep learning model to classify the given images into three classes. Now I want to add one more class to my model. I tried to check out "Online learning", but it seems to train on new data for existing classes. Do I need to train my whole model again on all four classes or is there any way I can just train my model on new class?

Arthromere answered 8/12, 2019 at 14:39 Comment(0)
S
3

You probably have used a softmax after 3 neuron dense layer at the end of the architecture to classify into 3 classes. Adding a class will lead to doing a softmax over 4 neuron dense layer so there will be no way to accommodate that extra neuron in your current graph with frozen weights, basically you're modifying the graph and hence you'll have to train the whole model from scratch

-----or-----

one way would be loading the model and removing the last layer , changing it to 4 neurons and training the network again! This will basically train the weights of the last layer from scratch . I don't think there is anyway to keep these(weights of the last layer) weights intact while adding a new class .

Sauers answered 8/12, 2019 at 15:32 Comment(2)
Now i understood how to update to network to classify a new class... i think i can use transfer learning, instead of training my model from scratch (random weight initialization). thank you for your comments.Arthromere
Yes you can initialize weights of the last layer keeping intact the weights of the previous layer. Cheers !Sauers
D
5

I tried to check out "Online learning", but it seems to train on new data for existing classes.

Online learning is a term used to refer to a model which takes a continual or sequential stream of input data while training, in contrast to offline learning (also called batch learning), where the model is pre-trained on a static predefined dataset.

Continual learning (also called incremental, continuous, lifelong learning) refers to a branch of ML working in an online learning context where models are designed to learn new tasks while maintaining performance on historic tasks. It can be applied to multiple problem paradigms (including Class-incremental learning, where each new task presents new class labels for an ever expanding super-classification problem).

Do I need to train my whole model again on all four classes or is there any way I can just train my model on new class?

Naively re-training the model on the updated dataset is indeed a solution. Continual learning seeks to address contexts where access to historic data (i.e. the original 3 classes) is not possible, or when retraining on an increasingly large dataset is impractical (for efficiency, space, privacy etc concerns). Multiple such models using different underlying architectures have been proposed, but almost all examples exclusively deal with image classification problems.


Related q's:

Dutcher answered 2/11, 2020 at 17:42 Comment(0)
A
4

You have to remove the final fully-connected layer, freeze the weights in the feature extraction layers, add a new fully-connected layer with four outputs and retrain the model with images of the original three classes and the new fourth class.

Adonic answered 1/3, 2020 at 3:43 Comment(1)
hey ! in my last model there were 13 classes. I needed to add 4 more classes in it. I used transfer learning to do so. But Now I am having 4 classes only in the model. i don't know where did I go wrong. can you tell me what happened ?Pasquale
S
3

You probably have used a softmax after 3 neuron dense layer at the end of the architecture to classify into 3 classes. Adding a class will lead to doing a softmax over 4 neuron dense layer so there will be no way to accommodate that extra neuron in your current graph with frozen weights, basically you're modifying the graph and hence you'll have to train the whole model from scratch

-----or-----

one way would be loading the model and removing the last layer , changing it to 4 neurons and training the network again! This will basically train the weights of the last layer from scratch . I don't think there is anyway to keep these(weights of the last layer) weights intact while adding a new class .

Sauers answered 8/12, 2019 at 15:32 Comment(2)
Now i understood how to update to network to classify a new class... i think i can use transfer learning, instead of training my model from scratch (random weight initialization). thank you for your comments.Arthromere
Yes you can initialize weights of the last layer keeping intact the weights of the previous layer. Cheers !Sauers

© 2022 - 2024 — McMap. All rights reserved.