# How to add classes incrementally for a classification problem?

I do not understand how it is possible to add classes incrementally to a classification model without retraining the whole model with all classes. Even getting an idea of the general working logic or a simple example will be valuable for me.

In the simplest scenario each time you want to add new class you need to retrain the whole model. You have to also use loss function for multiclass (e.g. https://keras.io/api/losses/probabilistic_losses/#categoricalcrossentropy-class).

Complicated: if adding new class is very dynamic (system where many new classes are added every day, hour, second) you can think if model with triplet loss is applicable.

• I was looking for a solution besides the retraining whole model.. Can you give more explanation about "you can think if model with triplet loss is applicable?" Jan 17, 2022 at 12:33
• In triplet loss you build one model that creates embbedings for a sample and you can find closest sample from database. Look at: youtube.com/watch?v=6jfw8MuKwpI&ab_channel=DeepLearningAI , youtube.com/watch?v=d2XB5-tuCWU&ab_channel=DeepLearningAI , arxiv.org/pdf/1503.03832.pdf Jan 17, 2022 at 12:48
• but what is its relation with class incremental learning (CIL)? suppose that we have a model that classifies fruits as the apple, orange. After a certain time, we want to add banana to the model. Therefore, for a given image, we want the probability of being apple, orange and banana as output. What is the relation of that with triplet loss? Jan 17, 2022 at 13:16
• "suppose that we have a model that classifies fruits as the apple, orange" - that is wrong assumption with tripplet loss trained model. This model does not classify samples as orange or apple. This model produce vector as output. In database you store vectors (produced by model) for 10 different samples of oranges, 10 vectors (produced by the same model) of different apples. Now you pass through model image of orange and the output is vector (e.g. shape=(1,100)). Now you use e.g. n-closest neighbor between this bector of new image vs all vectors in database. That is how you obtain label. Jan 17, 2022 at 13:41
• Now if you want to add class strawberry, then just pass 10 images of strawberry through model and store those 10 vectors in database. The thing is you need to train model with triplet loss (or sth similar) so the model does not learn to classify to some defined classes but learns to produce good embedding representation. Please watch youtube link I provided before - Andrew Ng with longer time teaches much better than me in stack comments ;) Jan 17, 2022 at 13:44

Bit late to the party, but so-called one-class classifiers (aka class models) model each class completely independently of all other classes.

Thus, adding (or changing/retraining) one class doesn't affect any of the other classes.

Note that these are rather different from discriminative classifiers, they are e.g. for scenarios where something unknown may appear and should be identified as such. A scenario where new classes "appear" later on is inherently very foreign to dicriminative models.