Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 740
Surya Avatar asked Dec 08 '19 14:12

Surya


People also ask

What is class incremental learning?

Class-Incremental Learning (CIL) aims to learn a classification model with the number of classes increasing phase-by-phase. Paper.

Can I use deep learning for classification?

Now, after learning all the important components of classification in Deep learning, you can move on to sample classification problems. In the following parts, we will see how to apply all these functions for solving specific classification problems in detail.

How to add a fourth class to an existing feature extraction layer?

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. Show activity on this post.

Should I add a class to my neural network model?

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

How to create a new layer without original training data?

Your new layer would be a matmul layer with shape [len (dense layer), len (new classes)]. Without access to original training data, you would have two options: Freeze all the weights in original layers by allowing "new" model to optimize only new weights.

What are the solutions to class-incremental learning?

What you are after is called "Class-incremental learning" (IL). In this study they consider three classes of solutions: solutions that directly address the problem of the bias towards recently-learned tasks. For exemplar-free class-IL, data regularization methods outperform weight regularization methods.


Video Answer


3 Answers

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 .

like image 76
Akash Basudevan Avatar answered Oct 17 '22 18:10

Akash Basudevan


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.

like image 42
George Berlak Avatar answered Oct 17 '22 19:10

George Berlak


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:

  • How to fine-tune a keras model with existing plus newer classes?
like image 39
iacob Avatar answered Oct 17 '22 18:10

iacob