Skip to content

Commit

Permalink
feat: fitnet retina
Browse files Browse the repository at this point in the history
  • Loading branch information
LutingWang committed Feb 17, 2023
1 parent 14fb2cc commit 9843ac0
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 185 deletions.
121 changes: 60 additions & 61 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: fix-encoding-pragma
args:
- --remove
- id: mixed-line-ending
args:
- --fix=lf
exclude: \.bat$
- id: mixed-line-ending
args:
- --fix=crlf
files: \.bat$
- id: requirements-txt-fixer
files: requirements.txt|requirements/.*
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pycqa/docformatter
rev: v1.4
hooks:
- id: docformatter
args:
- --in-place
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
additional_dependencies:
- toml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: mypy
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args:
- head
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.29.0
hooks:
- id: commitizen
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: fix-encoding-pragma
args:
- --remove
- id: mixed-line-ending
args:
- --fix=lf
- id: requirements-txt-fixer
files: requirements.txt
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/docformatter
rev: v1.5.0
hooks:
- id: docformatter
# - repo: https://github.com/pycqa/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0
hooks:
- id: yapf
additional_dependencies:
- toml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
hooks:
- id: mypy
additional_dependencies:
- todd_ai
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args:
- configs
- head
- tests
additional_dependencies:
- tomli
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.0
hooks:
- id: commitizen
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Luting Wang.
Copyright 2022 Luting Wang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
```
# HEtero-Assists Distillation (ECCV 2022)

```text
_/ _/ _/_/_/_/ _/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/
_/_/_/_/ _/_/_/ _/_/_/_/ _/ _/
_/ _/ _/ _/ _/ _/ _/
_/ _/ _/_/_/_/ _/ _/ _/_/_/
```

HEtero-Assists Distillation for Heterogeneous Object Detectors
This repository is the official implementation of "[HEtero-Assists Distillation for Heterogeneous Object Detectors](https://arxiv.org/abs/2207.05345)".

[![lint](https://github.com/LutingWang/HEAD/actions/workflows/lint.yaml/badge.svg)](https://github.com/LutingWang/HEAD/actions/workflows/lint.yaml)
[![wakatime](https://wakatime.com/badge/github/LutingWang/HEAD.svg)](https://wakatime.com/badge/github/LutingWang/HEAD)
Expand All @@ -21,6 +23,7 @@ Download `MMDetection` pretrained models to `pretrained/mmdetection`
mkdir -p pretrained/mmdetection
wget -P pretrained/mmdetection https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_mstrain_3x_coco/faster_rcnn_r50_fpn_mstrain_3x_coco_20210524_110822-e10bd31c.pth
wget -P pretrained/mmdetection https://download.openmmlab.com/mmdetection/v2.0/third_party/mobilenet_v2_batch256_imagenet-ff34753d.pth
wget -P pretrained/mmdetection https://download.openmmlab.com/mmdetection/v2.0/retinanet/retinanet_r50_fpn_mstrain_3x_coco/retinanet_r50_fpn_mstrain_3x_coco_20210718_220633-88476508.pth
```

Download `torchvision` pretrained models to `pretrained/torchvision`
Expand All @@ -34,7 +37,7 @@ wget -P pretrained/torchvision https://download.pytorch.org/models/resnet50-0676

The directory tree should be like this

```
```text
HEAD
├── data
│ └── coco -> ~/Developer/datasets/coco
Expand All @@ -48,7 +51,8 @@ HEAD
├── pretrained
│ ├── mmdetection
│ │ ├── faster_rcnn_r50_fpn_mstrain_3x_coco_20210524_110822-e10bd31c.pth
│ │ └── mobilenet_v2_batch256_imagenet-ff34753d.pth
│ │ ├── mobilenet_v2_batch256_imagenet-ff34753d.pth
│ │ └── retinanet_r50_fpn_mstrain_3x_coco_20210718_220633-88476508.pth
│ └── torchvision -> ~/.cache/torch/hub/checkpoints
│ ├── resnet18-f37072fd.pth
│ └── resnet50-0676ba61.pth
Expand Down Expand Up @@ -85,19 +89,25 @@ pip install todd_ai==0.2.3a9 -i https://pypi.org/simple
## train

```bash
python tools/train.py configs/HEAD/head_retina_faster_r18_fpn_mstrain_1x_coco.py --work-dir work_dirs/debug --seed 3407
python tools/train.py configs/head/head_retina_faster_r18_fpn_mstrain_1x_coco.py --work-dir work_dirs/debug --seed 3407
```

For distributed training

```bash
bash tools/dist_train.sh configs/HEAD/head_retina_faster_r18_fpn_mstrain_1x_coco.py 8 --work-dir work_dirs/debug --seed 3407
bash tools/dist_train.sh configs/head/head_retina_faster_r18_fpn_mstrain_1x_coco.py 8 --work-dir work_dirs/debug --seed 3407
```

## Results

