---
title: 'FitNets: Efficient Deep Network Compression'
url: https://www.emergentmind.com/topics/fitnets
type: topic
---

# FitNets: Efficient Deep Network Compression

FitNets are thin, deep neural networks trained using intermediate hints from a larger, moderately deep teacher network in order to achieve high accuracy with fewer parameters and reduced computational cost. The FitNet methodology extends conventional Knowledge Distillation (KD) not only by using the teacher’s output distribution but also by leveraging its intermediate activations (“hints”) to facilitate the optimization and generalization of deeper, thinner student models. This two-stage training scheme enables the compression of large convolutional neural networks (CNNs) into smaller models that, in key experimental settings, can even surpass the teacher’s performance, while being more efficient in terms of parameter count and runtime [1412.6550].

## 1. Teacher and Student Architectures

FitNet involves a teacher network $T$ and a student (“FitNet”) network $S$, designed with distinct architectural paradigms:

- **Teacher ($T$):** Typically a wide and moderately deep CNN. For example, in CIFAR-10, $T$ is a maxout-CNN with 3 convolutional layers (96–192–192 filters, each followed by maxout and pooling), one maxout fully-connected layer (500 units), and a softmax output, totaling approximately 9 million parameters.
- **Student ($S$):** Constructed to be significantly deeper (e.g., 11, 13, or 19 convolutional layers) but “thinner” (fewer feature maps per layer), with an overall parameter count ranging from 3–10× fewer than $T$.

Training very deep, thin CNNs directly using standard backpropagation is challenging due to vanishing gradients and poor local minima. Knowledge Distillation alone is often insufficient, especially when the student is much deeper than the teacher. FitNets address this by delivering “hints” (intermediate representations) from the teacher to the student during training, providing additional supervision beyond the final output distribution [1412.6550].

## 2. Hint and Guided Layers

A crucial aspect of FitNets is the selection of the “hint layer” in the teacher and the “guided layer” in the student:

- **Hint Layer (Teacher, $k$):** Selected at an intermediate depth, typically the middle convolutional layer. This layer embodies meaningful abstractions that are neither too low-level nor too specialized.
- **Guided Layer (Student, $\ell$):** Chosen at a comparable semantic depth in the student network, such as the middle layer among all convolutional layers.

The rationale for selecting mid-level layers is to ensure that hints are sufficiently informative while being feasible for the thinner student to approximate. Empirically, aligning the semantic depth of hint and guided layers avoids both excessive regularization of early features and trivial targets near the output [1412.6550].

## 3. Mapping Function and Loss Formulations

As the student’s guided layer is generally thinner than the teacher’s hint layer, their activations cannot be compared directly. The FitNet strategy introduces a learnable mapping function or regressor, $g$, commonly instantiated as a 2D convolution:

$$
g: \mathbb{R}^{N^s_1 \times N^s_2 \times O^s} \rightarrow \mathbb{R}^{N^t_1 \times N^t_2 \times O^t}
$$

where $(N^s_i, O^s)$ and $(N^t_i, O^t)$ denote the spatial dimensions and channel counts of the student and teacher layers, respectively. The kernel size of $g$ is chosen so that the student feature map, after mapping, matches the teacher’s hint representation, while minimizing additional parameters [1412.6550].

The training objectives are given as follows:

- **Hint Loss (pre-training):**
  $$
  \mathcal{L}_{\text{hint}}(W_S, W_r) = \frac{1}{2} \left\| g(h^s_\ell(x); W_r) - h^t_k(x) \right\|^2
  $$
- **Standard Cross-Entropy Loss:**
  $$
  \mathcal{L}_{\text{ce}}(W_S) = H(y_\text{true}, P_S(x)) = -\sum_c y_\text{true}(c) \log P_S(c; x)
  $$
- **Distillation Loss (softened):**
  $$
  \mathcal{L}_{\text{distill}}(W_S) = H(P_T^\tau(x), P_S^\tau(x)) = -\sum_c P_T^\tau(c; x) \log P_S^\tau(c; x)
  $$
