-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
586 additions
and
23 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,36 @@ | ||
# COCO Object detection with VanillaNet | ||
|
||
## Getting started | ||
|
||
We add VanillaNet model and config files based on [mmdetection-2.x](https://github.com/open-mmlab/mmdetection/tree/2.x). Please refer to [get_started.md](https://github.com/open-mmlab/mmdetection/blob/2.x/docs/en/get_started.md) for mmdetection installation and dataset preparation instructions. | ||
|
||
## Results and Fine-tuned Models | ||
|
||
| Framework | Backbone | FLOPs(G) | Params(M) | FPS | AP<sup>b</sup> | AP<sup>m</sup> | Model | | ||
|:---:|:---:|:---:|:---:| :---:|:---:|:---:|:---:| | ||
| RetinaNet | Swin-T | 244.8 | 38.5 | 27.5 | 41.5 | - |-| | ||
| | VanillaNet-13 | 396.9 | 75.4 | 29.8 | 43.0 | - | [log](https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/retinanet_vanillanet_13.log.json)/[model](https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/retinanet_vanillanet_13.pth) | | ||
| Mask RCNN | [Swin-T](https://github.com/SwinTransformer/Swin-Transformer-Object-Detection/tree/master) | 263.8 | 47.8 | 28.2 | 43.7 | 39.8 |-| | ||
| | ConvNeXtV2-Nano | 220.6 | 35.2 | 34.4 | 43.3 | 39.4 |-| | ||
| | VanillaNet-13 | 420.7 | 77.1 | 32.6 | 44.3 | 40.1 | [log](https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/mask_rcnn_vanillanet_13.log.json)/[model](https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/mask_rcnn_vanillanet_13.pth) | | ||
|
||
|
||
### Training | ||
|
||
You can download the ImageNet pre-trained [checkpoint](https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/vanillanet_13_act_num_4_kd_pretrain.pth) for VanillaNet-13(act_num=4), which is trained via [knowledge distillation(this paper)](https://arxiv.org/pdf/2305.15781.pdf). | ||
|
||
For example, to train a Mask R-CNN model with VanillaNet backbone and 8 gpus, run: | ||
``` | ||
python -m torch.distributed.launch --nproc_per_node=8 tools/train.py configs/vanillanet/mask_rcnn_vanillanet_13_mstrain_480-1024_adamw.py --gpus 8 --launcher pytorch --work-dir <WORK_DIR> | ||
``` | ||
|
||
### Inference | ||
|
||
For example, test with single-gpu, run: | ||
``` | ||
python -m torch.distributed.launch --nproc_per_node=1 tools/test.py configs/vanillanet/mask_rcnn_vanillanet_13_mstrain_480-1024_adamw.py <CHECKPOINT_FILE> --launcher pytorch --eval bbox segm | ||
``` | ||
|
||
## Acknowledgment | ||
|
||
This code is built based on [mmdetection](https://github.com/open-mmlab/mmdetection), [ConvNeXt](https://github.com/facebookresearch/ConvNeXt) repositories. |
110 changes: 110 additions & 0 deletions
110
object_detection/configs/vanillanet/mask_rcnn_vanillanet_13_mstrain_480-1024_adamw.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,110 @@ | ||
#Copyright (C) 2023. Huawei Technologies Co., Ltd. All rights reserved. | ||
|
||
#This program is free software; you can redistribute it and/or modify it under the terms of the MIT License. | ||
|
||
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT License for more details. | ||
|
||
|
||
_base_ = [ | ||
'../_base_/models/mask_rcnn_r50_fpn.py', | ||
'../_base_/schedules/schedule_1x.py', | ||
'../_base_/default_runtime.py' | ||
] | ||
|
||
# you can download ckpt from: | ||
# https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/vanillanet_13_act_num_4_kd_pretrain.pth | ||
checkpoint_file = '/your_path_to/vanillanet_13_act_num_4_kd_pretrain.pth' | ||
|
||
model = dict( | ||
backbone=dict( | ||
_delete_=True, | ||
type='Vanillanet', | ||
act_num=4, # enlarge act_num for better downstream performance | ||
dims=[128*4, 128*4, 256*4, 512*4, 512*4, 512*4, 512*4, 512*4, 512*4, 512*4, 1024*4, 1024*4], | ||
out_indices=[0, 1, 8, 10], | ||
strides=[1,2,2,1,1,1,1,1,1,2,1], | ||
init_cfg=dict(type='Pretrained', checkpoint=checkpoint_file)), | ||
neck=dict(in_channels=[128*4, 256*4, 512*4, 1024*4])) | ||
|
||
# dataset settings | ||
dataset_type = 'CocoDataset' | ||
data_root = 'data/coco/' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='LoadAnnotations', with_bbox=True, with_mask=True), | ||
dict( | ||
type='Resize', | ||
img_scale=[(1333, 480), (1333, 512), (1333, 544), (1333, 576), (1333, 608), (1333, 640), (1333, 672), (1333, 704), (1333, 736), (1333, 768), (1333, 800), (1333, 832), (1333, 864), (1333, 896), (1333, 928), (1333, 960), (1333, 992), (1333, 1024)], | ||
multiscale_mode='value', | ||
keep_ratio=True), | ||
dict(type='RandomFlip', flip_ratio=0.5), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='Pad', size_divisor=32), | ||
dict(type='DefaultFormatBundle'), | ||
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict( | ||
type='MultiScaleFlipAug', | ||
img_scale=(1333, 800), | ||
flip=False, | ||
transforms=[ | ||
dict(type='Resize', keep_ratio=True), | ||
dict(type='RandomFlip'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='Pad', size_divisor=32), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='Collect', keys=['img']), | ||
]) | ||
] | ||
data = dict( | ||
samples_per_gpu=4, | ||
workers_per_gpu=4, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_train2017.json', | ||
img_prefix=data_root + 'train2017/', | ||
pipeline=train_pipeline), | ||
persistent_workers=True, | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_val2017.json', | ||
img_prefix=data_root + 'val2017/', | ||
pipeline=test_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_val2017.json', | ||
img_prefix=data_root + 'val2017/', | ||
pipeline=test_pipeline)) | ||
evaluation = dict(metric=['bbox', 'segm']) | ||
|
||
optimizer = dict( | ||
_delete_=True, | ||
constructor='LearningRateDecayOptimizerConstructor', | ||
type='AdamW', | ||
lr=1.3e-4, | ||
betas=(0.9, 0.999), | ||
weight_decay=0.05, | ||
paramwise_cfg={ | ||
'decay_rate': 0.6, | ||
'decay_type': 'layer_wise', | ||
'num_layers': 6 | ||
}) | ||
|
||
lr_config = dict( | ||
policy='step', | ||
warmup='linear', | ||
warmup_iters=500, | ||
warmup_ratio=0.001, | ||
step=[10, 12]) | ||
runner = dict(max_epochs=12) | ||
|
||
log_config = dict( | ||
interval=200, | ||
hooks=[ | ||
dict(type='TextLoggerHook'), | ||
# dict(type='TensorboardLoggerHook') | ||
]) |
111 changes: 111 additions & 0 deletions
111
object_detection/configs/vanillanet/retinanet_vanillanet_13_mstrain_480-1024_adamw.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,111 @@ | ||
#Copyright (C) 2023. Huawei Technologies Co., Ltd. All rights reserved. | ||
|
||
#This program is free software; you can redistribute it and/or modify it under the terms of the MIT License. | ||
|
||
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT License for more details. | ||
|
||
|
||
_base_ = [ | ||
'../_base_/models/retinanet_r50_fpn.py', | ||
'../_base_/datasets/coco_detection.py', | ||
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py' | ||
] | ||
|
||
# you can download ckpt from: | ||
# https://github.com/huawei-noah/VanillaNet/releases/download/ckpt/vanillanet_13_act_num_4_kd_pretrain.pth | ||
checkpoint_file = '/your_path_to/vanillanet_13_act_num_4_kd_pretrain.pth' | ||
|
||
model = dict( | ||
backbone=dict( | ||
_delete_=True, | ||
type='Vanillanet', | ||
act_num=4, # enlarge act_num for better downstream performance | ||
dims=[128*4, 128*4, 256*4, 512*4, 512*4, 512*4, 512*4, 512*4, 512*4, 512*4, 1024*4, 1024*4], | ||
out_indices=[1, 8, 10], | ||
strides=[1,2,2,1,1,1,1,1,1,2,1], | ||
init_cfg=dict(type='Pretrained', checkpoint=checkpoint_file)), | ||
neck=dict(in_channels=[256*4, 512*4, 1024*4], start_level=0, num_outs=5)) | ||
|
||
# dataset settings | ||
dataset_type = 'CocoDataset' | ||
data_root = 'data/coco/' | ||
img_norm_cfg = dict( | ||
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='LoadAnnotations', with_bbox=True), | ||
dict( | ||
type='Resize', | ||
img_scale=[(1333, 480), (1333, 512), (1333, 544), (1333, 576), (1333, 608), (1333, 640), (1333, 672), (1333, 704), (1333, 736), (1333, 768), (1333, 800), (1333, 832), (1333, 864), (1333, 896), (1333, 928), (1333, 960), (1333, 992), (1333, 1024)], | ||
multiscale_mode='value', | ||
keep_ratio=True), | ||
dict(type='RandomFlip', flip_ratio=0.5), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='Pad', size_divisor=32), | ||
dict(type='DefaultFormatBundle'), | ||
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']), | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict( | ||
type='MultiScaleFlipAug', | ||
img_scale=(1333, 800), | ||
flip=False, | ||
transforms=[ | ||
dict(type='Resize', keep_ratio=True), | ||
dict(type='RandomFlip'), | ||
dict(type='Normalize', **img_norm_cfg), | ||
dict(type='Pad', size_divisor=32), | ||
dict(type='ImageToTensor', keys=['img']), | ||
dict(type='Collect', keys=['img']), | ||
]) | ||
] | ||
data = dict( | ||
samples_per_gpu=4, | ||
workers_per_gpu=4, | ||
train=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_train2017.json', | ||
img_prefix=data_root + 'train2017/', | ||
pipeline=train_pipeline), | ||
val=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_val2017.json', | ||
img_prefix=data_root + 'val2017/', | ||
pipeline=test_pipeline), | ||
test=dict( | ||
type=dataset_type, | ||
ann_file=data_root + 'annotations/instances_val2017.json', | ||
img_prefix=data_root + 'val2017/', | ||
pipeline=test_pipeline)) | ||
evaluation = dict(interval=1, metric='bbox') | ||
|
||
optimizer = dict( | ||
_delete_=True, | ||
constructor='LearningRateDecayOptimizerConstructor', | ||
type='AdamW', | ||
lr=8e-5, | ||
betas=(0.9, 0.999), | ||
weight_decay=0.05, | ||
paramwise_cfg={ | ||
'decay_rate': 0.6, | ||
'decay_type': 'layer_wise', | ||
'num_layers': 6 | ||
}) | ||
|
||
optimizer_config = dict(grad_clip=None) | ||
# learning policy | ||
lr_config = dict( | ||
policy='step', | ||
warmup='linear', | ||
warmup_iters=500, | ||
warmup_ratio=0.001, | ||
step=[10, 11]) | ||
runner = dict(type='EpochBasedRunner', max_epochs=12) | ||
|
||
log_config = dict( | ||
interval=200, | ||
hooks=[ | ||
dict(type='TextLoggerHook'), | ||
# dict(type='TensorboardLoggerHook') | ||
]) |
Oops, something went wrong.