Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmcls -> mmpretrain #2003

Merged
merged 16 commits into from
Apr 28, 2023
Merged
10 changes: 5 additions & 5 deletions .github/scripts/linux/test_full_pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ mkdir -p $work_dir $mmdeploy_dir/data

model_cfg=$work_dir/resnet18_8xb32_in1k.py
checkpoint=$work_dir/resnet18_8xb32_in1k_20210831-fbbb1da6.pth
sdk_cfg=configs/mmcls/classification_sdk_dynamic.py
sdk_cfg=configs/mmpretrain/classification_sdk_dynamic.py
input_img=tests/data/tiger.jpeg

python3 -m mim download mmcls --config resnet18_8xb32_in1k --dest $work_dir
python3 -m mim download mmpretrain --config resnet18_8xb32_in1k --dest $work_dir

if [ $backend == "ort" ]; then
deploy_cfg=configs/mmcls/classification_onnxruntime_dynamic.py
deploy_cfg=configs/mmpretrain/classification_onnxruntime_dynamic.py
model=$work_dir/end2end.onnx
elif [ $backend == "trt" ]; then
deploy_cfg=configs/mmcls/classification_tensorrt-fp16_dynamic-224x224-224x224.py
deploy_cfg=configs/mmpretrain/classification_tensorrt-fp16_dynamic-224x224-224x224.py
model=$work_dir/end2end.engine
elif [ $backend == "ncnn" ]; then
deploy_cfg=configs/mmcls/classification_ncnn_static.py
deploy_cfg=configs/mmpretrain/classification_ncnn_static.py
model="$work_dir/end2end.param $work_dir/end2end.bin"
else
echo "Unsupported Backend=$backend"
Expand Down
8 changes: 4 additions & 4 deletions .github/scripts/quantize_to_ncnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
[
'hrnet.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/hrnet.onnx', # noqa: E501
'~/mmclassification/configs/hrnet/hrnet-w18_4xb32_in1k.py',
'~/mmpretrain/configs/hrnet/hrnet-w18_4xb32_in1k.py',
],
[
'resnet18.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/resnet18.onnx', # noqa: E501
'~/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py',
'~/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py',
],
[
'mobilenet-v2.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/mobilenet-v2.onnx', # noqa: E501
'~/mmclassification/configs/mobilenet_v2/mobilenet-v2_8xb32_in1k.py',
'~/mmpretrain/configs/mobilenet_v2/mobilenet-v2_8xb32_in1k.py',
]
]

Expand All @@ -45,7 +45,7 @@ def main():
model = conf[0]
os.system('wget {}'.format(conf[1]))
model_cfg = conf[2]
deploy_cfg = 'configs/mmcls/classification_ncnn-int8_static.py'
deploy_cfg = 'configs/mmpretrain/classification_ncnn-int8_static.py'
quant_cmd = [
'python', 'tools/onnx2ncnn_quant_table.py', '--onnx', model,
'--deploy-cfg', deploy_cfg, '--model-cfg', model_cfg, '--out-onnx',
Expand Down
12 changes: 6 additions & 6 deletions .github/scripts/test_onnx2ncnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
# list of tuple: config, pretrained model, onnx filename
CONFIGS = [
(
'mmclassification/configs/vision_transformer/vit-base-p32_ft-64xb64_in1k-384.py', # noqa: E501
'mmpretrain/configs/vision_transformer/vit-base-p32_ft-64xb64_in1k-384.py', # noqa: E501
'https://download.openmmlab.com/mmclassification/v0/vit/finetune/vit-base-p32_in21k-pre-3rdparty_ft-64xb64_in1k-384_20210928-9cea8599.pth', # noqa: E501
'vit.onnx'),
(
'mmclassification/configs/resnet/resnet50_8xb32_in1k.py',
'mmpretrain/configs/resnet/resnet50_8xb32_in1k.py',
'https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_8xb32_in1k_20210831-ea4938fc.pth', # noqa: E501
'resnet50.onnx',
),
(
'mmclassification/configs/resnet/resnet18_8xb32_in1k.py',
'mmpretrain/configs/resnet/resnet18_8xb32_in1k.py',
'https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth', # noqa: E501
'resnet18.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/resnet18.onnx', # noqa: E501
),
(
'mmclassification/configs/mobilenet_v2/mobilenet-v2_8xb32_in1k.py',
'mmpretrain/configs/mobilenet_v2/mobilenet-v2_8xb32_in1k.py',
'https://download.openmmlab.com/mmclassification/v0/mobilenet_v2/mobilenet_v2_batch256_imagenet_20200708-3b2dc3af.pth', # noqa: E501
'mobilenet-v2.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/mobilenet-v2.onnx', # noqa: E501
Expand All @@ -36,7 +36,7 @@ def parse_args():
parser.add_argument(
'--run', type=bool, help='Execute mmdeploy_onnx2ncnn bin.')
parser.add_argument(
'--repo-dir', type=str, default='~/', help='mmcls directory.')
'--repo-dir', type=str, default='~/', help='mmpretrain directory.')
parser.add_argument(
'--out',
type=str,
Expand All @@ -56,7 +56,7 @@ def generate_onnx(args):
model = conf[1]
convert_cmd = [
'python', 'tools/deploy.py',
'configs/mmcls/classification_ncnn_static.py', config, model,
'configs/mmpretrain/classification_ncnn_static.py', config, model,
'cat-dog.png', '--work-dir', 'work_dir', '--device', 'cpu'
]
print(subprocess.call(convert_cmd))
Expand Down
8 changes: 4 additions & 4 deletions .github/scripts/windows/test_full_pipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ $work_dir="work_dir"
New-Item -Path $work_dir, .\data -ItemType Directory -Force
$model_cfg="$work_dir\resnet18_8xb32_in1k.py"
$checkpoint="$work_dir\resnet18_8xb32_in1k_20210831-fbbb1da6.pth"
$sdk_cfg="configs\mmcls\classification_sdk_dynamic.py"
$sdk_cfg="configs\mmpretrain\classification_sdk_dynamic.py"
$input_img="tests\data\tiger.jpeg"

python -m mim download mmcls --config resnet18_8xb32_in1k --dest $work_dir
python -m mim download mmpretrain --config resnet18_8xb32_in1k --dest $work_dir

if ($Backend -eq "ort") {
$deploy_cfg="configs\mmcls\classification_onnxruntime_dynamic.py"
$deploy_cfg="configs\mmpretrain\classification_onnxruntime_dynamic.py"
$model="$work_dir\end2end.onnx"
} elseif ($Backend -eq "trt") {
$deploy_cfg="configs\mmcls\classification_tensorrt-fp16_dynamic-224x224-224x224.py"
$deploy_cfg="configs\mmpretrain\classification_tensorrt-fp16_dynamic-224x224-224x224.py"
$model="$work_dir\end2end.engine"
} else {
Write-Host "Unsupported Backend=$Backend"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/backend-ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
python -m pip install mmcv-lite openmim
python tools/scripts/build_ubuntu_x64_ort.py 8
python -c 'import mmdeploy.apis.onnxruntime as ort_api; assert ort_api.is_available(with_custom_ops=True)'
- name: test mmcls full pipeline
- name: test mmpretrain full pipeline
run: |
python -m mim install $(cat requirements/codebases.txt | grep mmcls)
python -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
export MMDEPLOY_DIR=$(pwd)
export ONNXRUNTIME_DIR=$MMDEPLOY_DIR/../mmdeploy-dep/onnxruntime-linux-x64-1.8.1
export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$MMDEPLOY_DIR/build/install/lib:$LD_LIBRARY_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backend-pplnn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
python3 -V
python3 -m pip install openmim numpy
python3 -m pip install -r requirements.txt
python3 -m mim install $(cat requirements/codebases.txt | grep mmcls)
python3 -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
python3 -m pip list
- name: Build SDK
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
python3 -m pip install opencv-python==4.5.4.60 opencv-python-headless==4.5.4.60 opencv-contrib-python==4.5.4.60
python3 -m pip install openmim numpy pycuda clip transformers
python3 -m pip install -r requirements.txt
python3 -m mim install $(cat requirements/codebases.txt | grep mmcls)
python3 -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
python3 -m pip list
- name: Build SDK
run: |
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
python -m pip install openmim
python -m pip install -r requirements.txt
python -m pip install -r requirements/backends.txt
python -m mim install "mmcls>=1.0.0rc2"
python -m mim install "mmpretrain>=1.0.0rc7"
python -m pip list
- name: Build mmdeploy
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/quantize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ jobs:
python -m pip install -r requirements.txt
python -m pip install -U numpy

- name: Install mmcls
- name: Install mmpretrain
run: |
python -m pip install openmim
python -m mim install $(cat requirements/codebases.txt | grep mmcls)
git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmclassification.git ~/mmclassification
cd ~/mmclassification && python -m pip install . && cd -
python -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmpretrain.git ~/mmpretrain
cd ~/mmpretrain && python -m pip install . && cd -
- name: Install ppq
run: |
python -m pip install protobuf==3.20.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MMDeploy is an open-source deep learning model deployment toolset. It is a part

The currently supported codebases and models are as follows, and more will be included in the future

- [mmcls](docs/en/04-supported-codebases/mmcls.md)
- [mmpretrain](docs/en/04-supported-codebases/mmpretrain.md)
- [mmdet](docs/en/04-supported-codebases/mmdet.md)
- [mmseg](docs/en/04-supported-codebases/mmseg.md)
- [mmedit](docs/en/04-supported-codebases/mmedit.md)
Expand Down
10 changes: 5 additions & 5 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
全新的 MMDeploy 1.x 已发布,该版本适配OpenMMLab 2.0生态体系,使用时务必**对齐版本**。
MMDeploy 代码库默认分支从`master`切换至`main`。 MMDeploy 0.x (`master`)将逐步废弃,新特性将只添加到 MMDeploy 1.x (`main`)。

| mmdeploy | mmengine | mmcv | mmdet | mmcls and others |
| :------: | :------: | :------: | :------: | :--------------: |
| 0.x.y | - | \<=1.x.y | \<=2.x.y | 0.x.y |
| 1.x.y | 0.x.y | 2.x.y | 3.x.y | 1.x.y |
| mmdeploy | mmengine | mmcv | mmdet | mmpretrain and others |
| :------: | :------: | :------: | :------: | :-------------------: |
| 0.x.y | - | \<=1.x.y | \<=2.x.y | 0.x.y |
| 1.x.y | 0.x.y | 2.x.y | 3.x.y | 1.x.y |

## 介绍

Expand All @@ -52,7 +52,7 @@ MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为

### 支持超多 OpenMMLab 算法库

- [mmcls](docs/zh_cn/04-supported-codebases/mmcls.md)
- [mmpretrain](docs/zh_cn/04-supported-codebases/mmpretrain.md)
- [mmdet](docs/zh_cn/04-supported-codebases/mmdet.md)
- [mmseg](docs/zh_cn/04-supported-codebases/mmseg.md)
- [mmedit](docs/zh_cn/04-supported-codebases/mmedit.md)
Expand Down
3 changes: 0 additions & 3 deletions configs/mmcls/classification_static.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_base_ = ['../_base_/torchscript_config.py', '../_base_/backends/coreml.py']

codebase_config = dict(type='mmcls', task='Classification')
codebase_config = dict(type='mmpretrain', task='Classification')

backend_config = dict(model_inputs=[
dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

backend_config = dict(
pipeline=[dict(type='LoadImageFromFile'),
dict(type='PackClsInputs')])
dict(type='PackInputs')])
3 changes: 3 additions & 0 deletions configs/mmpretrain/classification_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_base_ = ['../_base_/onnx_config.py']

codebase_config = dict(type='mmpretrain', task='Classification')
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
]

ir_config = dict(input_shape=None)
codebase_config = dict(type='mmcls', task='Classification')
codebase_config = dict(type='mmpretrain', task='Classification')
7 changes: 6 additions & 1 deletion csrc/mmdeploy/codebase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ endif ()

foreach (codebase IN LISTS CODEBASES)
message(STATUS "build codebase: ${codebase}")
add_subdirectory(${codebase})
if (codebase STREQUAL "mmpretrain")
set(subdir_name "mmcls")
else()
set(subdir_name ${codebase})
endif()
add_subdirectory(${subdir_name})
endforeach ()
4 changes: 2 additions & 2 deletions docs/en/01-how-to-build/cmake_option.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@
</tr>
<tr>
<td>MMDEPLOY_CODEBASES</td>
<td>{"mmcls", "mmdet", "mmseg", "mmedit", "mmocr", "all"}</td>
<td>{"mmpretrain", "mmdet", "mmseg", "mmedit", "mmocr", "all"}</td>
RunningLeon marked this conversation as resolved.
Show resolved Hide resolved
<td>all</td>
<td>Enable codebase's postprocess modules. You can provide a semicolon separated list of codebase names to enable them, e.g., <code>-DMMDEPLOY_CODEBASES="mmcls;mmdet"</code>. Or you can pass <code>all</code> to enable them all, i.e., <code>-DMMDEPLOY_CODEBASES=all</code></td>
<td>Enable codebase's postprocess modules. You can provide a semicolon separated list of codebase names to enable them, e.g., <code>-DMMDEPLOY_CODEBASES="mmpretrain;mmdet"</code>. Or you can pass <code>all</code> to enable them all, i.e., <code>-DMMDEPLOY_CODEBASES=all</code></td>
RunningLeon marked this conversation as resolved.
Show resolved Hide resolved
</tr>

</tbody>
Expand Down
6 changes: 3 additions & 3 deletions docs/en/01-how-to-build/cross_build_ncnn_aarch64.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Device

## 1. Model Convert on Host

Refer to the doc to install [mmdeploy](../01-how-to-build/) and [mmcls](https://github.com/open-mmlab/mmclassification), and convert resnet18 for model package
Refer to the doc to install [mmdeploy](../01-how-to-build/) and [mmpretrain](https://github.com/open-mmlab/mmpretrain), and convert resnet18 for model package

```bash
export MODEL_CONFIG=/path/to/mmclassification/configs/resnet/resnet18_8xb32_in1k.py
export MODEL_CONFIG=/path/to/mmpretrain/configs/resnet/resnet18_8xb32_in1k.py
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth

# Convert resnet18
cd /path/to/mmdeploy
python tools/deploy.py \
configs/mmcls/classification_ncnn_static.py \
configs/mmpretrain/classification_ncnn_static.py \
$MODEL_CONFIG \
$MODEL_PATH \
tests/data/tiger.jpeg \
Expand Down
4 changes: 2 additions & 2 deletions docs/en/01-how-to-build/riscv.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ You can refer to [Build document](./linux-x86_64.md) to install ncnn inference e
b) Convert model

```bash
export MODEL_CONFIG=/path/to/mmclassification/configs/resnet/resnet18_8xb32_in1k.py
export MODEL_CONFIG=/path/to/mmpretrain/configs/resnet/resnet18_8xb32_in1k.py
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth

# Convert the model
cd /path/to/mmdeploy
python tools/deploy.py \
configs/mmcls/classification_ncnn_static.py \
configs/mmpretrain/classification_ncnn_static.py \
$MODEL_CONFIG \
$MODEL_PATH \
tests/data/tiger.jpeg \
Expand Down
12 changes: 6 additions & 6 deletions docs/en/01-how-to-build/rockchip.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ It is recommended to create a virtual environment for the project.
conda install pytorch==1.8.0 torchvision==0.9.0 cudatoolkit=11.1 -c pytorch -c conda-forge
```

To work with models from [MMClassification](https://mmclassification.readthedocs.io/en/1.x/get_started.html), you may need to install it additionally.
To work with models from [MMPretrain](https://mmpretrain.readthedocs.io/en/latest/get_started.html), you may need to install it additionally.

## Usage

Example:

```bash
python tools/deploy.py \
configs/mmcls/classification_rknn_static.py \
/mmclassification_dir/configs/resnet/resnet50_8xb32_in1k.py \
configs/mmpretrain/classification_rknn_static.py \
/mmpretrain_dir/configs/resnet/resnet50_8xb32_in1k.py \
https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_batch256_imagenet_20200708-cfb998bf.pth \
/mmclassification_dir/demo/demo.JPEG \
/mmpretrain_dir/demo/demo.JPEG \
--work-dir ../resnet50 \
--device cpu
```

## Deployment config

With the deployment config, you can modify the `backend_config` for your preference. An example `backend_config` of mmclassification is shown as below:
With the deployment config, you can modify the `backend_config` for your preference. An example `backend_config` of mmpretrain is shown as below:

```python
backend_config = dict(
Expand Down Expand Up @@ -119,7 +119,7 @@ First make sure that`--dump-info`is used during convert model, so that the worki
```bash
cd /path/to/mmdeploy
adb push resnet50 /data/local/tmp/resnet50
adb push /mmclassification_dir/demo/demo.JPEG /data/local/tmp/resnet50/demo.JPEG
adb push /mmpretrain_dir/demo/demo.JPEG /data/local/tmp/resnet50/demo.JPEG
cd build
adb push lib /data/local/tmp/lib
adb push bin/image_classification /data/local/tmp/image_classification
Expand Down
10 changes: 5 additions & 5 deletions docs/en/01-how-to-build/snpe.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ $ python3 -m pip install -e .

## 3. Test the model

Take Resnet-18 as an example. First refer to [documentation to install mmcls](https://github.com/open-mmlab/mmclassification/tree/1.x) and use `tools/deploy.py` to convert the model.
Take Resnet-18 as an example. First refer to [documentation to install mmpretrain](https://github.com/open-mmlab/mmpretrain/tree/main) and use `tools/deploy.py` to convert the model.

```bash
$ export MODEL_CONFIG=/path/to/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py
$ export MODEL_CONFIG=/path/to/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py
$ export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20210528-bd6371c8.pth

# Convert the model
$ cd /path/to/mmdeploy
$ python3 tools/deploy.py configs/mmcls/classification_snpe_static.py $MODEL_CONFIG $MODEL_PATH /path/to/test.png --work-dir resnet18 --device cpu --uri 10.0.0.1\:60000 --dump-info
$ python3 tools/deploy.py configs/mmpretrain/classification_snpe_static.py $MODEL_CONFIG $MODEL_PATH /path/to/test.png --work-dir resnet18 --device cpu --uri 10.0.0.1\:60000 --dump-info

# Test
$ python3 tools/test.py configs/mmcls/classification_snpe_static.py $MODEL_CONFIG --model reset18/end2end.dlc --metrics accuracy precision f1_score recall --uri 10.0.0.1\:60000
$ python3 tools/test.py configs/mmpretrain/classification_snpe_static.py $MODEL_CONFIG --model reset18/end2end.dlc --metrics accuracy precision f1_score recall --uri 10.0.0.1\:60000
```

Note that `--uri` is required to specify the ip and port of the snpe inference service, ipv4 and ipv6 addresses can be used.
Expand Down Expand Up @@ -163,7 +163,7 @@ $ adb push bin/image_classification /data/local/tmp/resnet18/
Set up environment variable and execute the sample.

```bash
$ adb push /path/to/mmcls/demo/demo.JPEG /data/local/tmp
$ adb push /path/to/mmpretrain/demo/demo.JPEG /data/local/tmp
$ adb shell
venus:/ $ cd /data/local/tmp/resnet18
venus:/data/local/tmp/resnet18 $ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/data/local/tmp/lib
Expand Down
Loading