All logs and checkpoints can be found in the [Google Drive](https://drive.google.com/drive/folders/1cs9WWyBaZmstsKlwnMv7PE9ky-i98WUh?usp=sharing).

### Baseline

| Method | Student | Teacher | mAP | Config | Comment |
| :-: | :-: | :-: | :-: | :-: | :-: |
| FitNet | R18 RetinaNet | R50 RetinaNet | $35.6$ | [fitnet_retina](configs/fitnet/fitnet_retina_r18_fpn_mstrain_1x_coco.py) | with weight transfer |

### HEAD

Teachers and students are all trained with multi-scale, for 3x and 1x scheduler respectively.
Expand All @@ -106,20 +116,20 @@ Teachers and students are all trained with multi-scale, for 3x and 1x scheduler
| :-: | :-: | :-: | :-: | :-: | :-: | - |
| R18 RetinaNet | | | | | $31.7$ | refer to [mmdetection](https://github.com/open-mmlab/mmdetection/blob/master/configs/retinanet/README.md) |
| R18 RetinaNet | R50 Faster R-CNN | $\checkmark$ | | | $33.4$ | [retina_faster_r18](configs/assist/retina_faster_r18_fpn_mstrain_1x_coco.py) |
| R18 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | | $35.7$ | [HEAD_dag_retina_faster_r18](configs/HEAD_dag/HEAD_dag_retina_faster_r18_fpn_mstrain_1x_coco.py) |
| R18 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | $\checkmark$ | $36.1$ | [HEAD_retina_faster_r18](configs/HEAD/HEAD_retina_faster_r18_fpn_mstrain_1x_coco.py) |
| R18 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | | $35.7$ | [HEAD_dag_retina_faster_r18](configs/head_dag/head_dag_retina_faster_r18_fpn_mstrain_1x_coco.py) |
| R18 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | $\checkmark$ | $36.1$ | [HEAD_retina_faster_r18](configs/head/head_retina_faster_r18_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | | | | | $27.8$ | [retinanet_mnv2](configs/retinanet/retinanet_mnv2_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | R50 Faster R-CNN | $\checkmark$ | | | $28.9$ | [retina_faster_mnv2](configs/assist/retina_faster_mnv2_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | | $32.2$ | [HEAD_dag_retina_faster_mnv2](configs/HEAD_dag/HEAD_dag_retina_faster_mnv2_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | $\checkmark$ | $33.1$ | [HEAD_retina_faster_mnv2](configs/HEAD/HEAD_retina_faster_mnv2_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | | $32.2$ | [HEAD_dag_retina_faster_mnv2](configs/head_dag/head_dag_retina_faster_mnv2_fpn_mstrain_1x_coco.py) |
| MNv2 RetinaNet | R50 Faster R-CNN | $\checkmark$ | $\checkmark$ | $\checkmark$ | $33.1$ | [HEAD_retina_faster_mnv2](configs/head/head_retina_faster_mnv2_fpn_mstrain_1x_coco.py) |

### TF-HEAD

Coming soon...

# Developer Guides
## Developer Guides

## Local Installation
### Setup

```bash
pip install https://download.pytorch.org/whl/cpu/torch-1.9.1-cp38-none-macosx_11_0_arm64.whl
Expand All @@ -135,7 +145,7 @@ pre-commit install
pre-commit install -t commit-msg
```

## TODO
### TODO

- complete distributed train/test guide
- more configs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_base_ = [
'../_base_/models/HEAD_retina_faster.py',
'../_base_/models/head_retina_faster.py',
'../_base_/models/mnv2_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
Expand Down
2 changes: 1 addition & 1 deletion configs/HEAD/head_retina_faster_r18_fpn_mstrain_1x_coco.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_base_ = [
'../_base_/models/HEAD_retina_faster.py',
'../_base_/models/head_retina_faster.py',
'../_base_/models/r18_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_base_ = [
'../_base_/models/HEAD_dag_retina_faster.py',
'../_base_/models/head_dag_retina_faster.py',
'../_base_/models/mnv2_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_base_ = [
'../_base_/models/HEAD_dag_retina_faster.py',
'../_base_/models/head_dag_retina_faster.py',
'../_base_/models/r18_fpn.py',
'../_base_/datasets/coco_detection_mstrain.py',
'../_base_/schedules/schedule_1x.py',
Expand Down
3 changes: 1 addition & 2 deletions configs/_base_/models/HEAD_dag_retina_faster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
teacher=dict(
config='configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py',
ckpt=(
'pretrained/mmdetection/'
'faster_rcnn_r50_fpn_mstrain_3x_coco_'
'pretrained/mmdetection/faster_rcnn_r50_fpn_mstrain_3x_coco_'
'20210524_110822-e10bd31c.pth'
),
),
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/models/HEAD_retina_faster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_base_ = [
'HEAD_dag_retina_faster.py',
'head_dag_retina_faster.py',
]

model = dict(
Expand Down
41 changes: 41 additions & 0 deletions configs/_base_/models/fitnet_retina.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
_base_ = [
'retinanet.py',
]

model = dict(
type='SingleTeacherSingleStageDistiller',
distiller=dict(
teacher=dict(
config=('configs/retinanet/retinanet_r50_fpn_1x_coco.py'),
ckpt=(
'pretrained/mmdetection/retinanet_r50_fpn_mstrain_3x_coco_'
'20210718_220633-88476508.pth'
),
),
weight_transfer={
'.student.bbox_head': '.teacher.bbox_head',
},
student_hooks=dict(neck=dict(type='StandardHook', path='neck')),
teacher_hooks=dict(
teacher_neck=dict(type='StandardHook', path='neck'),
),
adapts=dict(
neck_adapted=dict(
type='Conv2d',
fields=['neck'],
parallel=5,
in_channels=256,
out_channels=256,
kernel_size=1,
),
),
losses=dict(
loss_feat=dict(
type='MSELoss',
fields=['neck_adapted', 'teacher_neck'],
parallel=True,
weight=1.0,
)
),
)
)
Loading

0 comments on commit 9843ac0

Please sign in to comment.