Search

Search papers and lessons

FitNets: Hints for Thin Deep Nets

Adriana Romero, Nicolas Ballas, Samira Ebrahimi Kahou et al. · 2014

FitNets trains a deeper, thinner student by first matching a middle layer of a teacher, then distilling its outputs, and the student beats its larger teacher on CIFAR-10.

On this page

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

TL;DR

FitNets shows how to compress a wide, deep teacher into a student that is deeper but much thinner. The student first learns to predict a middle layer of the teacher, through a small regressor, and then learns the teacher's outputs as in ordinary Knowledge Distillation. On CIFAR-10 a FitNet with about 2.5 million parameters reaches 91.61%, above its teacher's 90.18% with about 9 million.

Builds on: Knowledge Distillation, Convolutional Neural Network, Mean Squared Error · Leads to: Hint-Based Training, the method this paper introduces

Why it mattered

The paper turned the idea of distillation from a way to shrink a model into a way to train a model that could not be trained directly. Its claim is that a thin, deep network is hard to optimise from random weights, but becomes easier to train once a teacher's middle layer gives it a target. The experiments on CIFAR-10 give a compression rate of 10.44 at 91.06% accuracy, against a teacher with about 9 million parameters at 90.18%, in the paper's Table 5.

The idea of matching intermediate features is now a standard tool in distillation work. The paper introduces the hint-based training recipe that many later compression papers build on, and it is the paper that made the case that depth can be traded for width under a fixed computation budget.

The problem

Deep and wide convolutional networks are accurate but slow and large at inference time. Compression methods existed before 2014. Mimicking a large ensemble with a shallow network (Ba and Caruana, 2014) and distillation (Hinton and colleagues) both reduce the size of the model. But they compress into a student of similar depth, or into a shallower and wider one. Neither uses depth, and depth is what gives deep networks their representations: features are reused and become more abstract at higher layers.

Deep networks are also hard to train. They are long chains of non-linear functions, which makes the loss surface highly non-convex. Earlier work eased this with greedy layer-wise pre-training and with supervision at intermediate layers. The FitNets authors ask whether a teacher's intermediate representation can serve as that supervision, so the student can be deeper than the teacher.

How it works

The method has two stages, run on one teacher and one student.

  1. Pick the hint and guided layers. The hint is a middle layer of the teacher. The guided layer is a middle layer of the student. The paper chooses the middle layer of each network. A layer deeper in the student gives it less freedom, which risks over-regularising it.
  2. Add a regressor. The teacher's hint is usually wider than the student's guided layer. A convolutional regressor on top of the guided layer maps its output to the hint's spatial size and channel count, so the two can be compared.
  3. Stage one: hint training. Starting from random weights for the student's layers up to the guided layer, minimise the squared distance between the hint and the regressed guided output. Only these layers and the regressor are updated.
  4. Stage two: distillation. Starting from the stage-one weights, train the whole student with the knowledge-distillation objective, which combines the teacher's softened outputs with the true labels.
  5. Output. The final model is the student's own layers. The regressor is discarded.

A tiny instance: the hint is (2,0)(2, 0), the guided output is 11, and the regressor weights are (1,3)(1, 3). The regressor output is (1,3)(1, 3), the gap is (1,−3)(1, -3), and the hint loss is 12(1+9)=5\frac12 (1 + 9) = 5. Hold the regressor fixed and take one gradient step with learning rate 0.050.05. The gradient with respect to the guided output is −(1⋅1+3⋅(−3))=8-(1 \cdot 1 + 3 \cdot (-3)) = 8, so the guided output drops from 11 to 1−0.05⋅8=0.61 - 0.05 \cdot 8 = 0.6. The regressor now gives (0.6,1.8)(0.6, 1.8), the gap is (1.4,−1.8)(1.4, -1.8), and the loss falls to 12(1.96+3.24)=2.6\frac12 (1.96 + 3.24) = 2.6. The full walkthrough with more numbers is in Hint-Based Training.

flowchart TD
  A["Trained teacher"] --> B["Hint: middle layer"]
  C["Random student"] --> D["Guided: middle layer"]
  D --> E["Convolutional regressor"]
  E --> F["Hint loss"]
  B --> F
  F --> G["Stage one: update student to guided layer"]
  G --> H["Stage two: distillation of the whole student"]
  H --> I["Thin, deep FitNet"]

The math

The hint loss, in the paper's notation, is

LHT(WGuided,Wr)=12∥uh(x;WHint)−r(vg(x;WGuided);Wr)∥2,\mathcal{L}_{HT}(\mathbf{W}_{\text{Guided}}, \mathbf{W}_r) = \frac{1}{2} \lVert u_h(\mathbf{x}; \mathbf{W}_{\text{Hint}}) - r(v_g(\mathbf{x}; \mathbf{W}_{\text{Guided}}); \mathbf{W}_r) \rVert^2,

where uhu_h is the teacher's network up to the hint layer, vgv_g is the student's network up to the guided layer, and rr is the regressor with weights Wr\mathbf{W}_r. The paper requires the outputs of uhu_h and rr to be comparable, so both use the same non-linearity.

Stage one (Algorithm 1 in the paper) minimises LHT\mathcal{L}_{HT} over the student's weights up to the guided layer and over Wr\mathbf{W}_r. Stage two minimises the knowledge-distillation objective, the paper's Eq. (2), over all of the student's weights WS\mathbf{W}_S, starting from the stage-one values.

