31
$\begingroup$

I would like to train a neural network (NN) where the output classes are not (all) defined from the start. More and more classes will be introduced later based on incoming data. This means that, every time I introduce a new class, I would need to retrain the NN.

How can I train an NN incrementally, that is, without forgetting the previously acquired information during the previous training phases?

$\endgroup$
0

5 Answers 5

14
$\begingroup$

I'd like to add to what's been said already that your question touches upon an important notion in machine learning called transfer learning. In practice, very few people train an entire convolutional network from scratch (with random initialization), because it is time consuming and relatively rare to have a dataset of sufficient size.

Modern ConvNets take 2-3 weeks to train across multiple GPUs on ImageNet. So it is common to see people release their final ConvNet checkpoints for the benefit of others who can use the networks for fine-tuning. For example, the Caffe library has a Model Zoo where people share their network weights.

When you need a ConvNet for image recognition, no matter what your application domain is, you should consider taking an existing network, for example VGGNet is a common choice.

There are a few things to keep in mind when performing transfer learning:

  • Constraints from pretrained models. Note that if you wish to use a pretrained network, you may be slightly constrained in terms of the architecture you can use for your new dataset. For example, you can’t arbitrarily take out Conv layers from the pretrained network. However, some changes are straight-forward: due to parameter sharing, you can easily run a pretrained network on images of different spatial size. This is clearly evident in the case of Conv/Pool layers because their forward function is independent of the input volume spatial size (as long as the strides “fit”).

  • Learning rates. It’s common to use a smaller learning rate for ConvNet weights that are being fine-tuned, in comparison to the (randomly-initialized) weights for the new linear classifier that computes the class scores of your new dataset. This is because we expect that the ConvNet weights are relatively good, so we don’t wish to distort them too quickly and too much (especially while the new Linear Classifier above them is being trained from random initialization).

Additional reference if you are interested in this topic: How transferable are features in deep neural networks?

$\endgroup$
1
  • 3
    $\begingroup$ Transfer learning does not necessarily address the catastrophic forgetting problem, though with a small learning rate (and by freezing some weights) you may not forget previously learned knowledge. Transfer learning is good for speeding up training or when you have a small number of samples. See my answer. Your answer can be misleading, and people continue to upvote it (probably because "transfer learning" is just popular, when it does not emphasize certain important aspects). $\endgroup$
    – nbro
    Commented May 2, 2019 at 15:44
7
$\begingroup$

Here is one way you could do that.

After training your network, you can save its weights to disk. This allows you to load this weights when new data becomes available and continue training pretty much from where your last training left off. However, since this new data might come with additional classes, you now do pre-training or fine-tuning on the network with weights previously saved. The only thing you have to do, at this point, is make the last layer(s) accommodate the new classes that have now been introduced with the arrival of your new dataset, most importantly include the extra classes (e.g., if your last layer initially had 10 classes, and now you have found 2 more classes, as part of your pre-training/fine-tuning, you replace it with 12 classes). In short, repeat this circle :

Repeat

$\endgroup$
1
  • $\begingroup$ if you only accommodate the new classes in the last layer ( training classes + new classes) the model cannot be fit because we want to train with the new classes (only) and the model expect an array with the shape of (training + the new classes, ). $\endgroup$ Commented Mar 20, 2019 at 11:55
3
$\begingroup$

There are several ways to add new classes to the trained model, which require just training for the new classes.

  • Incremental training (GitHub)
  • continuously learn a stream of data (GitHub)
  • online machine learning (GitHub)
  • Transfer Learning Twice
  • Continual learning approaches (Regularization, Expansion, Rehearsal) (GitHub)
$\endgroup$
3
  • $\begingroup$ What do you mean by "transfer learning twice"? Apart from that, your suggestions are more or less appropriate. $\endgroup$
    – nbro
    Commented Nov 10, 2020 at 10:00
  • $\begingroup$ used the previous datasets of training and add new class to them and re train the model. $\endgroup$ Commented Nov 17, 2020 at 18:35
  • $\begingroup$ Given that you provided links for all approaches other than "transfer learning twice", you may also add a link to some implementation/paper that shows that approach. $\endgroup$
    – nbro
    Commented Nov 17, 2020 at 18:37
1
$\begingroup$

You could use transfer learning (i.e. use a pre-trained model, then change its last layer to accommodate the new classes, and re-train this slightly modified model, maybe with a lower learning rate) to achieve that, but transfer learning does not necessarily attempt to retain any of the previously acquired information (especially if you don't use very small learning rates, you keep on training and you do not freeze the weights of the convolutional layers), but only to speed up training or when your new dataset is not big enough, by starting from a model that has already learned general features that are supposedly similar to the features needed for your specific task. There is also the related domain adaptation problem.

There are more suitable approaches to perform incremental class learning (which is what you are asking for!), which directly address the catastrophic forgetting problem. For instance, you can take a look at this paper Class-incremental Learning via Deep Model Consolidation, which proposes the Deep Model Consolidation (DMC) approach. There are other continual/incremental learning approaches, many of them are described here or in more detail here.

$\endgroup$
0
$\begingroup$

What you are after is called "Class-incremental learning" (IL).

In this study they consider three classes of solutions:

  • regularization-based solutions that aim to minimize the impact of learning new tasks on the weights that are important for previous tasks;
  • exemplar-based solutions that store a limited set of exemplars to prevent forgetting of previous tasks;
  • solutions that directly address the problem of the bias towards recently-learned tasks.

Their main findings are:

  • For exemplar-free class-IL, data regularization methods outperform weight regularization methods.
  • Finetuning with exemplars (FT-E) yields a good baseline that outperforms more complex methods on several experimental settings.
  • Weight regularization combines better with exemplars than data regularization for some scenarios.
  • Methods that explicitly address task-recency bias outperform those that do not.
  • Network architecture greatly influences the performance of class-IL methods, in particular the presence or absence of skip connections has a significant impact.
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .