Search

Search papers and lessons

Learning without Forgetting

Zhizhong Li, Derek Hoiem · 2016

Learning without Forgetting adds a new task to a trained image network using only the new task's images, by keeping the old outputs on those images close to the original network's outputs.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Optimizers
  • ReadReady to readNot yet

TL;DR

Learning without Forgetting (LwF) teaches a trained image classifier a new task using only the new task's images and labels. Before training starts, the original network's outputs are recorded on those images, and during training the network is kept close to them, which keeps the old task working. Across the paper's seven task pairs, it keeps the old task far better than fine-tuning and stays close to joint training, which uses the old data too.

Builds on: Convolutional Neural Network, Knowledge Distillation, Catastrophic Forgetting, Fine-Tuning · Leads to: later continual-learning methods that keep old outputs as a stand-in for old data

Why it mattered

The paper turned a common practice into a clear rule. Adapting a pre-trained network to a new task had usually meant fine-tuning it on the new data with a small learning rate and hoping the old behaviour survived. LwF replaces that hope with a direct constraint: the outputs on the new images should not drift from what the original network produced. The paper argues that for the new task alone, this often beats plain fine-tuning, which makes it a practical default for adding a capability to an existing network.

The idea of keeping an old model's outputs as a substitute for the old data is now a common pattern in continual learning. The paper also shows the cost of the simple alternatives. A deployed system that must keep its old skills cannot keep every old dataset, and that is the situation the paper addresses.

The problem

Suppose a convolutional network has been trained on ImageNet, with a shared trunk of layers and an output layer for its 1,000 classes. Now a new task must be added, such as recognising scenes or birds, and the ImageNet images and labels are no longer available. Three standard ways of doing this each fail in a different way.

Feature extraction keeps the shared layers frozen and trains a new classifier on their features. It keeps the old task exactly, but the shared features were not built for the new task, so the new task suffers.

Fine-tuning trains everything on the new data with a small learning rate. The new task does well, but the shared layers drift, and the old task can lose accuracy quickly. In the paper's Table I, fine-tuning ends up to 4.6 points below LwF on the old task.

Joint training trains on old and new data together. It is the best reference for how well both tasks can do, but it needs the old data, and it becomes more cumbersome to train as tasks are added.

Catastrophic forgetting is the name for the second failure, where learning the new task overwrites what the network knew. LwF's goal is to get close to joint training without the old data, and without the cost of a separate network per task.

How it works

Start with one network that has shared layers, an old output layer, and a new output layer that starts random. The paper's notation is θs\theta_s for the shared parameters, θo\theta_o for the old output parameters and θn\theta_n for the new ones.

  1. Record the old network's answers. For every image in the new task's training set, run the original network and store its output probabilities for the old classes. Take a tiny example: an image whose recorded old-class probabilities are (0.8,0.2)(0.8, 0.2). Check: the two numbers add to 1.
  2. Add the new output nodes. Attach new output units for the new classes, with random weights. There are few new weights compared with the whole network. Check: the old output layer is unchanged in shape.
  3. Warm-up. Freeze θs\theta_s and θo\theta_o, and train only θn\theta_n until it converges. This gives the new head a sensible starting point.
  4. Joint optimisation. Train θs\theta_s, θo\theta_o and θn\theta_n together, on new-task images only. Each batch has two terms. The new-task term uses the new labels. The old-task term asks the network's old outputs on the same image to match the recorded ones. Take the same image: the new label is the true class, and the current network gives it probability 0.70.7. The new-task loss is −ln⁡0.7≈0.357-\ln 0.7 \approx 0.357. Check: a more confident network gives a smaller loss.
  5. Compare the old outputs with the recorded ones. The current network's old-class probabilities on that image are (0.6,0.4)(0.6, 0.4), against the recorded (0.8,0.2)(0.8, 0.2). The old-task loss, computed with the softened probabilities in step 6, is about 0.6650.665. Check: the loss is smaller when the two sets of probabilities agree.
  6. Soften both sets of probabilities. Before comparing, raise each probability to the power 1/T1/T with T=2T = 2 and renormalise, which makes small probabilities count more. The recorded (0.8,0.2)(0.8, 0.2) becomes (0.667,0.333)(0.667, 0.333), and the current (0.6,0.4)(0.6, 0.4) becomes about (0.550,0.450)(0.550, 0.450).
  7. Sum the losses. The total is the new-task loss plus the old-task loss, weighted by the balance λo\lambda_o (set to 1 in most of the paper), plus a small weight-decay term. In the example the total is about 0.357+0.665=1.0220.357 + 0.665 = 1.022, before weight decay. The optimiser lowers this total, which moves the shared layers so the new task improves while the old outputs stay near the recorded ones.