The regressor's size is the reason for the convolutional form. With hint size Nh,1×Nh,2N_{h,1} \times N_{h,2} and OhO_h channels, and guided size Ng,1×Ng,2N_{g,1} \times N_{g,2} and OgO_g channels, a fully connected regressor needs

Nh,1×Nh,2×Oh×Ng,1×Ng,2×OgN_{h,1} \times N_{h,2} \times O_h \times N_{g,1} \times N_{g,2} \times O_g

weights. A convolutional regressor with kernel k1×k2k_1 \times k_2 chosen so that Ng,i−ki+1=Nh,iN_{g,i} - k_i + 1 = N_{h,i} needs only

k1×k2×Oh×Ogk_1 \times k_2 \times O_h \times O_g

weights, which is much smaller because k1×k2k_1 \times k_2 is far smaller than the spatial product in the first expression.

The paper also argues that hint training is a form of curriculum learning. The teacher's cross-entropy term in the distillation objective weights examples the teacher is confident about more strongly, so easy examples push the student harder early on. This is the link to Curriculum Learning.

Results

CIFAR-10 (Table 1). The FitNet has about 2.5M parameters and reaches 91.61%. The teacher has about 9M and 90.18%. The paper's comparison points are maxout at 90.65%, network in network at 91.2%, and deeply-supervised networks at 91.78%. A deeply-supervised version of the same 19-layer student, trained with labels at intermediate layers, reached 88.2%. The paper reports that the FitNet matches the best methods while having far fewer parameters.

CIFAR-100 (Table 2). The FitNet reaches 64.96% against the teacher's 63.54%, with about 2.5M against about 9M parameters. Deeply-supervised networks reach 65.43%.

SVHN (Table 3). A 13-layer FitNet with about 1.5M parameters has 2.42% misclassification, against 2.38% for the teacher with about 4.9M parameters. The paper says this is comparable accuracy with only 32% of the teacher's capacity. Deeply-supervised networks reach 1.92%.

MNIST (Table 4). A student twice as deep as the teacher, with about 8% of its parameters, is compared under three training methods on about 30K parameters. Standard backpropagation gives 1.9% error, knowledge distillation 0.65%, and hint-based training 0.51%. The teacher, with about 361K parameters, has 0.55%.

Speed and compression (Table 5). On CIFAR-10 the paper measures inference time on a GPU. FitNet 1, with about 250K parameters, is 13.36 times faster than the teacher with 89.01% accuracy. FitNet 2, with about 862K parameters, reaches 91.06% at 4.64 times the speed. FitNet 4, with about 2.5M parameters, reaches 91.61% at 1.52 times the speed and a compression rate of 3.60.

Training depth (Section 4.1, Figure 2). On CIFAR-10 with a budget of about 30M multiplications, standard backpropagation could not train networks with more than 5 layers, knowledge distillation reached 7 layers, and hint training trained 13-layer networks. At 7 layers, hints raise test accuracy from 89.45% to 90.1%.

AFLW (Section 3.4). On a face-patch classifier with a teacher error of 4.21%, FitNet 1, with 15 times fewer multiplications, drops from 4.58% error with distillation to 2.55% with hints.

Limits. The experiments are on small images (CIFAR, SVHN, MNIST, 16 by 16 face patches) with mostly maxout convolutional networks (the face task uses ReLU networks), and the speed numbers are on one GPU. The choice of hint and guided layer is made by hand and is not searched. The paper does not claim the method works for every architecture, only that it works on the ones it tests.

Reading guide

Check yourself

QuestionIn one sentence, what are the two stages of FitNets training?Show answer
Stage one trains the student's layers up to the guided layer, and a regressor, to predict the teacher's hint layer. Stage two trains the whole student with the knowledge-distillation objective, starting from the stage-one weights.
QuestionThe paper's CIFAR-10 FitNet has about 2.5M parameters and reaches 91.61%. The teacher has about 9M and reaches 90.18%. What is the parameter ratio, and what is the accuracy gap in points?Show answer
The ratio is 2.5/9≈0.282.5 / 9 \approx 0.28, so the student is under a third of the teacher. The gap is 91.61−90.18=1.4391.61 - 90.18 = 1.43 points.
QuestionWhy does the paper use a convolutional regressor instead of a fully connected one?Show answer
A fully connected regressor from a convolutional guided layer to a convolutional hint layer needs the product of all spatial positions and channels on both sides. The convolutional regressor only needs a small kernel times the channel counts, because its output is designed to cover the same spatial region as the hint.
QuestionA student is deeper and thinner than its teacher. Standard backpropagation fails to train it past 5 layers in the paper's budget. Which change does the paper report makes a 13-layer network trainable?Show answer
Adding hint-based training, where the student's middle layer is first trained to predict the teacher's middle layer, before the usual distillation stage. Distillation alone reached 7 layers in the same experiment.
QuestionOn SVHN, the 13-layer FitNet is compared with a teacher. Why is a 2.42% versus 2.38% error result still a success for the method?Show answer
The FitNet uses about 1.5M parameters against the teacher's 4.9M, and the paper describes it as comparable accuracy with 32% of the teacher's capacity. Matching the teacher at that size is the point of the method, not beating it.

Sources

Read the full paper

Adriana Romero, Nicolas Ballas, Samira Ebrahimi Kahou et al., 2014. arXiv:1412.6550