Skip to content

Commit

Permalink
[Feature] Support RTMDet (#85)
Browse files Browse the repository at this point in the history
* add cspnext

* add neck


* update

* align s,tiny test

* update

* update

* fix bug of UT

* fix typehint

* fix resize bug

* update s and tiny

* update s and tiny link

* update convert

* add cls config with rtmdet

* update config


* fix ci error

Co-authored-by: wanghonglie <wanghonglie@pjlab.org.cn>
  • Loading branch information
hhaAndroid and wanghonglie committed Sep 29, 2022
1 parent 8ba4979 commit bb3aa48
Show file tree
Hide file tree
Showing 26 changed files with 2,097 additions and 42 deletions.
26 changes: 26 additions & 0 deletions configs/rtmdet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# RTMDet

<!-- [ALGORITHM] -->

## Abstract

Our tech-report will be released soon.

<div align=center>
<img src="https://user-images.githubusercontent.com/12907710/192182907-f9a671d6-89cb-4d73-abd8-c2b9dada3c66.png"/>
</div>

## Results and Models

| Backbone | size | SyncBN | ox AP | Params(M) | FLOPS(G) | TRT-FP16-Latency(ms) | Config | Download |
| :---------: | :--: | :----: | ----: | :-------: | :------: | :------------------: | :-----------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| RTMDet-tiny | 640 | Yes | 40.9 | 4.8 | 8.1 | 0.98 | [config](./rtmdet_tiny_syncbn_8xb32-300e_coco.py) | [model](https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_tiny_syncbn_8xb32-300e_coco/rtmdet_tiny_syncbn_8xb32-300e_coco_20220902_112414-259f3241.pth) \| [log](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_tiny_8xb32-300e_coco/rtmdet_s_8xb32-300e_coco_20220902_112414.log.json) |
| RTMDet-s | 640 | Yes | 44.5 | 8.89 | 14.8 | 1.22 | [config](./rtmdet_s_syncbn_8xb32-300e_coco.py) | [model](https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_s_syncbn_8xb32-300e_coco/rtmdet_s_syncbn_8xb32-300e_coco_20220905_161602-fd1cacb9.pth) \| [log](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_s_8xb32-300e_coco/rtmdet_s_8xb32-300e_coco_20220905_161602.log.json) |
| RTMDet-m | 640 | Yes | 49.1 | 24.71 | 39.27 | 1.62 | [config](./rtmdet_m_syncbn_8xb32-300e_coco.py) | [model](https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_m_syncbn_8xb32-300e_coco/rtmdet_m_syncbn_8xb32-300e_coco_20220924_132959-d9f2e90d.pth) \| [log](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_m_8xb32-300e_coco/rtmdet_m_8xb32-300e_coco_20220924_132959.log.json) |
| RTMDet-l | 640 | Yes | 51.3 | 52.3 | 80.23 | 2.44 | [config](./rtmdet_l_syncbn_8xb32-300e_coco.py) | [model](https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_l_syncbn_8xb32-300e_coco/rtmdet_l_syncbn_8xb32-300e_coco_20220926_150401-40c754b5.pth) \| [log](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/rtmdet_l_8xb32-300e_coco/rtmdet_l_8xb32-300e_coco_20220926_150401.log.json) |
| RTMDet-x | 640 | Yes | 52.6 | 94.86 | 141.67 | 3.10 | [config](./rtmdet_x_syncbn_8xb32-300e_coco.py) | [model](<>) \| [log](<>) |

**Note**:

1. The inference speed is measured on an NVIDIA 3090 GPU with TensorRT 8.4.3, cuDNN 8.2.0, FP16, batch size=1, and without NMS.
2. We still directly use the weights trained by `mmdet` currently. A re-trained model will be released later.
53 changes: 53 additions & 0 deletions configs/rtmdet/cspnext_imagenet_pretrain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CSPNeXt ImageNet Pre-training

In this folder, we provide the imagenet pre-training config of RTMDet's backbone CSPNeXt.

## Requirements

To train with these configs, please install [MMClassification 1.x](https://github.com/open-mmlab/mmclassification/tree/1.x) first.

Install by MIM:

```shell
mim install mmcls>=1.0.0rc0
```

or install by pip:

```shell
pip install mmcls>=1.0.0rc0
```

## Prepare Dataset

To pre-train on ImageNet, you need to prepare the dataset first. Please refer to the [guide](https://mmclassification.readthedocs.io/en/1.x/user_guides/dataset_prepare.html#imagenet).

## How to Train

You can use the classification config in the same way as the detection config.

For single-GPU training, run:

```shell
python tools/train.py \
${CONFIG_FILE} \
[optional arguments]
```

For multi-GPU training, run:

```shell
bash ./tools/dist_train.sh \
${CONFIG_FILE} \
${GPU_NUM} \
[optional arguments]
```

More details can be found in [user guides](https://mmdetection.readthedocs.io/en/3.x/user_guides/train.html).

## Results and Models

| Model | resolution | Params(M) | Flops(G) | Top-1 (%) | Top-5 (%) | Download |
| :----------: | :--------: | :-------: | :------: | :-------: | :-------: | :-----------------------------------------------------------------------------------------------------------------: |
| CSPNeXt-tiny | 224x224 | 2.73 | 0.339 | 69.44 | 89.45 | [model](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/cspnext_rsb_pretrain/cspnext-tiny_imagenet_600e.pth) |
| CSPNeXt-s | 224x224 | 4.89 | 0.664 | 74.41 | 92.23 | [model](https://download.openmmlab.com/mmdetection/v3.0/rtmdet/cspnext_rsb_pretrain/cspnext-s_imagenet_600e.pth) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
_base_ = [
'mmcls::_base_/datasets/imagenet_bs256_rsb_a12.py',
'mmcls::_base_/schedules/imagenet_bs2048_rsb.py',
'mmcls::_base_/default_runtime.py'
]

custom_imports = dict(
imports=['mmdet.models', 'mmyolo.models'], allow_failed_imports=False)

model = dict(
type='ImageClassifier',
backbone=dict(
type='mmyolo.CSPNeXt',
arch='P5',
out_indices=(4, ),
expand_ratio=0.5,
deepen_factor=0.33,
widen_factor=0.5,
channel_attention=True,
norm_cfg=dict(type='BN'),
act_cfg=dict(type='mmyolo.SiLU')),
neck=dict(type='GlobalAveragePooling'),
head=dict(
type='LinearClsHead',
num_classes=1000,
in_channels=512,
loss=dict(
type='LabelSmoothLoss',
label_smooth_val=0.1,
mode='original',
loss_weight=1.0),
topk=(1, 5)),
train_cfg=dict(augments=[
dict(type='Mixup', alpha=0.2, num_classes=1000),
dict(type='CutMix', alpha=1.0, num_classes=1000)
]))

# dataset settings
train_dataloader = dict(sampler=dict(type='RepeatAugSampler', shuffle=True))

# schedule settings
optim_wrapper = dict(
optimizer=dict(weight_decay=0.01),
paramwise_cfg=dict(bias_decay_mult=0., norm_decay_mult=0.),
)

param_scheduler = [
# warm up learning rate scheduler
dict(
type='LinearLR',
start_factor=0.0001,
by_epoch=True,
begin=0,
end=5,
# update by iter
convert_to_iter_based=True),
# main learning rate scheduler
dict(
type='CosineAnnealingLR',
T_max=595,
eta_min=1.0e-6,
by_epoch=True,
begin=5,
end=600)
]

train_cfg = dict(by_epoch=True, max_epochs=600)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_base_ = './cspnext-s_8xb256-rsb-a1-600e_in1k.py'

model = dict(
backbone=dict(deepen_factor=0.167, widen_factor=0.375),
head=dict(in_channels=384))
68 changes: 68 additions & 0 deletions configs/rtmdet/metafile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Collections:
- Name: RTMDet
Metadata:
Training Data: COCO
Training Techniques:
- AdamW
- Flat Cosine Annealing
Training Resources: 8x A100 GPUs
Architecture:
- CSPNeXt
- CSPNeXtPAFPN
README: configs/rtmdet/README.md
Code:
URL: https://github.com/open-mmlab/mmyolo/blob/main/mmyolo/models/detectors/yolo_detector.py#L12
Version: v0.1.1

Models:
- Name: rtmdet_tiny_syncbn_8xb32-300e_coco
In Collection: RTMDet
Config: configs/rtmdet/rtmdet_tiny_syncbn_8xb32-300e_coco.py
Metadata:
Training Memory (GB): 7.6
Epochs: 300
Results:
- Task: Object Detection
Dataset: COCO
Metrics:
box AP: 40.9
Weights: https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_tiny_syncbn_8xb32-300e_coco/rtmdet_tiny_syncbn_8xb32-300e_coco_20220902_112414-259f3241.pth

- Name: rtmdet_s_syncbn_8xb32-300e_coco
In Collection: RTMDet
Config: configs/rtmdet/rtmdet_s_syncbn_8xb32-300e_coco.py
Metadata:
Training Memory (GB): 7.6
Epochs: 300
Results:
- Task: Object Detection
Dataset: COCO
Metrics:
box AP: 44.5
Weights: https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_s_syncbn_8xb32-300e_coco/rtmdet_s_syncbn_8xb32-300e_coco_20220905_161602-fd1cacb9.pth

- Name: rtmdet_m_syncbn_8xb32-300e_coco
In Collection: RTMDet
Config: configs/rtmdet/rtmdet_m_syncbn_8xb32-300e_coco.py
Metadata:
Training Memory (GB): 7.6
Epochs: 300
Results:
- Task: Object Detection
Dataset: COCO
Metrics:
box AP: 49.1
Weights: https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_m_syncbn_8xb32-300e_coco/rtmdet_m_syncbn_8xb32-300e_coco_20220924_132959-d9f2e90d.pth

- Name: rtmdet_l_syncbn_8xb32-300e_coco
In Collection: RTMDet
Config: configs/rtmdet/rtmdet_l_syncbn_8xb32-300e_coco.py
Metadata:
Training Memory (GB): 7.6
Epochs: 300
Results:
- Task: Object Detection
Dataset: COCO
Metrics:
box AP: 51.3
Weights: https://download.openmmlab.com/mmyolo/v0/rtmdet/rtmdet_l_syncbn_8xb32-300e_coco/rtmdet_l_syncbn_8xb32-300e_coco_20220926_150401-40c754b5.pth
Loading

0 comments on commit bb3aa48

Please sign in to comment.