flowchart LR
  A["Original network"] --> B["Record old outputs on new images"]
  A --> C["Add new output nodes"]
  C --> D["Warm-up: train new head only"]
  D --> E["Joint training on new images"]
  B --> F["Old-output loss"]
  E --> F
  E --> G["New-task loss"]
  F --> H["Adapted network"]
  G --> H

The math

The new-task loss is the usual multinomial logistic loss. Write yn\mathbf{y}_n for the one-hot ground-truth vector and y^n\hat{\mathbf{y}}_n for the network's softmax output:

Lnew(yn,y^n)=−yn⋅log⁡y^n.\mathcal{L}_{new}(\mathbf{y}_n, \hat{\mathbf{y}}_n) = -\mathbf{y}_n \cdot \log \hat{\mathbf{y}}_n.

With one correct class cc, this is −log⁡y^n,c-\log \hat{y}_{n,c}, which is the example's −ln⁡0.7-\ln 0.7.

The old-task loss is a knowledge-distillation style cross-entropy. The recorded old-class probabilities are yo(i)y_o^{(i)} and the current ones are y^o(i)\hat{y}_o^{(i)}, for i=1,…,li = 1, \dots, l old labels. They are softened with temperature TT:

yo′(i)=(yo(i))1/T∑j(yo(j))1/T,y^o′(i)=(y^o(i))1/T∑j(y^o(j))1/T.y_o^{\prime(i)} = \frac{(y_o^{(i)})^{1/T}}{\sum_j (y_o^{(j)})^{1/T}}, \qquad \hat{y}_o^{\prime(i)} = \frac{(\hat{y}_o^{(i)})^{1/T}}{\sum_j (\hat{y}_o^{(j)})^{1/T}}.

The loss is then

Lold(yo,y^o)=−∑i=1lyo′(i)log⁡y^o′(i).\mathcal{L}_{old}(\mathbf{y}_o, \hat{\mathbf{y}}_o) = -\sum_{i=1}^{l} y_o^{\prime(i)} \log \hat{y}_o^{\prime(i)}.

The paper uses T=2T = 2, chosen by grid search on a held-out set. Raising the probabilities to 1/T1/T instead of 11 is what makes small probabilities matter more, as in Softmax Temperature.

Checking the example: 0.81/2=0.8940.8^{1/2} = 0.894 and 0.21/2=0.4470.2^{1/2} = 0.447. Their sum is 1.3421.342, so yo′=(0.667,0.333)y_o^{\prime} = (0.667, 0.333). The current (0.6,0.4)(0.6, 0.4) gives (0.775,0.632)(0.775, 0.632), sum 1.4071.407, so y^o′=(0.550,0.450)\hat{y}_o^{\prime} = (0.550, 0.450). The loss is −(0.667ln⁡0.550+0.333ln⁡0.450)≈0.665-(0.667 \ln 0.550 + 0.333 \ln 0.450) \approx 0.665.

The paper's total objective is

L=Lnew+λoLold+R,\mathcal{L} = \mathcal{L}_{new} + \lambda_o \mathcal{L}_{old} + \mathcal{R},

where R\mathcal{R} is a weight decay term of 0.00050.0005. Training uses Stochastic Gradient Descent with momentum 0.90.9, and the warm-up step is the one above. The paper takes λo\lambda_o as a balance: making it larger favours the old task, and this trade-off is traced out in the paper's Figure 7.

The paper also compares response-preserving losses, L1L_1, L2L_2, cross-entropy and the knowledge-distillation loss, and finds the last one slightly better. The difference is small, which the paper takes to mean that keeping the outputs close matters more than the exact distance measure.

Results

The main experiments use AlexNet, with ImageNet or Places365 as the old task and VOC, CUB or MIT indoor scenes as the new one. Table I gives LwF's own numbers and the differences of the other methods from LwF, so a negative value means that method scored below LwF on that task. Every number is an accuracy in percent, or mean average precision for VOC. Each figure is a mean over three runs.

