forked from open-mmlab/mmrazor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump version to v0.3.0 (open-mmlab#135)
* [Feature] Add function to meet mmdeploy support (open-mmlab#102) * add init_model function for mmdeploy * fix lint * add unittest for init_xxx_model * fix lint * mv test_inference.py to test_apis directory * [Feature] Add function to meet mmdeploy support (open-mmlab#102) * add init_model function for mmdeploy * fix lint * add unittest for init_xxx_model * fix lint * mv test_inference.py to test_apis directory * [Refactor] Delete redundant `set_random_seed` function (open-mmlab#104) * refactor set_random_seed * add unittests * fix unittests error * fix lint * avoid bc breaking * [Feature] Add diff seeds to diff ranks and set torch seed in worker_init_fn (open-mmlab#113) * add init_random_seed * Set diff seed to diff workers * [Feature] Add multi machine dist_train (open-mmlab#114) * support multi nodes * update training doc * fix lints * remove fixed seed * fix ddp wrapper registry (open-mmlab#128) * [Docs] Add brief installation steps in README(_zh-CN).md (open-mmlab#121) * Add brief installation * add brief installtion ref to mmediting pr#816 Co-authored-by: caoweihan <caoweihan@sensetime.com> * [BUG]Fix bugs in pruner (open-mmlab#126) * fix bugs in pruner when pruning models with shared modules * pruner can trace models with dilation conv2d * fix deploy_subnet * fix add_pruning_attrs * fix bugs in modify_forward * fix lint * fix StructurePruner * test tracing models with shared modules Co-authored-by: caoweihan <caoweihan@sensetime.com> * [Docs]Add some more details to docs (open-mmlab#133) * add docs for dataset * add cfg-options for distillation * fix docs Co-authored-by: caoweihan <caoweihan@sensetime.com> * reset norm running status after prepare_from_supernet (open-mmlab#81) * [Improvement]Sync train api (open-mmlab#115) Co-authored-by: caoweihan <caoweihan@sensetime.com> * [Feature]Support Relational Knowledge Distillation (open-mmlab#127) * add rkd * add rkd pytest * add rkd configs * fix readme * fix rkd * split rkd loss to distance-wise and angle-wise losses * rename rkd losses * add rkd metaflie * add rkd related links * rename rkd metafile and add to model index * delete cifar100 Co-authored-by: caoweihan <caoweihan@sensetime.com> Co-authored-by: pppppM <gjf_mail@126.com> Co-authored-by: qiufeng <44188071+wutongshenqiu@users.noreply.github.com> Co-authored-by: wutongshenqiu <690364065@qq.com> Co-authored-by: whcao <41630003+HIT-cwh@users.noreply.github.com> Co-authored-by: caoweihan <caoweihan@sensetime.com>
- Loading branch information
1 parent
9cf76b3
commit 5329362
Showing
39 changed files
with
1,408 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# RKD | ||
|
||
|
||
|
||
> [Relational Knowledge Distillation](https://arxiv.org/abs/1904.05068) | ||
<!-- [ALGORITHM] --> | ||
## Abstract | ||
Knowledge distillation aims at transferring knowledge acquired | ||
in one model (a teacher) to another model (a student) that is | ||
typically smaller. Previous approaches can be expressed as | ||
a form of training the student to mimic output activations of | ||
individual data examples represented by the teacher. We introduce | ||
a novel approach, dubbed relational knowledge distillation (RKD), | ||
that transfers mutual relations of data examples instead. | ||
For concrete realizations of RKD, we propose distance-wise and | ||
angle-wise distillation losses that penalize structural differences | ||
in relations. Experiments conducted on different tasks show that the | ||
proposed method improves educated student models with a significant margin. | ||
In particular for metric learning, it allows students to outperform their | ||
teachers' performance, achieving the state of the arts on standard benchmark datasets. | ||
|
||
![pipeline](/docs/en/imgs/model_zoo/rkd/pipeline.png) | ||
|
||
## Results and models | ||
### Classification | ||
|Location|Dataset|Teacher|Student|Acc|Acc(T)|Acc(S)|Config | Download | | ||
:--------:|:---------:|:---------:|:---------:|:---------:|:---------:|:---------:|:------:|:---------| | ||
| neck |ImageNet|[resnet34](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet34_8xb32_in1k.py)|[resnet18](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet18_8xb32_in1k.py)| 70.23 | 73.62 | 69.90 |[config](./rkd_neck_resnet34_resnet18_8xb32_in1k.py)|[teacher](https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_b16x8_cifar10_20210528-a8aa36a6.pth) |[model](https://download.openmmlab.com/mmrazor/v0.3/distill/rkd/rkd_neck_resnet34_resnet18_8xb32_in1k_acc-70.23_20220401-f25700ac.pth) | [log](https://download.openmmlab.com/mmrazor/v0.3/distill/rkd/rkd_neck_resnet34_resnet18_8xb32_in1k_20220312_130419.log.json)| | ||
|
||
|
||
|
||
## Citation | ||
```latex | ||
@inproceedings{park2019relational, | ||
title={Relational knowledge distillation}, | ||
author={Park, Wonpyo and Kim, Dongju and Lu, Yan and Cho, Minsu}, | ||
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, | ||
pages={3967--3976}, | ||
year={2019} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Collections: | ||
- Name: RKD | ||
Metadata: | ||
Training Data: | ||
- ImageNet-1k | ||
Paper: | ||
URL: https://arxiv.org/abs/1904.05068 | ||
Title: Relational Knowledge Distillation | ||
README: configs/distill/rkd/README.md | ||
Code: | ||
URL: https://github.com/open-mmlab/mmrazor/blob/v0.3.0/mmrazor/models/losses/relation_kd.py | ||
Version: v0.3.0 | ||
Converted From: | ||
Code: https://github.com/lenscloth/RKD | ||
Models: | ||
- Name: rkd_neck_resnet34_resnet18_8xb32_in1k | ||
In Collection: RKD | ||
Metadata: | ||
Location: neck | ||
Student: R-18 | ||
Teacher: R-34 | ||
Teacher Checkpoint: https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_8xb32_in1k_20210831-f257d4e6.pth | ||
Results: | ||
- Task: Image Classification | ||
Dataset: ImageNet-1k | ||
Metrics: | ||
Top 1 Accuracy: 70.23 | ||
Top 1 Accuracy:(S): 69.90 | ||
Top 1 Accuracy:(T): 73.62 | ||
Config: configs/distill/rkd/rkd_neck_resnet34_resnet18_8xb32_in1k.py | ||
Weights: https://download.openmmlab.com/mmrazor/v0.3/distill/rkd/rkd_neck_resnet34_resnet18_8xb32_in1k_acc-70.23_20220401-f25700ac.pth |
79 changes: 79 additions & 0 deletions
79
configs/distill/rkd/rkd_neck_resnet34_resnet18_8xb32_in1k.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
_base_ = [ | ||
'../../_base_/datasets/mmcls/imagenet_bs32.py', | ||
'../../_base_/schedules/mmcls/imagenet_bs256.py', | ||
'../../_base_/mmcls_runtime.py' | ||
] | ||
|
||
# model settings | ||
student = dict( | ||
type='mmcls.ImageClassifier', | ||
backbone=dict( | ||
type='ResNet', | ||
depth=18, | ||
num_stages=4, | ||
out_indices=(3, ), | ||
style='pytorch'), | ||
neck=dict(type='GlobalAveragePooling'), | ||
head=dict( | ||
type='LinearClsHead', | ||
num_classes=1000, | ||
in_channels=512, | ||
loss=dict(type='CrossEntropyLoss', loss_weight=1.0), | ||
topk=(1, 5), | ||
)) | ||
|
||
# teacher settings | ||
teacher_ckpt = 'https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_8xb32_in1k_20210831-f257d4e6.pth' # noqa: E501 | ||
|
||
teacher = dict( | ||
type='mmcls.ImageClassifier', | ||
init_cfg=dict(type='Pretrained', checkpoint=teacher_ckpt), | ||
backbone=dict( | ||
type='ResNet', | ||
depth=34, | ||
num_stages=4, | ||
out_indices=(3, ), | ||
style='pytorch'), | ||
neck=dict(type='GlobalAveragePooling'), | ||
head=dict( | ||
type='LinearClsHead', | ||
num_classes=1000, | ||
in_channels=512, | ||
loss=dict(type='CrossEntropyLoss', loss_weight=1.0), | ||
topk=(1, 5), | ||
)) | ||
|
||
# algorithm setting | ||
algorithm = dict( | ||
type='GeneralDistill', | ||
architecture=dict( | ||
type='MMClsArchitecture', | ||
model=student, | ||
), | ||
with_student_loss=True, | ||
with_teacher_loss=False, | ||
distiller=dict( | ||
type='SingleTeacherDistiller', | ||
teacher=teacher, | ||
teacher_trainable=False, | ||
teacher_norm_eval=True, | ||
components=[ | ||
dict( | ||
student_module='neck.gap', | ||
teacher_module='neck.gap', | ||
losses=[ | ||
dict( | ||
type='DistanceWiseRKD', | ||
name='distance_wise_loss', | ||
loss_weight=25.0, | ||
with_l2_norm=True), | ||
dict( | ||
type='AngleWiseRKD', | ||
name='angle_wise_loss', | ||
loss_weight=50.0, | ||
with_l2_norm=True), | ||
]) | ||
]), | ||
) | ||
|
||
find_unused_parameters = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Prepare datasets | ||
|
||
Currently our algorithms support [mmclassification](https://mmclassification.readthedocs.io/en/latest/), | ||
[mmdetection](https://mmdetection.readthedocs.io/en/latest/) and | ||
[mmsegmentation](https://mmsegmentation.readthedocs.io/en/latest/). | ||
Before running our algorithms, you may need to prepare the datasets according | ||
to the instructions in the corresponding document. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.