Home

Awesome

Curriculum Temperature for Knowledge Distillation

Curriculum Temperature for Knowledge Distillation <br> Zheng Li, Xiang Li#, Lingfeng Yang, Borui Zhao, Renjie Song, Lei Luo, Jun Li, Jian Yang#. <br> Nankai University, Nanjing University of Science and Technology, Megvii Technology. <br> AAAI 2023 <br> [Paper] [Project Page] [中文解读]

💡 Note

The implementation of instance-wise temperature has been publicly released, please check the following README carefully.

Abstract

CTKD organizes the distillation task from easy to hard through a dynamic and learnable temperature. The temperature is learned during the student’s training process with a reversed gradient that aims to maximize the distillation loss (i.e., increase the learning difficulty) between teacher and student in an adversarial manner.

As an easy-to-use plug-in technique, CTKD can be seamlessly integrated into existing state-of-the-art knowledge distillation frameworks and brings general improvements at a negligible additional computation cost.

Framework

<div style="text-align:center"><img src="figure/framework.png" width="100%" ></div>

(a) We introduce a learnable temperature module that predicts a suitable temperature τ for distillation. The gradient reversal layer is proposed to reverse the gradient of the temperature module during the backpropagation.

(b) Following the easy-to-hard curriculum, we gradually increase the parameter λ, leading to increased learning difficulty w.r.t. temperature for the student.

Visualization

The learning curves of temperature during training:

<div style="text-align:center"><img src="figure/temp_curve.png" width="100%" ></div>

Main Results

On CIFAR-100:

Teacher <br> StudentRN-56 <br> RN-20RN-110 <br> RN-32RN-110 <br> RN-20WRN-40-2 <br> WRN-16-2WRN-40-2 <br> WRN-40-1VGG-13 <br> VGG-8
KD70.6673.0870.6674.9273.5472.98
+CTKD71.1973.5270.9975.4573.9373.52

On ImageNet-2012:

Teacher <br> (RN-34)Student <br> (RN-18)KD+CTKDDKD+CTKD
Top-173.9670.2670.8371.3271.1371.51
Top-591.5889.5090.3190.2790.3190.47

Requirements

Running

  1. Download the pre-trained teacher models and put them to ./save/models.
DatasetDownload
CIFAR teacher models[Baidu Cloud] [Github Releases]
ImageNet teacher models[Baidu Cloud] [Github Releases]

If you want to train your teacher model, please consider using ./scripts/run_cifar_vanilla.sh or ./scripts/run_imagenet_vanilla.sh.

After the training process, put your teacher model to ./save/models.

  1. Training on CIFAR-100:
  1. Training on ImageNet-2012:

Model Zoo & Training Logs

Global Temperature

We provide complete training configs, logs, and models for your reference.

CIFAR-100:

Instance-wise Temperature

The detailed implementation and training log of instance-wise CTKD are provided for your reference.
[Baidu Cloud][Google Drive]

In this case, you need to simply change the distillation loss calculation process in the distiller_zoo/KD.py line16-line18 as follows:

KD_loss = 0
for i in range(T.shape[0]):
   KD_loss += KL_Loss(y_s[i], y_t[i], T[i])
KD_loss /= T.shape[0]

KL_Loss() is defined as follows:

def KL_Loss(output_batch, teacher_outputs, T):

    output_batch = output_batch.unsqueeze(0)
    teacher_outputs = teacher_outputs.unsqueeze(0)

    output_batch = F.log_softmax(output_batch / T, dim=1)
    teacher_outputs = F.softmax(teacher_outputs / T, dim=1) + 10 ** (-7)

    loss = T * T * torch.sum(torch.mul(teacher_outputs, torch.log(teacher_outputs) - output_batch))
    return loss

Contact

If you have any questions, you can submit an issue on GitHub, leave a message on Zhihu Article (if you can speak Chinese), or contact me by email (zhengli97[at]qq.com).

Citation

If this repo is helpful for your research, please consider citing our paper and giving this repo a star ⭐. Thank you!

@inproceedings{li2023curriculum,
  title={Curriculum temperature for knowledge distillation},
  author={Li, Zheng and Li, Xiang and Yang, Lingfeng and Zhao, Borui and Song, Renjie and Luo, Lei and Li, Jun and Yang, Jian},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  volume={37},
  number={2},
  pages={1504--1512},
  year={2023}
}