On ImageNet to VOC, LwF reaches 56.2% on the old task and 76.1% on the new. Fine-tuning is 0.9 points lower on the old task and 0.3 lower on the new. Joint training reaches 56.9% old and 75.9% new. On Places365 to Scenes, LwF reaches 50.9% old and 75.2% new; fine-tuning is 2.1 lower on old and 1.7 lower on new.

The paper's main claims from Table I are these:

  • On the new task, LwF beats feature extraction, fine-tuning FC and Less Forgetting Learning in all seven pairs. It beats fine-tuning in four pairs, ties on ImageNet to MNIST, and is slightly behind on Places365 to VOC (by 0.1 points) and Places365 to CUB (by 1.0 point, with fine-tuning at 35.8% against LwF's 34.8%).
  • On the old task, LwF is much better than fine-tuning and worse than feature extraction in every pair, since feature extraction leaves the old task exactly as it was.
  • LwF is close to joint training. It is slightly better on the new task and slightly worse on the old, which the paper attributes to the different image distributions of the two tasks.
  • Dissimilar tasks cost more old-task accuracy. For CUB added to a Places365 network, the drop on Places365 is 8.48.4 points for fine-tuning, 3.83.8 for LwF and 1.51.5 for joint training.
  • The MNIST case is the failure case. The handwritten digits give little indirect supervision for the ImageNet task, and LwF's old-task accuracy falls to 49.8% while its new-task accuracy reaches 99.3%.

The multiple-task experiment adds VOC or Scenes in parts, recording the old outputs again each time, so the old network's answers always come from the latest model. LwF beats fine-tuning and feature extraction for most newly added tasks, but falls behind joint training on the old task after several additions.

The paper's design tests give further results. Adding more task-specific layers did not help. Expanding the network with new nodes and freezing the old ones performed worse than LwF on the new task. Simply lowering the learning rate of the shared layers did not protect the old task and reduced new-task accuracy. A soft constraint on the weights, which penalises the distance of shared weights from their original values, did worse than constraining the outputs.

The results are limited. The new-task datasets are small, with about 5,300 to 6,000 training images. The experiments are on image classification, with one tracking application in an appendix, and the authors list segmentation and detection as future work. The old network's outputs are only recorded on the new task's images, so they can be a poor sample of the old task's distribution, which the paper's MNIST result shows.

Reading guide

Check yourself

QuestionIn one sentence, what does Learning without Forgetting use in place of the old task's training data?Show answer
The outputs that the original network produced on the new task's images, recorded before training. The new network is trained to keep its old-task outputs close to these recorded outputs.
QuestionThe recorded old-class probabilities for an image are (0.8, 0.2) and the current ones are (0.6, 0.4). With T = 2, what are the softened recorded probabilities?Show answer
Raise each to the power 1/2 and renormalise: 0.8=0.894\sqrt{0.8} = 0.894 and 0.2=0.447\sqrt{0.2} = 0.447, which sum to 1.3421.342. So the softened recorded probabilities are (0.667,0.333)(0.667, 0.333).
QuestionWhy does the paper use the knowledge-distillation loss with a temperature above 1, instead of the ordinary cross-entropy on the old outputs?Show answer
A temperature above 1 flattens the probabilities, so the smaller ones carry more weight in the loss. The network then also has to preserve how the old classes relate to each other, not only which one is most likely. The paper found this slightly better than the alternatives, though the difference was small.
QuestionOn the Places365 to CUB pair, fine-tuning reaches 1.0 points more new-task accuracy than LwF. Why does LwF still count as a success on this pair?Show answer
LwF's new-task accuracy is 34.8%, close to fine-tuning's 35.8%, while fine-tuning's old-task accuracy on the same pair is 4.6 points below LwF's. The method is judged on keeping both tasks, and a small new-task deficit for a large old-task gain is the trade the paper accepts.
QuestionA team has a network trained on ImageNet and wants to add a new visual task, but they no longer have the ImageNet data. Would Learning without Forgetting help, and what would they need to check?Show answer
It would help, because it needs only the new task's images and labels. The team should check that the new images are a reasonable sample of the old task's domain, because the recorded old outputs are only as good as those images. The MNIST result shows that unrelated new data can make the old task suffer.

Sources

Read the full paper

Zhizhong Li, Derek Hoiem, 2016. arXiv:1606.09282