- **Combined Objective (fine-tuning):**
  $$
  \mathcal{L}_{\text{total}}(W_S) = \mathcal{L}_{\text{ce}}(W_S) + \lambda \mathcal{L}_{\text{distill}}(W_S)
  $$

Here, $W_S$ and $W_r$ are student and regressor parameters, $h^t_k(x)$ and $h^s_\ell(x)$ the respective teacher and student representations, $P_T^\tau$ and $P_S^\tau$ the softened output distributions with temperature $\tau$, and $\lambda$ a weighting coefficient (often annealed from 4 to 1 during training).

## 4. Two-Stage Training Algorithm

FitNet training consists of two sequential stages:

- **Stage 1: Hint-based Pre-training**
  - The teacher network is fixed up to layer $k$.
  - The student’s initial $\ell$ layers and the regressor $g$ are trained (random initialization) to minimize $\mathcal{L}_{\text{hint}}$, aligning the student’s mid-level activations with the teacher’s.
- **Stage 2: Joint Fine-tuning with Distillation**
  - The full student network is initialized with the pre-trained layers from stage 1; the remaining layers are randomly initialized.
  - All student parameters are optimized using the combined loss $\mathcal{L}_{\text{total}} = \mathcal{L}_{\text{ce}} + \lambda\mathcal{L}_{\text{distill}}$.

This two-stage paradigm produces a “warm-start” in the student’s middle layers, enabling optimization to escape poor local minima and avoid vanishing gradients encountered in training deep thin nets from scratch [1412.6550].

## 5. Experimental Results

Extensive experiments demonstrate the efficacy of FitNets in compressing large models while achieving superior or comparable accuracy. On CIFAR-10:

- **Teacher:** 3 convolutional layers + 1 maxout-FC layer; $\sim 9$ million parameters; test accuracy $\sim 90.18\%$.
- **FitNet-4 [19 conv layers]:** $\sim 2.5$ million parameters ($\sim 3.6\times$ compression); test accuracy $\sim 91.61\%$ ($+1.43\%$ over teacher).
- **FitNet (11 conv layers):** $\sim 0.86$ million parameters ($\sim 10\times$ fewer than teacher); accuracy $91.06\%$; $4.6\times$ GPU speed-up.

Compared to prior mimic/KD baselines (e.g., 70M parameter students achieving $85.8\%$ accuracy), FitNets achieved $28\times$ greater compression and a $\sim 5\%$ accuracy improvement. Similar results are observed on CIFAR-100, SVHN, and MNIST, with FitNets surpassing or matching teacher performance at $3$–$12\times$ parameter reductions [1412.6550].

## 6. Practical Considerations

When implementing FitNets, the following guidelines are advised:

- Select the teacher’s hint layer and student’s guided layer at mid-network locations to target meaningful, reproducible features.
- The regressor $g$ should consist of a 2D convolution with kernel size suited to match student and teacher feature map sizes while maintaining low parameter cost.
- Typical learning settings involve RMSProp with initial learning rate $0.005$, batch size 128.
- Use temperature $\tau \approx 3$ and set $\lambda$ initially to 4, linearly annealed to 1 across training epochs.
- Early stop pretraining after $\sim 100$ epochs without improvement, up to a maximum of 500 epochs; repeat for fine-tuning.

## 7. Limitations and Prospects

FitNets present increased training computational overhead, as the pre-trained teacher must be retained to extract hint activations for all training samples. The optimal choice of hint/guided layers and the schedule for $\lambda$ decay are empirically determined and remain somewhat heuristic. Future research may automate the selection of hint layers, incorporate multiple hints, or extend the approach to sequence and attention-based architectures. Integrating FitNet compression with methods such as low-rank factorization or parameter quantization is a promising direction for further efficiency gains [1412.6550].

Source: https://www.emergentmind.com/topics/fitnets