Skip to content

Commit

Permalink
replace mmcls with mmpretrain (open-mmlab#10545)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaAndroid authored Jun 28, 2023
1 parent 02a7f2a commit 5036dc5
Show file tree
Hide file tree
Showing 29 changed files with 152 additions and 130 deletions.
18 changes: 10 additions & 8 deletions .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
pip install -r requirements/tests.txt -r requirements/optional.txt
pip install --force-reinstall pycocotools
pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
pip install -r requirements/tracking.txt
pip install git+https://github.com/cocodataset/panopticapi.git
pip install git+https://github.com/JonathonLuiten/TrackEval.git
- run:
Expand All @@ -93,10 +94,10 @@ jobs:
type: string
cuda:
type: enum
enum: ["10.1", "10.2", "11.1", "11.7"]
enum: ["11.1", "11.7"]
cudnn:
type: integer
default: 7
default: 8
machine:
image: ubuntu-2004-cuda-11.4:202110-01
# docker_layer_caching: true
Expand All @@ -123,6 +124,7 @@ jobs:
docker exec mmdetection pip install -r requirements/tests.txt -r requirements/optional.txt
docker exec mmdetection pip install pycocotools
docker exec mmdetection pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
docker exec mmdetection pip install -r requirements/tracking.txt
docker exec mmdetection pip install git+https://github.com/cocodataset/panopticapi.git
docker exec mmdetection pip install git+https://github.com/JonathonLuiten/TrackEval.git
docker exec mmdetection python -c 'import mmcv; print(mmcv.__version__)'
Expand Down Expand Up @@ -157,9 +159,9 @@ workflows:
- dev-3.x
- build_cpu:
name: minimum_version_cpu
torch: 1.7.1
torchvision: 0.8.2
python: 3.7.4 # The lowest python 3.7.x version available on CircleCI images
torch: 1.8.0
torchvision: 0.9.0
python: 3.7.16
requires:
- lint
- build_cpu:
Expand All @@ -178,7 +180,7 @@ workflows:
torch: 1.8.1
# Use double quotation mark to explicitly specify its type
# as string instead of number
cuda: "10.2"
cuda: "11.1"
requires:
- hold
- build_cuda:
Expand All @@ -194,8 +196,8 @@ workflows:
jobs:
- build_cuda:
name: minimum_version_gpu
torch: 1.6.0
cuda: "10.1"
torch: 1.8.0
cuda: "11.1"
filters:
branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion .dev_scripts/benchmark_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'pip install instaboostfast',
'pip install git+https://github.com/cocodataset/panopticapi.git',
'pip install timm',
'pip install mmcls>=1.0.0rc0',
'pip install mmpretrain',
'pip install git+https://github.com/lvis-dataset/lvis-api.git',
'pip install -r ../requirements/multimodal.txt',
'pip install -r ../requirements/tracking.txt',
Expand Down
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ If this PR introduces a new feature, it is better to list some use cases here, a

1. Pre-commit or other linting tools are used to fix the potential lint issues.
2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMPreTrain.
4. The documentation has been modified accordingly, like docstring or example tutorials.
4 changes: 2 additions & 2 deletions configs/convnext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ The "Roaring 20s" of visual recognition began with the introduction of Vision Tr

**Note**:

- ConvNeXt backbone needs to install [MMClassification](https://github.com/open-mmlab/mmclassification) first, which has abundant backbones for downstream tasks.
- ConvNeXt backbone needs to install [MMPreTrain](https://github.com/open-mmlab/mmpretrain) first, which has abundant backbones for downstream tasks.

```shell
pip install mmcls>=1.0
pip install mmpretrain
```

- The performance is unstable. `Cascade Mask R-CNN` may fluctuate about 0.2 mAP.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
_base_ = './cascade-mask-rcnn_convnext-t-p4-w7_fpn_4conv1fc-giou_amp-ms-crop-3x_coco.py' # noqa

# TODO: delete custom_imports after mmcls supports auto import
# please install mmcls>=1.0
# import mmcls.models to trigger register_module in mmcls
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(
imports=['mmpretrain.models'], allow_failed_imports=False)
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/convnext/downstream/convnext-small_3rdparty_32xb128-noema_in1k_20220301-303e75e3.pth' # noqa

model = dict(
backbone=dict(
_delete_=True,
type='mmcls.ConvNeXt',
type='mmpretrain.ConvNeXt',
arch='small',
out_indices=[0, 1, 2, 3],
drop_path_rate=0.6,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]

# TODO: delete custom_imports after mmcls supports auto import
# please install mmcls>=1.0
# import mmcls.models to trigger register_module in mmcls
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(
imports=['mmpretrain.models'], allow_failed_imports=False)
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/convnext/downstream/convnext-tiny_3rdparty_32xb128-noema_in1k_20220301-795e9634.pth' # noqa

model = dict(
backbone=dict(
_delete_=True,
type='mmcls.ConvNeXt',
type='mmpretrain.ConvNeXt',
arch='tiny',
out_indices=[0, 1, 2, 3],
drop_path_rate=0.4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]

# TODO: delete custom_imports after mmcls supports auto import
# please install mmcls>=1.0
# import mmcls.models to trigger register_module in mmcls
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(
imports=['mmpretrain.models'], allow_failed_imports=False)
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/convnext/downstream/convnext-tiny_3rdparty_32xb128-noema_in1k_20220301-795e9634.pth' # noqa

model = dict(
backbone=dict(
_delete_=True,
type='mmcls.ConvNeXt',
type='mmpretrain.ConvNeXt',
arch='tiny',
out_indices=[0, 1, 2, 3],
drop_path_rate=0.4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
detector=detector,
reid=dict(
type='BaseReID',
data_preprocessor=None,
data_preprocessor=dict(type='mmpretrain.ClsDataPreprocessor'),
backbone=dict(
type='mmcls.ResNet',
type='mmpretrain.ResNet',
depth=50,
num_stages=4,
out_indices=(3, ),
Expand All @@ -55,7 +55,7 @@
fc_channels=1024,
out_channels=128,
num_classes=380,
loss_cls=dict(type='mmcls.CrossEntropyLoss', loss_weight=1.0),
loss_cls=dict(type='mmpretrain.CrossEntropyLoss', loss_weight=1.0),
loss_triplet=dict(type='TripletLoss', margin=0.3, loss_weight=1.0),
norm_cfg=dict(type='BN1d'),
act_cfg=dict(type='ReLU')),
Expand Down
2 changes: 1 addition & 1 deletion configs/reid/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Training a ReID Model

You may want to train a ReID model for multiple object tracking or other applications. We support ReID model training in MMDetection, which is built upon [MMClassification](https://github.com/open-mmlab/mmclassification).
You may want to train a ReID model for multiple object tracking or other applications. We support ReID model training in MMDetection, which is built upon [MMPretrain](https://github.com/open-mmlab/mmpretrain).

### 1. Development Environment Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
std=[58.395, 57.12, 57.375],
to_rgb=True),
backbone=dict(
type='mmcls.ResNet',
type='mmpretrain.ResNet',
depth=50,
num_stages=4,
out_indices=(3, ),
Expand All @@ -22,7 +22,7 @@
fc_channels=1024,
out_channels=128,
num_classes=380,
loss_cls=dict(type='mmcls.CrossEntropyLoss', loss_weight=1.0),
loss_cls=dict(type='mmpretrain.CrossEntropyLoss', loss_weight=1.0),
loss_triplet=dict(type='TripletLoss', margin=0.3, loss_weight=1.0),
norm_cfg=dict(type='BN1d'),
act_cfg=dict(type='ReLU')),
Expand Down
8 changes: 4 additions & 4 deletions configs/rtmdet/classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ In this folder, we provide the imagenet pre-training config of RTMDet's backbone

## Requirements

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

Install by MIM:

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

or install by pip:

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

## 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).
To pre-train on ImageNet, you need to prepare the dataset first. Please refer to the [guide](https://mmpretrain.readthedocs.io/en/latest/user_guides/dataset_prepare.html#imagenet).

## How to Train

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_base_ = [
'mmcls::_base_/datasets/imagenet_bs256_rsb_a12.py',
'mmcls::_base_/schedules/imagenet_bs2048_rsb.py',
'mmcls::_base_/default_runtime.py'
'mmpretrain::_base_/datasets/imagenet_bs256_rsb_a12.py',
'mmpretrain::_base_/schedules/imagenet_bs2048_rsb.py',
'mmpretrain::_base_/default_runtime.py'
]

model = dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
detector=detector,
reid=dict(
type='BaseReID',
data_preprocessor=None,
data_preprocessor=dict(type='mmpretrain.ClsDataPreprocessor'),
backbone=dict(
type='mmcls.ResNet',
type='mmpretrain.ResNet',
depth=50,
num_stages=4,
out_indices=(3, ),
Expand All @@ -37,7 +37,7 @@
fc_channels=1024,
out_channels=128,
num_classes=380,
loss_cls=dict(type='mmcls.CrossEntropyLoss', loss_weight=1.0),
loss_cls=dict(type='mmpretrain.CrossEntropyLoss', loss_weight=1.0),
loss_triplet=dict(type='TripletLoss', margin=0.3, loss_weight=1.0),
norm_cfg=dict(type='BN1d'),
act_cfg=dict(type='ReLU'))),
Expand Down
10 changes: 5 additions & 5 deletions configs/timm_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ Py**T**orch **Im**age **M**odels (`timm`) is a collection of image models, layer

### Install additional requirements

MMDetection supports timm backbones via `TIMMBackbone`, a wrapper class in MMClassification.
Thus, you need to install `mmcls` in addition to timm.
MMDetection supports timm backbones via `TIMMBackbone`, a wrapper class in MMPretrain.
Thus, you need to install `mmpretrain` in addition to timm.
If you have already installed requirements for mmdet, run

```shell
pip install 'dataclasses; python_version<"3.7"'
pip install timm
pip install 'mmcls>=0.20.0'
pip install mmpretrain
```

See [this document](https://mmclassification.readthedocs.io/en/latest/install.html) for the details of MMClassification installation.
See [this document](https://mmpretrain.readthedocs.io/en/latest/get_started.html#installation) for the details of MMPretrain installation.

### Edit config

- See example configs for basic usage.
- See the documents of [timm feature extraction](https://rwightman.github.io/pytorch-image-models/feature_extraction/#multi-scale-feature-maps-feature-pyramid) and [TIMMBackbone](https://mmclassification.readthedocs.io/en/latest/api.html#mmcls.models.backbones.TIMMBackbone) for details.
- See the documents of [timm feature extraction](https://rwightman.github.io/pytorch-image-models/feature_extraction/#multi-scale-feature-maps-feature-pyramid) and [TIMMBackbone](https://mmpretrain.readthedocs.io/en/latest/api/generated/mmpretrain.models.backbones.TIMMBackbone.html#mmpretrain.models.backbones.TIMMBackbone) for details.
- Which feature map is output depends on the backbone.
Please check `backbone out_channels` and `backbone out_strides` in your log, and modify `model.neck.in_channels` and `model.backbone.out_indices` if necessary.
- If you use Vision Transformer models that do not support `features_only=True`, add `custom_hooks = []` to your config to disable `NumClassCheckHook`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]

# TODO: delete custom_imports after mmcls supports auto import
# please install mmcls>=1.0
# import mmcls.models to trigger register_module in mmcls
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(
imports=['mmpretrain.models'], allow_failed_imports=False)

model = dict(
backbone=dict(
_delete_=True,
type='mmcls.TIMMBackbone',
type='mmpretrain.TIMMBackbone',
model_name='efficientnet_b1',
features_only=True,
pretrained=True,
Expand Down
10 changes: 5 additions & 5 deletions configs/timm_example/retinanet_timm-tv-resnet50_fpn_1x_coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
'../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]

# TODO: delete custom_imports after mmcls supports auto import
# please install mmcls>=1.0
# import mmcls.models to trigger register_module in mmcls
custom_imports = dict(imports=['mmcls.models'], allow_failed_imports=False)
# please install mmpretrain
# import mmpretrain.models to trigger register_module in mmpretrain
custom_imports = dict(
imports=['mmpretrain.models'], allow_failed_imports=False)

model = dict(
backbone=dict(
_delete_=True,
type='mmcls.TIMMBackbone',
type='mmpretrain.TIMMBackbone',
model_name='tv_resnet50', # ResNet-50 with torchvision weights
features_only=True,
pretrained=True,
Expand Down
Loading

0 comments on commit 5036dc5

Please sign in to comment.