Awesome
Knowledge-Distillation-Zoo
News! I'm going to have a major update of this repo. The new version will contain most of the methods in Todo list. Please stay tuned.
Pytorch implementation of various Knowledge Distillation (KD) methods.
This repository is a simple reference, mainly focuses on basic knowledge distillation/transfer methods. Thus many tricks and variations, such as step-by-step training, iterative training, ensemble of teachers, ensemble of KD methods, data-free, self-distillation, online distillation etc. are not considered. Hope it is useful for your project or research.
I will update this repo regularly with new KD methods. If there some basic methods I missed, please contact with me.
Lists
Name | Method | Paper Link | Code Link |
---|---|---|---|
Baseline | basic model with softmax loss | — | code |
Logits | mimic learning via regressing logits | paper | code |
ST | soft target | paper | code |
AT | attention transfer | paper | code |
Fitnet | hints for thin deep nets | paper | code |
NST | neural selective transfer | paper | code |
PKT | probabilistic knowledge transfer | paper | code |
FSP | flow of solution procedure | paper | code |
FT | factor transfer | paper | code |
RKD | relational knowledge distillation | paper | code |
AB | activation boundary | paper | code |
SP | similarity preservation | paper | code |
Sobolev | sobolev/jacobian matching | paper | code |
BSS | boundary supporting samples | paper | code |
CC | correlation congruence | paper | code |
LwM | learning without memorizing | paper | code |
IRG | instance relationship graph | paper | code |
VID | variational information distillation | paper | code |
OFD | overhaul of feature distillation | paper | code |
AFD | attention feature distillation | paper | code |
CRD | contrastive representation distillation | paper | code |
DML | deep mutual learning | paper | code |
- Note, there are some differences between this repository and the original papers:
- For
AT
: I use the sum of absolute values with power p=2 as the attention. - For
Fitnet
: The training procedure is one stage without hint layer. - For
NST
: I employ polynomial kernel with d=2 and c=0. - For
AB
: Two-stage training, the first 50 epochs for initialization, the second stage only employs CE without ST. - For
BSS
: 80% epochs employ CE+BSS loss, the rest 20% only uses CE. In addition, warmup for the first 10 epochs. - For
CC
: For consistency, I only consider CC without instance congruence. Gaussian RBF kernel is employed because Bilinear Pool kernel is similar with PKT. I choose P=2 order Taylor of Gaussian RBF kernel. No special sampling strategy. - For
LwM
: I employ it after rb2 (middle conv layer) but not rb3 (last conv layer), because the base net is resnet with the end of GAP followed by a classifier. If after rb3, the grad-CAN has the same values across H and W in each channel. - For
IRG
: I only use one-to-one mode. - For
VID
: I set the hidden channel size to be same with the output channel size and remove BN in μ. - For
AFD
: I find the original implementation of attention is unstable, thus replace it with a SE block. - For
DML
: Just two nets are employed. Synchronous update to avoid multiple forwards.
- For
Datasets
- CIFAR10
- CIFAR100
Networks
- Resnet-20
- Resnet-110
The networks are same with Tabel 6 in paper.
Training
- Creating
./dataset
directory and downloading CIFAR10/CIFAR100 in it. - Using the script
example_train_script.sh
to train various KD methods. You can simply specify the hyper-parameters listed intrain_xxx.py
or manually change them. - The hyper-parameters I used can be found in the training logs (code: ezed).
- Some Notes:
- Sobolev/LwM alone is unstable and may be used in conjunction with other KD methods.
- BSS may occasionally destroy the training procedure, leading to poor results.
- If not specified in the original papers, all the methods can be used on the middle feature maps or multiple feature maps are only employed after the last conv layer. It is simple to extend to multiple feature maps.
- I assume the size (C, H, W) of features between teacher and student are the same. If not, you could employ 1*1 conv, linear or pooling to rectify them.
Results
- The trained baseline models are used as teachers. For fair comparison, all the student nets have same initialization with the baseline models.
- The initial models, trained models and training logs are uploaded here (code: ezed).
- The trade-off parameter
--lambda_kd
and other hyper-parameters are not chosen carefully. Thus the following results do not reflect which method is better than the others. - Some relation based methods, e.g. PKT, RKD and CC, have less effectiveness on CIFAR100 dataset. It may be because there are more inter classes but less intra classes in one batch. You could increase the batch size, create memory bank or design advance batch sampling methods.
Todo List
- KDSVD (now has some bugs)
- QuEST: Quantized Embedding Space for Transferring Knowledge
- EEL: Learning an Evolutionary Embedding via Massive Knowledge Distillation
- OnAdvFD: Feature-map-level Online Adversarial Knowledge Distillation
- CS-KD: Regularizing Class-wise Predictions via Self-knowledge Distillation
- PAD: Prime-Aware Adaptive Distillation
- DCM: Knowledge Transfer via Dense Cross-Layer Mutual-Distillation
- ESKD: On the Efficacy of Knowledge Distillation
- GKA: Teachers Do More Than Teach: Compressing Image-to-Image Models
- KD-fn: Feature Normalized Knowledge Distillation for Image Classification
- FSD: Knowledge Distillation via Adaptive Instance Normalization
- CSKD: Improving Knowledge Distillation via Category Structure
- CD & GKD: Channel Distillation: Channel-Wise Attention for Knowledge Distillation
- CRCD: Complementary Relation Contrastive Distillation
- MGD: Matching Guided Distillation
- SSKD: Knowledge Distillation Meets Self-Supervision
- KR: Distilling Knowledge via Knowledge Review
- AFD-SAD: Show, Attend and Distill: Knowledge Distillation via Attention-based Feature Matching
- SRRL: Knowledge Distillation via Softmax Regression Representation Learning
- SemCKD: Cross-Layer Distillation with Semantic Calibration
- SKD: Reducing the Teacher-Student Gap via Spherical Knowledge Disitllation
- IFDM: Heterogeneous Knowledge Distillation using Information Flow Modeling
- LKD: Local Correlation Consistency for Knowledge Distillation
- HKD: Distilling Holistic Knowledge with Graph Neural Networks
- LONDON: Lipschitz Continuity Guided Knowledge Distillation
- CDD: Channel-Wise Knowledge Distillation for Dense Prediction
- SCKD: Student Customized Knowledge Distillation: Bridging the Gap Between Student and Teacher
- ICKD: Exploring Inter-Channel Correlation for Diversity-preserved Knowledge Distillation
- DKMF: Distilling Knowledge by Mimicking Features
- CRCD: Complementary Relation Contrastive Distillation
- WCoRD: Wasserstein Contrastive Representation Distillation
- LKD: Local Correlation Consistency for Knowledge Distillation
- KDCL: Online Knowledge Distillation via Collaborative Learning
- ONE: Knowledge Distillation by On-the-Fly Native Ensemble
Requirements
- python 3.7
- pytorch 1.3.1
- torchvision 0.4.2
Acknowledgements
This repo is partly based on the following repos, thank the authors a lot.
- HobbitLong/RepDistiller
- bhheo/BSS_distillation
- clovaai/overhaul-distillation
- passalis/probabilistic_kt
- lenscloth/RKD
If you employ the listed KD methods in your research, please cite the corresponding papers.