mirror of
https://github.com/open-mmlab/mmpretrain.git
synced 2025-06-03 14:59:18 +08:00
Add Chinese Readme and docs (#221)
* Add Citation in README Add Citation and mmgeneration in README * Merge inference and test section in getting_start.md and other small chagne. * Fix code type in install.md * Add Chinese Readme * README and docs improvement.
This commit is contained in:
parent
01d2849b76
commit
3d87474c71
16
README.md
16
README.md
@ -9,6 +9,8 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
English | [简体中文](/README_zh-CN.md)
|
||||
|
||||
MMClassification is an open source image classification toolbox based on PyTorch. It is
|
||||
a part of the [OpenMMLab](https://openmmlab.com/) project.
|
||||
|
||||
@ -56,6 +58,19 @@ Please refer to [install.md](docs/install.md) for installation and dataset prepa
|
||||
|
||||
Please see [getting_started.md](docs/getting_started.md) for the basic usage of MMClassification. There are also tutorials for [finetuning models](docs/tutorials/finetune.md), [adding new dataset](docs/tutorials/new_dataset.md), [designing data pipeline](docs/tutorials/data_pipeline.md), and [adding new modules](docs/tutorials/new_modules.md).
|
||||
|
||||
## Citation
|
||||
|
||||
If you find this project useful in your research, please consider cite:
|
||||
|
||||
```BibTeX
|
||||
@misc{2020mmclassification,
|
||||
title={OpenMMLab's Image Classification Toolbox and Benchmark},
|
||||
author={MMClassification Contributors},
|
||||
howpublished = {\url{https://github.com/open-mmlab/mmclassification}},
|
||||
year={2020}
|
||||
}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
We appreciate all contributions to improve MMClassification.
|
||||
@ -78,3 +93,4 @@ We wish that the toolbox and benchmark could serve the growing research communit
|
||||
- [MMPose](https://github.com/open-mmlab/mmpose): OpenMMLab pose estimation toolbox and benchmark.
|
||||
- [MMEditing](https://github.com/open-mmlab/mmediting): OpenMMLab image and video editing toolbox.
|
||||
- [MMOCR](https://github.com/open-mmlab/mmocr): OpenMMLab toolbox for text detection, recognition and understanding.
|
||||
- [MMGeneration](https://github.com/open-mmlab/mmgeneration): OpenMMlab toolkit for generative models.
|
||||
|
101
README_zh-CN.md
Normal file
101
README_zh-CN.md
Normal file
@ -0,0 +1,101 @@
|
||||
<div align="center">
|
||||
<img src="resources/mmcls-logo.png" width="600"/>
|
||||
</div>
|
||||
|
||||
[English](/README.md) | 简体中文
|
||||
|
||||
[](https://github.com/open-mmlab/mmclassification/actions)
|
||||
[](https://mmclassification.readthedocs.io/en/latest/?badge=latest)
|
||||
[](https://codecov.io/gh/open-mmlab/mmclassification)
|
||||
[](https://github.com/open-mmlab/mmclassification/blob/master/LICENSE)
|
||||
|
||||
## Introduction
|
||||
|
||||
MMClassification是一款基于PyTorch的开源图像分类工具箱,是 [OpenMMLab](https://openmmlab.com/) 项目的成员之一
|
||||
|
||||
参考文档: https://mmclassification.readthedocs.io/en/latest/
|
||||
|
||||

|
||||
|
||||
### 主要特性
|
||||
|
||||
- 支持多样的主干网络与预训练模型
|
||||
- 支持配置多种训练技巧
|
||||
- 大量的训练配置文件
|
||||
- 高效率和高可扩展性
|
||||
|
||||
## 许可证
|
||||
|
||||
该项目开源自 [Apache 2.0 license](LICENSE).
|
||||
|
||||
## 更新日志
|
||||
|
||||
2021/4/1 发布了 v0.10.0 版本
|
||||
|
||||
发布历史和更新细节请参考 [更新日志](docs/changelog.md)
|
||||
|
||||
## 基准测试及模型库
|
||||
|
||||
相关结果和模型可在 [model zoo](docs_zh-CN/model_zoo.md) 中获得
|
||||
|
||||
支持的主干网络:
|
||||
|
||||
- [x] ResNet
|
||||
- [x] ResNeXt
|
||||
- [x] SE-ResNet
|
||||
- [x] SE-ResNeXt
|
||||
- [x] RegNet
|
||||
- [x] ShuffleNetV1
|
||||
- [x] ShuffleNetV2
|
||||
- [x] MobileNetV2
|
||||
- [x] MobileNetV3
|
||||
|
||||
## 安装
|
||||
|
||||
请参考 [安装指南](docs_zh-CN/install.md) 进行安装
|
||||
|
||||
## 基础教程
|
||||
|
||||
请参考 [基础教程](docs_zh-CN/getting_started.md) 来了解 MMClassification 的基本使用。其中还包含了 [如何微调模型](docs_zh-CN/tutorials/finetune.md), [如何增加新数据集](docs_zh-CN/tutorials/new_dataset.md), [如何设计数据处理流程](docs_zh-CN/tutorials/data_pipeline.md), 以及 [如何增加新模块](docs_zh-CN/tutorials/new_modules.md) 等指南。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
我们非常欢迎任何有助于提升 MMClassification 的贡献,请参考 [贡献指南](.github/CONTRIBUTING.md) 来了解如何参与贡献。
|
||||
|
||||
## 致谢
|
||||
|
||||
MMClassification 是一款由不同学校和公司共同贡献的开源项目。我们感谢所有为项目提供算法复现和新功能支持的贡献者,以及提供宝贵反馈的用户。
|
||||
|
||||
我们希望该工具箱和基准测试可以为社区提供灵活的代码工具,供用户复现现有算法并开发自己的新模型,从而不断为开源社区提供贡献。
|
||||
|
||||
## OpenMMLab 的其他项目
|
||||
|
||||
- [MMCV](https://github.com/open-mmlab/mmcv): OpenMMLab 计算机视觉基础库
|
||||
- [MMDetection](https://github.com/open-mmlab/mmdetection): OpenMMLab 检测工具箱与测试基准
|
||||
- [MMDetection3D](https://github.com/open-mmlab/mmdetection3d): OpenMMLab 新一代通用3D目标检测平台
|
||||
- [MMSegmentation](https://github.com/open-mmlab/mmsegmentation): OpenMMLab 语义分割工具箱与测试基准
|
||||
- [MMAction2](https://github.com/open-mmlab/mmaction2): OpenMMLab 新一代视频理解工具箱与测试基准
|
||||
- [MMTracking](https://github.com/open-mmlab/mmtracking): OpenMMLab 一体化视频目标感知平台
|
||||
- [MMPose](https://github.com/open-mmlab/mmpose): OpenMMLab 姿态估计工具箱与测试基准
|
||||
- [MMEditing](https://github.com/open-mmlab/mmediting): OpenMMLab 图像视频编辑工具箱
|
||||
- [MMOCR](https://github.com/open-mmlab/mmocr): OpenMMLab 全流程文字检测识别理解工具包
|
||||
- [MMGeneration](https://github.com/open-mmlab/mmgeneration): OpenMMLab 生成模型工具箱
|
||||
|
||||
## 欢迎加入 OpenMMLab 社区
|
||||
|
||||
扫描下方的二维码可关注 OpenMMLab 团队的 [知乎官方账号](https://www.zhihu.com/people/openmmlab),加入 OpenMMLab 团队的 [官方交流 QQ 群](https://jq.qq.com/?_wv=1027&k=aCvMxdr3)
|
||||
|
||||
<div align="center">
|
||||
<img src="/docs/imgs/zhihu_qrcode.jpg" height="400" /> <img src="/docs/imgs/qq_group_qrcode.jpg" height="400" />
|
||||
</div>
|
||||
|
||||
我们会在 OpenMMLab 社区为大家
|
||||
|
||||
- 📢 分享 AI 框架的前沿核心技术
|
||||
- 💻 解读 PyTorch 常用模块源码
|
||||
- 📰 发布 OpenMMLab 的相关新闻
|
||||
- 🚀 介绍 OpenMMLab 开发的前沿算法
|
||||
- 🏃 获取更高效的问题答疑和意见反馈
|
||||
- 🔥 提供与各行各业开发者充分交流的平台
|
||||
|
||||
干货满满 📘,等你来撩 💗,OpenMMLab 社区期待您的加入 👬
|
@ -51,7 +51,7 @@ We provide scripts to inference a single image, inference a dataset and test a d
|
||||
python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE}
|
||||
```
|
||||
|
||||
### Inference a dataset
|
||||
### Inference and test a dataset
|
||||
|
||||
- single GPU
|
||||
- single node multiple GPU
|
||||
@ -60,16 +60,20 @@ python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE}
|
||||
You can use the following commands to infer a dataset.
|
||||
|
||||
```shell
|
||||
# single-gpu inference
|
||||
python tools/inference.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--out ${RESULT_FILE}]
|
||||
# single-gpu
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--metrics ${METRICS}] [--out ${RESULT_FILE}]
|
||||
|
||||
# multi-gpu inference
|
||||
./tools/dist_inference.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}]
|
||||
# multi-gpu
|
||||
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--metrics ${METRICS}] [--out ${RESULT_FILE}]
|
||||
|
||||
# multi-node in slurm environment
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--metrics ${METRICS}] [--out ${RESULT_FILE}] --launcher slurm
|
||||
```
|
||||
|
||||
Optional arguments:
|
||||
|
||||
- `RESULT_FILE`: Filename of the output results in pickle format. If not specified, the results will not be saved to a file.
|
||||
- `RESULT_FILE`: Filename of the output results. If not specified, the results will not be saved to a file. Support formats include json, yaml and pickle.
|
||||
- `METRICS`:Items to be evaluated on the results, like accuracy, precision, recall, etc.
|
||||
|
||||
Examples:
|
||||
|
||||
@ -77,38 +81,7 @@ Assume that you have already downloaded the checkpoints to the directory `checkp
|
||||
Infer ResNet-50 on ImageNet validation set to get predicted labels and their corresponding predicted scores.
|
||||
|
||||
```shell
|
||||
python tools/inference.py configs/imagenet/resnet50_batch256.py \
|
||||
checkpoints/xxx.pth
|
||||
```
|
||||
|
||||
### Test a dataset
|
||||
|
||||
- single GPU
|
||||
- single node multiple GPU
|
||||
- multiple node
|
||||
|
||||
You can use the following commands to test a dataset.
|
||||
|
||||
```shell
|
||||
# single-gpu testing
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--out ${RESULT_FILE}]
|
||||
|
||||
# multi-gpu testing
|
||||
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}]
|
||||
```
|
||||
|
||||
Optional arguments:
|
||||
|
||||
- `RESULT_FILE`: Filename of the output results in pickle format. If not specified, the results will not be saved to a file.
|
||||
|
||||
Examples:
|
||||
|
||||
Assume that you have already downloaded the checkpoints to the directory `checkpoints/`.
|
||||
Test ResNet-50 on ImageNet validation and evaluate the top-1 and top-5.
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/imagenet/resnet50_b32x8.py \
|
||||
checkpoints/xxx.pth
|
||||
python tools/test.py configs/imagenet/resnet50_batch256.py checkpoints/xxx.pth --out result.pkl
|
||||
```
|
||||
|
||||
## Train a model
|
||||
@ -226,7 +199,8 @@ Params: 25.56 M
|
||||
### Publish a model
|
||||
|
||||
Before you upload a model to AWS, you may want to
|
||||
(1) convert model weights to CPU tensors, (2) delete the optimizer states and
|
||||
(1) convert model weights to CPU tensors
|
||||
(2) delete the optimizer states
|
||||
(3) compute the hash of the checkpoint file and append the hash id to the filename.
|
||||
|
||||
```shell
|
||||
@ -243,4 +217,9 @@ The final output filename will be `imagenet_resnet50_20200708-{hash id}.pth`.
|
||||
|
||||
## Tutorials
|
||||
|
||||
Currently, we provide five tutorials for users to [finetune models](tutorials/finetune.md), [add new dataset](tutorials/new_dataset.md), [design data pipeline](tutorials/data_pipeline.md) and [add new modules](tutorials/new_modules.md).
|
||||
Currently, we provide five tutorials for users.
|
||||
|
||||
- [finetune models](tutorials/finetune.md)
|
||||
- [add new dataset](tutorials/new_dataset.md)
|
||||
- [design data pipeline](tutorials/data_pipeline.md)
|
||||
- [add new modules](tutorials/new_modules.md).
|
||||
|
BIN
docs/imgs/qq_group_qrcode.jpg
Normal file
BIN
docs/imgs/qq_group_qrcode.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 200 KiB |
BIN
docs/imgs/zhihu_qrcode.jpg
Normal file
BIN
docs/imgs/zhihu_qrcode.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 388 KiB |
@ -38,14 +38,14 @@ You can check the supported CUDA version for precompiled packages on the [PyTorc
|
||||
`E.g.1` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install
|
||||
PyTorch 1.5, you need to install the prebuilt PyTorch with CUDA 10.1.
|
||||
|
||||
```python
|
||||
```shell
|
||||
conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
|
||||
```
|
||||
|
||||
`E.g.2` If you have CUDA 9.2 installed under `/usr/local/cuda` and would like to install
|
||||
PyTorch 1.3.1., you need to install the prebuilt PyTorch with CUDA 9.2.
|
||||
|
||||
```python
|
||||
```shell
|
||||
conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
|
||||
```
|
||||
|
||||
|
222
docs_zh-CN/getting_started.md
Normal file
222
docs_zh-CN/getting_started.md
Normal file
@ -0,0 +1,222 @@
|
||||
# 基础教程
|
||||
|
||||
本文档提供 MMClassification 相关用法的基本教程。
|
||||
|
||||
## 准备数据集
|
||||
|
||||
MMClassification 建议用户将数据集根目录链接到 `$MMCLASSIFICATION/data` 下。
|
||||
如果用户的文件夹结构与默认结构不同,则需要在配置文件中进行对应路径的修改。
|
||||
|
||||
```
|
||||
mmclassification
|
||||
├── mmcls
|
||||
├── tools
|
||||
├── configs
|
||||
├── docs
|
||||
├── data
|
||||
│ ├── imagenet
|
||||
│ │ ├── meta
|
||||
│ │ ├── train
|
||||
│ │ ├── val
|
||||
│ ├── cifar
|
||||
│ │ ├── cifar-10-batches-py
|
||||
│ ├── mnist
|
||||
│ │ ├── train-images-idx3-ubyte
|
||||
│ │ ├── train-labels-idx1-ubyte
|
||||
│ │ ├── t10k-images-idx3-ubyte
|
||||
│ │ ├── t10k-labels-idx1-ubyte
|
||||
|
||||
```
|
||||
|
||||
对于 ImageNet,其存在多个版本,但最为常用的一个是 [ILSVRC 2012](http://www.image-net.org/challenges/LSVRC/2012/),可以通过以下步骤获取该数据集。
|
||||
|
||||
1. 注册账号并登录 [下载页面](http://www.image-net.org/download-images)
|
||||
2. 获取 ILSVRC2012 下载链接并下载以下文件
|
||||
- ILSVRC2012_img_train.tar (~138GB)
|
||||
- ILSVRC2012_img_val.tar (~6.3GB)
|
||||
3. 解压下载的文件
|
||||
4. 使用 [该脚本](https://github.com/BVLC/caffe/blob/master/data/ilsvrc12/get_ilsvrc_aux.sh) 获取元数据
|
||||
|
||||
对于 MNIST,CIFAR10 和 CIFAR100,程序将会在需要的时候自动下载数据集。
|
||||
|
||||
对于用户自定义数据集的准备,请参阅 [教程 2:如何增加新数据集](tutorials/new_dataset.md)
|
||||
|
||||
## 使用预训练模型进行推理
|
||||
|
||||
MMClassification 提供了一些脚本用于进行单张图像的推理、数据集的推理和数据集的测试(如 ImageNet 等)
|
||||
|
||||
### 单张图像的推理
|
||||
|
||||
```shell
|
||||
python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE}
|
||||
```
|
||||
|
||||
### 数据集的推理与测试
|
||||
|
||||
- 支持单 GPU
|
||||
- 支持单节点多 GPU
|
||||
- 支持多节点
|
||||
|
||||
用户可使用以下命令进行数据集的推理:
|
||||
|
||||
```shell
|
||||
# 单 GPU
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--metrics ${METRICS}] [--out ${RESULT_FILE}]
|
||||
|
||||
# 多 GPU
|
||||
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--metrics ${METRICS}] [--out ${RESULT_FILE}]
|
||||
|
||||
# 基于 slurm 分布式环境的多节点
|
||||
python tools/test.py ${CONFIG_FILE} ${CHECKPOINT_FILE} [--metrics ${METRICS}] [--out ${RESULT_FILE}] --launcher slurm
|
||||
```
|
||||
|
||||
可选参数:
|
||||
|
||||
- `RESULT_FILE`:输出结果的文件名。如果未指定,结果将不会保存到文件中。支持json, yaml, pickle格式。
|
||||
- `METRICS`:数据集测试指标,如准确率(accuracy), 精确率(precision), 召回率(recall)等
|
||||
|
||||
例子:
|
||||
|
||||
假定用户将下载的模型权重文件放置在 `checkpoints/` 目录下。
|
||||
|
||||
在 ImageNet 验证集上,使用 ResNet-50 进行推理并获得预测标签及其对应的预测得分。
|
||||
|
||||
```shell
|
||||
python tools/test.py configs/imagenet/resnet50_batch256.py checkpoints/xxx.pth --out result.pkl
|
||||
```
|
||||
|
||||
## 模型训练
|
||||
|
||||
MMClassification 使用 `MMDistributedDataParallel` 进行分布式训练,使用 `MMDataParallel` 进行非分布式训练。
|
||||
|
||||
所有的输出(日志文件和模型权重文件)会被将保存到工作目录下。工作目录通过配置文件中的参数 `work_dir` 指定。
|
||||
|
||||
默认情况下,MMClassification 在每个周期后会在验证集上评估模型,可以通过在训练配置中修改 `interval` 参数来更改评估间隔
|
||||
|
||||
```python
|
||||
evaluation = dict(interval=12) # 每进行12轮训练后评估一次模型
|
||||
```
|
||||
|
||||
### 使用单个 GPU 进行训练
|
||||
|
||||
```shell
|
||||
python tools/train.py ${CONFIG_FILE} [optional arguments]
|
||||
```
|
||||
|
||||
如果用户想在命令中指定工作目录,则需要增加参数 `--work-dir ${YOUR_WORK_DIR}`
|
||||
|
||||
### 使用多个 GPU 进行训练
|
||||
|
||||
```shell
|
||||
./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [optional arguments]
|
||||
```
|
||||
|
||||
可选参数为:
|
||||
|
||||
- `--no-validate` (**不建议**): 默认情况下,程序将会在训练期间的每 k (默认为 1) 个周期进行一次验证。要禁用这一功能,使用 `--no-validate`
|
||||
- `--work-dir ${WORK_DIR}`:覆盖配置文件中指定的工作目录。
|
||||
- `--resume-from ${CHECKPOINT_FILE}`:从以前的模型权重文件恢复训练。
|
||||
|
||||
`resume-from` 和 `load-from` 的不同点:
|
||||
`resume-from` 加载模型参数和优化器状态,并且保留检查点所在的周期数,常被用于恢复意外被中断的训练。
|
||||
`load-from` 只加载模型参数,但周期数从 0 开始计数,常被用于微调模型。
|
||||
|
||||
### 使用多台机器进行训练
|
||||
|
||||
如果用户在 [slurm](https://slurm.schedmd.com/) 集群上运行 MMClassification,可使用 `slurm_train.sh` 脚本。(该脚本也支持单台机器上进行训练)
|
||||
|
||||
```shell
|
||||
[GPUS=${GPUS}] ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} ${WORK_DIR}
|
||||
```
|
||||
|
||||
用户可以在 [slurm_train.sh](https://github.com/open-mmlab/mmclassification/blob/master/tools/slurm_train.sh) 中检查所有的参数和环境变量
|
||||
|
||||
如果用户的多台机器通过 Ethernet 连接,则可以参考 pytorch [launch utility](https://pytorch.org/docs/stable/distributed.html#launch-utility)。如果用户没有高速网络,如 InfiniBand,速度将会非常慢。
|
||||
|
||||
### 使用单台机器启动多个任务
|
||||
|
||||
如果用使用单台机器启动多个任务,如在有 8 块 GPU 的单台机器上启动 2 个需要 4 块 GPU 的训练任务,则需要为每个任务指定不同端口,以避免通信冲突。
|
||||
|
||||
如果用户使用 `dist_train.sh` 脚本启动训练任务,则可以通过以下命令指定端口
|
||||
|
||||
```shell
|
||||
CUDA_VISIBLE_DEVICES=0,1,2,3 PORT=29500 ./tools/dist_train.sh ${CONFIG_FILE} 4
|
||||
CUDA_VISIBLE_DEVICES=4,5,6,7 PORT=29501 ./tools/dist_train.sh ${CONFIG_FILE} 4
|
||||
```
|
||||
|
||||
如果用户在 slurm 集群下启动多个训练任务,则需要修改配置文件(通常是配置文件的倒数第 6 行)中的 `dist_params` 变量,以设置不同的通信端口。
|
||||
|
||||
在 `config1.py` 中,
|
||||
|
||||
```python
|
||||
dist_params = dict(backend='nccl', port=29500)
|
||||
```
|
||||
|
||||
在 `config2.py` 中,
|
||||
|
||||
```python
|
||||
dist_params = dict(backend='nccl', port=29501)
|
||||
```
|
||||
|
||||
之后便可启动两个任务,分别对应 `config1.py` 和 `config2.py`。
|
||||
|
||||
```shell
|
||||
CUDA_VISIBLE_DEVICES=0,1,2,3 GPUS=4 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR}
|
||||
CUDA_VISIBLE_DEVICES=4,5,6,7 GPUS=4 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR}
|
||||
```
|
||||
|
||||
## 实用工具
|
||||
|
||||
我们在 `tools/` 目录下提供的一些对训练和测试十分有用的工具
|
||||
|
||||
### 计算 FLOPs 和参数量(试验性的)
|
||||
|
||||
我们根据 [flops-counter.pytorch](https://github.com/sovrasov/flops-counter.pytorch) 提供了一个脚本用于计算给定模型的 FLOPs 和参数量
|
||||
|
||||
```shell
|
||||
python tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]
|
||||
```
|
||||
|
||||
用户将获得如下结果:
|
||||
|
||||
```
|
||||
==============================
|
||||
Input shape: (3, 224, 224)
|
||||
Flops: 4.12 GFLOPs
|
||||
Params: 25.56 M
|
||||
==============================
|
||||
```
|
||||
|
||||
|
||||
**注意**:此工具仍处于试验阶段,我们不保证该数字正确无误。您最好将结果用于简单比较,但在技术报告或论文中采用该结果之前,请仔细检查。
|
||||
|
||||
- FLOPs 与输入的尺寸有关,而参数量与输入尺寸无关。默认输入尺寸为 (1, 3, 224, 224)
|
||||
- 一些运算不会被计入 FLOPs 的统计中,例如 GN 和自定义运算。详细信息请参考 [`mmcv.cnn.get_model_complexity_info()`](https://github.com/open-mmlab/mmcv/blob/master/mmcv/cnn/utils/flops_counter.py)
|
||||
|
||||
### 模型发布
|
||||
|
||||
在上传模型至 AWS 之前,也许会需要
|
||||
- 转换模型权重至 CPU 张量
|
||||
- 删除优化器状态
|
||||
- 计算模型权重文件的哈希值,并添加至文件名之后
|
||||
|
||||
```shell
|
||||
python tools/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}
|
||||
```
|
||||
|
||||
例如:
|
||||
|
||||
```shell
|
||||
python tools/publish_model.py work_dirs/resnet50/latest.pth imagenet_resnet50_20200708.pth
|
||||
```
|
||||
|
||||
最终输出的文件名将会是 `imagenet_resnet50_20200708-{hash id}.pth`
|
||||
|
||||
## 详细教程
|
||||
|
||||
目前, MMClassification 提供以下几种更详细的教程:
|
||||
|
||||
- [如何微调模型](tutorials/finetune.md)
|
||||
- [如何增加新数据集](tutorials/new_dataset.md)
|
||||
- [如何设计数据处理流程](tutorials/data_pipeline.md)
|
||||
- [如何增加新模块](tutorials/new_modules.md)
|
81
docs_zh-CN/install.md
Normal file
81
docs_zh-CN/install.md
Normal file
@ -0,0 +1,81 @@
|
||||
## 安装
|
||||
|
||||
### 安装依赖包
|
||||
|
||||
- Python 3.6+
|
||||
- PyTorch 1.3+
|
||||
- [MMCV](https://github.com/open-mmlab/mmcv)
|
||||
|
||||
MMClassification 和 MMCV 的适配关系如下,请安装正确版本的 MMCV 以避免安装问题
|
||||
|
||||
| MMClassification 版本 | MMCV 版本 |
|
||||
|:---------------------:|:-----------:|
|
||||
| master | mmcv>=1.3.0 |
|
||||
| 0.10.0 | mmcv>=1.3.0 |
|
||||
| 0.9.0 | mmcv>=1.1.4 |
|
||||
| 0.8.0 | mmcv>=1.1.4 |
|
||||
| 0.7.0 | mmcv>=1.1.4 |
|
||||
| 0.6.0 | mmcv>=1.1.4 |
|
||||
|
||||
### 安装 MMClassification 步骤
|
||||
|
||||
a. 创建conda虚拟环境,并激活
|
||||
|
||||
```shell
|
||||
conda create -n open-mmlab python=3.7 -y
|
||||
conda activate open-mmlab
|
||||
```
|
||||
|
||||
b. 按照 [官方指南](https://pytorch.org/) 安装PyTorch和TorchVision,如:
|
||||
|
||||
```shell
|
||||
conda install pytorch torchvision -c pytorch
|
||||
```
|
||||
|
||||
**注**:请确保 CUDA 编译版本和运行版本相匹配
|
||||
用户可以参照 [PyTorch 官网](https://pytorch.org/) 对预编译包所支持的 CUDA 版本进行核对。
|
||||
|
||||
`例 1`:如果用户的 `/usr/local/cuda` 文件夹下已安装 CUDA 10.1 版本,并且想要安装 PyTorch 1.5 版本,
|
||||
则需要安装 CUDA 10.1 下预编译的 PyTorch。
|
||||
|
||||
```shell
|
||||
conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
|
||||
```
|
||||
|
||||
`例 2`:如果用户的 `/usr/local/cuda` 文件夹下已安装 CUDA 9.2 版本,并且想要安装 PyTorch 1.3.1 版本,
|
||||
则需要安装 CUDA 9.2 下预编译的 PyTorch。
|
||||
|
||||
```shell
|
||||
conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
|
||||
```
|
||||
|
||||
如果 PyTorch 是由源码进行编译安装(而非直接下载预编译好的安装包),则可以使用更多的 CUDA 版本(如 9.0 版本)。
|
||||
|
||||
c. 克隆 mmclassification 库
|
||||
|
||||
```shell
|
||||
git clone https://github.com/open-mmlab/mmclassification.git
|
||||
cd mmclassification
|
||||
```
|
||||
|
||||
d. 安装依赖包和 MMClassification
|
||||
|
||||
```shell
|
||||
pip install -e . # or "python setup.py develop"
|
||||
```
|
||||
|
||||
提示:
|
||||
|
||||
1. 按照以上步骤,MMClassification 是以 `dev` 模式安装的,任何本地的代码修改都可以直接生效,无需重新安装(除非提交了一些commit,并且希望提升版本号)
|
||||
|
||||
2. 如果希望使用 `opencv-python-headless` 而不是 `opencv-python`,可以在安装 [mmcv](https://github.com/open-mmlab/mmcv) 之前提前安装。
|
||||
|
||||
### 在多个 MMClassification 版本下进行开发
|
||||
|
||||
MMClassification 的训练和测试脚本已经修改了 `PYTHONPATH` 变量,以确保其能够运行当前目录下的 MMClassification。
|
||||
|
||||
如果想要运行环境下默认的 MMClassification,用户需要在训练和测试脚本中去除这一行:
|
||||
|
||||
```shell
|
||||
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
|
||||
```
|
50
docs_zh-CN/model_zoo.md
Normal file
50
docs_zh-CN/model_zoo.md
Normal file
@ -0,0 +1,50 @@
|
||||
# Model Zoo
|
||||
|
||||
## ImageNet
|
||||
|
||||
ImageNet has multiple versions, but the most commonly used one is [ILSVRC 2012](http://www.image-net.org/challenges/LSVRC/2012/).
|
||||
The ResNet family models below are trained by standard data augmentations, i.e., RandomResizedCrop, RandomHorizontalFlip and Normalize.
|
||||
|
||||
| Model | Params(M) | Flops(G) | Top-1 (%) | Top-5 (%) | Config | Download |
|
||||
|:---------------------:|:---------:|:--------:|:---------:|:---------:|:---------:|:--------:|
|
||||
| VGG-11 | 132.86 | 7.63 | 68.75 | 88.87 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg11_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg11_batch256_imagenet_20210208-4271cd6c.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg11_batch256_imagenet_20210208-4271cd6c.log.json) |
|
||||
| VGG-13 | 133.05 | 11.34 | 70.02 | 89.46 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg13_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg13_batch256_imagenet_20210208-4d1d6080.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg13_batch256_imagenet_20210208-4d1d6080.log.json) |
|
||||
| VGG-16 | 138.36 | 15.5 | 71.62 | 90.49 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg16_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg16_batch256_imagenet_20210208-db26f1a5.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg16_batch256_imagenet_20210208-db26f1a5.log.json) |
|
||||
| VGG-19 | 143.67 | 19.67 | 72.41 | 90.80 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg19_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg19_bn_batch256_imagenet_20210208-da620c4f.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg19_bn_batch256_imagenet_20210208-da620c4f.log.json)|
|
||||
| VGG-11-BN | 132.87 | 7.64 | 70.75 | 90.12 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg11bn_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg11_bn_batch256_imagenet_20210207-f244902c.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg11_bn_batch256_imagenet_20210207-f244902c.log.json) |
|
||||
| VGG-13-BN | 133.05 | 11.36 | 72.15 | 90.71 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg13bn_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg13_bn_batch256_imagenet_20210207-1a8b7864.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg13_bn_batch256_imagenet_20210207-1a8b7864.log.json) |
|
||||
| VGG-16-BN | 138.37 | 15.53 | 73.72 | 91.68 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg16_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg16_bn_batch256_imagenet_20210208-7e55cd29.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg16_bn_batch256_imagenet_20210208-7e55cd29.log.json) |
|
||||
| VGG-19-BN | 143.68 | 19.7 | 74.70 | 92.24 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/vgg/vgg19bn_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/vgg/vgg19_bn_batch256_imagenet_20210208-da620c4f.pth) | [log](https://download.openmmlab.com/mmclassification/v0/vgg/vgg19_bn_batch256_imagenet_20210208-da620c4f.log.json)|
|
||||
| ResNet-18 | 11.69 | 1.82 | 70.07 | 89.44 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet18_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_batch256_imagenet_20200708-34ab8f90.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_batch256_imagenet_20200708-34ab8f90.log.json) |
|
||||
| ResNet-34 | 21.8 | 3.68 | 73.85 | 91.53 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet34_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_batch256_imagenet_20200708-32ffb4f7.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_batch256_imagenet_20200708-32ffb4f7.log.json) |
|
||||
| ResNet-50 | 25.56 | 4.12 | 76.55 | 93.15 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet50_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_batch256_imagenet_20200708-cfb998bf.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_batch256_imagenet_20200708-cfb998bf.log.json) |
|
||||
| ResNet-101 | 44.55 | 7.85 | 78.18 | 94.03 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet101_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet101_batch256_imagenet_20200708-753f3608.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet101_batch256_imagenet_20200708-753f3608.log.json) |
|
||||
| ResNeSt-50 | 27.48 | 5.41 | 81.13 | 95.59 | | [model](https://download.openmmlab.com/mmclassification/v0/resnest/resnest50_imagenet_converted-1ebf0afe.pth) | [log]() |
|
||||
| ResNeSt-101 | 48.28 | 10.27 | 82.32 | 96.24 | | [model](https://download.openmmlab.com/mmclassification/v0/resnest/resnest101_imagenet_converted-032caa52.pth) | [log]() |
|
||||
| ResNeSt-200 | 70.2 | 17.53 | 82.41 | 96.22 | | [model](https://download.openmmlab.com/mmclassification/v0/resnest/resnest200_imagenet_converted-581a60f2.pth) | [log]() |
|
||||
| ResNeSt-269 | 110.93 | 22.58 | 82.70 | 96.28 | | [model](https://download.openmmlab.com/mmclassification/v0/resnest/resnest269_imagenet_converted-59930960.pth) | [log]() |
|
||||
| ResNet-152 | 60.19 | 11.58 | 78.63 | 94.16 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet152_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet152_batch256_imagenet_20200708-ec25b1f9.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet152_batch256_imagenet_20200708-ec25b1f9.log.json) |
|
||||
| ResNetV1D-50 | 25.58 | 4.36 | 77.4 | 93.66 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnetv1d50_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d50_batch256_imagenet_20200708-1ad0ce94.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d50_batch256_imagenet_20200708-1ad0ce94.log.json) |
|
||||
| ResNetV1D-101 | 44.57 | 8.09 | 78.85 | 94.38 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnetv1d101_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d101_batch256_imagenet_20200708-9cb302ef.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d101_batch256_imagenet_20200708-9cb302ef.log.json) |
|
||||
| ResNetV1D-152 | 60.21 | 11.82 | 79.35 | 94.61 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnetv1d152_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d152_batch256_imagenet_20200708-e79cb6a2.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnetv1d152_batch256_imagenet_20200708-e79cb6a2.log.json) |
|
||||
| ResNeXt-32x4d-50 | 25.03 | 4.27 | 77.92 | 93.74 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnext/resnext50_32x4d_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_batch256_imagenet_20200708-c07adbb7.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext50_32x4d_batch256_imagenet_20200708-c07adbb7.log.json) |
|
||||
| ResNeXt-32x4d-101 | 44.18 | 8.03 | 78.7 | 94.34 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnext/resnext101_32x4d_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x4d_batch256_imagenet_20200708-87f2d1c9.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x4d_batch256_imagenet_20200708-87f2d1c9.log.json) |
|
||||
| ResNeXt-32x8d-101 | 88.79 | 16.5 | 79.22 | 94.52 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnext/resnext101_32x8d_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x8d_batch256_imagenet_20200708-1ec34aa7.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext101_32x8d_batch256_imagenet_20200708-1ec34aa7.log.json) |
|
||||
| ResNeXt-32x4d-152 | 59.95 | 11.8 | 79.06 | 94.47 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnext/resnext152_32x4d_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnext/resnext152_32x4d_batch256_imagenet_20200708-aab5034c.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnext/resnext152_32x4d_batch256_imagenet_20200708-aab5034c.log.json) |
|
||||
| SE-ResNet-50 | 28.09 | 4.13 | 77.74 | 93.84 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/seresnet/seresnet50_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/se-resnet/se-resnet50_batch256_imagenet_20200804-ae206104.pth) | [log](https://download.openmmlab.com/mmclassification/v0/se-resnet/se-resnet50_batch256_imagenet_20200708-657b3c36.log.json) |
|
||||
| SE-ResNet-101 | 49.33 | 7.86 | 78.26 | 94.07 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/seresnet/seresnet101_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/se-resnet/se-resnet101_batch256_imagenet_20200804-ba5b51d4.pth) | [log](https://download.openmmlab.com/mmclassification/v0/se-resnet/se-resnet101_batch256_imagenet_20200708-038a4d04.log.json) |
|
||||
| ShuffleNetV1 1.0x (group=3) | 1.87 | 0.146 | 68.13 | 87.81 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/shufflenet_v1/shufflenet_v1_1x_b64x16_linearlr_bn_nowd_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/shufflenet_v1/shufflenet_v1_batch1024_imagenet_20200804-5d6cec73.pth) | [log](https://download.openmmlab.com/mmclassification/v0/shufflenet_v1/shufflenet_v1_batch1024_imagenet_20200804-5d6cec73.log.json) |
|
||||
| ShuffleNetV2 1.0x | 2.28 | 0.149 | 69.55 | 88.92 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/shufflenet_v2/shufflenet_v2_1x_b64x16_linearlr_bn_nowd_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/shufflenet_v2/shufflenet_v2_batch1024_imagenet_20200812-5bf4721e.pth) | [log](https://download.openmmlab.com/mmclassification/v0/shufflenet_v2/shufflenet_v2_batch1024_imagenet_20200804-8860eec9.log.json) |
|
||||
| MobileNet V2 | 3.5 | 0.319 | 71.86 | 90.42 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/mobilenet_v2/mobilenet_v2_b32x8_imagenet.py) | [model](https://download.openmmlab.com/mmclassification/v0/mobilenet_v2/mobilenet_v2_batch256_imagenet_20200708-3b2dc3af.pth) | [log](https://download.openmmlab.com/mmclassification/v0/mobilenet_v2/mobilenet_v2_batch256_imagenet_20200708-3b2dc3af.log.json) |
|
||||
|
||||
Models with * are converted from other repos, others are trained by ourselves.
|
||||
|
||||
## CIFAR10
|
||||
|
||||
| Model | Params(M) | Flops(G) | Top-1 (%) | Config | Download |
|
||||
|:---------------------:|:---------:|:--------:|:---------:|:--------:|:--------:|
|
||||
| ResNet-18-b16x8 | 11.17 | 0.56 | 94.72 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet18_b16x8_cifar10.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20200823-f906fa4e.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20200823-f906fa4e.log.json) |
|
||||
| ResNet-34-b16x8 | 21.28 | 1.16 | 95.34 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet34_b16x8_cifar10.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_b16x8_cifar10_20200823-52d5d832.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet34_b16x8_cifar10_20200823-52d5d832.log.json) |
|
||||
| ResNet-50-b16x8 | 23.52 | 1.31 | 95.36 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet50_b16x8_cifar10.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_b16x8_cifar10_20200823-882aa7b1.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_b16x8_cifar10_20200823-882aa7b1.log.json) |
|
||||
| ResNet-101-b16x8 | 42.51 | 2.52 | 95.66 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet101_b16x8_cifar10.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet101_b16x8_cifar10_20200823-d9501bbc.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet101_b16x8_cifar10_20200823-d9501bbc.log.json) |
|
||||
| ResNet-152-b16x8 | 58.16 | 3.74 | 95.96 | [config](https://github.com/open-mmlab/mmclassification/blob/master/configs/resnet/resnet152_b16x8_cifar10.py) | [model](https://download.openmmlab.com/mmclassification/v0/resnet/resnet152_b16x8_cifar10_20200823-ad4d5d0c.pth) | [log](https://download.openmmlab.com/mmclassification/v0/resnet/resnet152_b16x8_cifar10_20200823-ad4d5d0c.log.json) |
|
2353
docs_zh-CN/tutorials/MMClassification_Tutorial.ipynb
Normal file
2353
docs_zh-CN/tutorials/MMClassification_Tutorial.ipynb
Normal file
File diff suppressed because one or more lines are too long
142
docs_zh-CN/tutorials/data_pipeline.md
Normal file
142
docs_zh-CN/tutorials/data_pipeline.md
Normal file
@ -0,0 +1,142 @@
|
||||
# Tutorial 3: Custom Data Pipelines
|
||||
|
||||
## Design of Data pipelines
|
||||
|
||||
Following typical conventions, we use `Dataset` and `DataLoader` for data loading
|
||||
with multiple workers. `Dataset` returns a dict of data items corresponding to
|
||||
the arguments of models forward method.
|
||||
|
||||
The data preparation pipeline and the dataset is decomposed. Usually a dataset
|
||||
defines how to process the annotations and a data pipeline defines all the steps to prepare a data dict.
|
||||
A pipeline consists of a sequence of operations. Each operation takes a dict as input and also output a dict for the next transform.
|
||||
|
||||
The operations are categorized into data loading, pre-processing and formatting.
|
||||
|
||||
Here is an pipeline example for ResNet-50 training on ImageNet.
|
||||
|
||||
```python
|
||||
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='RandomResizedCrop', size=224),
|
||||
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
|
||||
dict(type='Normalize', **img_norm_cfg),
|
||||
dict(type='ImageToTensor', keys=['img']),
|
||||
dict(type='ToTensor', keys=['gt_label']),
|
||||
dict(type='Collect', keys=['img', 'gt_label'])
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='LoadImageFromFile'),
|
||||
dict(type='Resize', size=256),
|
||||
dict(type='CenterCrop', crop_size=224),
|
||||
dict(type='Normalize', **img_norm_cfg),
|
||||
dict(type='ImageToTensor', keys=['img']),
|
||||
dict(type='Collect', keys=['img'])
|
||||
]
|
||||
```
|
||||
|
||||
By fault, `LoadImageFromFile` loads images from disk but it may lead to IO bottleneck for efficient small models.
|
||||
Various backends are supported by mmcv to accelerate this process. For example, if the training machines have setup
|
||||
[memcached](https://memcached.org/), we can revise the config as follows.
|
||||
|
||||
```
|
||||
memcached_root = '/mnt/xxx/memcached_client/'
|
||||
train_pipeline = [
|
||||
dict(
|
||||
type='LoadImageFromFile',
|
||||
file_client_args=dict(
|
||||
backend='memcached',
|
||||
server_list_cfg=osp.join(memcached_root, 'server_list.conf'),
|
||||
client_cfg=osp.join(memcached_root, 'client.conf'))),
|
||||
]
|
||||
```
|
||||
|
||||
More supported backends can be found in [mmcv.fileio.FileClient](https://github.com/open-mmlab/mmcv/blob/master/mmcv/fileio/file_client.py).
|
||||
|
||||
For each operation, we list the related dict fields that are added/updated/removed.
|
||||
At the end of the pipeline, we use `Collect` to only retain the necessary items for forward computation.
|
||||
|
||||
### Data loading
|
||||
|
||||
`LoadImageFromFile`
|
||||
|
||||
- add: img, img_shape, ori_shape
|
||||
|
||||
### Pre-processing
|
||||
|
||||
`Resize`
|
||||
|
||||
- add: scale, scale_idx, pad_shape, scale_factor, keep_ratio
|
||||
- update: img, img_shape
|
||||
|
||||
`RandomFlip`
|
||||
|
||||
- add: flip, flip_direction
|
||||
- update: img
|
||||
|
||||
`RandomCrop`
|
||||
|
||||
- update: img, pad_shape
|
||||
|
||||
`Normalize`
|
||||
|
||||
- add: img_norm_cfg
|
||||
- update: img
|
||||
|
||||
### Formatting
|
||||
|
||||
`ToTensor`
|
||||
|
||||
- update: specified by `keys`.
|
||||
|
||||
`ImageToTensor`
|
||||
|
||||
- update: specified by `keys`.
|
||||
|
||||
`Transpose`
|
||||
|
||||
- update: specified by `keys`.
|
||||
|
||||
`Collect`
|
||||
|
||||
- remove: all other keys except for those specified by `keys`
|
||||
|
||||
## Extend and use custom pipelines
|
||||
|
||||
1. Write a new pipeline in any file, e.g., `my_pipeline.py`. It takes a dict as input and return a dict.
|
||||
|
||||
```python
|
||||
from mmcls.datasets import PIPELINES
|
||||
|
||||
@PIPELINES.register_module()
|
||||
class MyTransform(object):
|
||||
|
||||
def __call__(self, results):
|
||||
results['dummy'] = True
|
||||
# apply transforms on results['img']
|
||||
return results
|
||||
```
|
||||
|
||||
2. Import the new class.
|
||||
|
||||
```python
|
||||
from .my_pipeline import MyTransform
|
||||
```
|
||||
|
||||
3. Use it in config files.
|
||||
|
||||
```python
|
||||
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='RandomResizedCrop', size=224),
|
||||
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
|
||||
dict(type='MyTransform'),
|
||||
dict(type='Normalize', **img_norm_cfg),
|
||||
dict(type='ImageToTensor', keys=['img']),
|
||||
dict(type='ToTensor', keys=['gt_label']),
|
||||
dict(type='Collect', keys=['img', 'gt_label'])
|
||||
]
|
||||
```
|
94
docs_zh-CN/tutorials/finetune.md
Normal file
94
docs_zh-CN/tutorials/finetune.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Tutorial 1: Finetuning Models
|
||||
|
||||
Classification models pre-trained on the ImageNet dataset has been demonstrated to be effective for other datasets and other downstream tasks.
|
||||
This tutorial provides instruction for users to use the models provided in the [Model Zoo](../model_zoo.md) for other datasets to obtain better performance.
|
||||
|
||||
There are two steps to finetune a model on a new dataset.
|
||||
|
||||
- Add support for the new dataset following [Tutorial 2: Adding New Dataset](new_dataset.md).
|
||||
- Modify the configs as will be discussed in this tutorial.
|
||||
|
||||
Take the finetuning on CIFAR10 Dataset as an example, the users need to modify five parts in the config.
|
||||
|
||||
## Inherit base configs
|
||||
|
||||
To reuse the common parts among different configs, we support inheriting configs from multiple existing configs. To finetune a ResNet-50 model, the new config needs to inherit
|
||||
`_base_/models/resnet50.py` to build the basic structure of the model. To use the CIFAR10 Dataset, the new config can also simply inherit `_base_/datasets/cifar10.py`. For runtime settings such as training schedules, the new config needs to inherit `_base_/default_runtime.py`.
|
||||
|
||||
```python
|
||||
_base_ = [
|
||||
'../_base_/models/resnet50.py',
|
||||
'../_base_/datasets/cifar10.py', '../_base_/default_runtime.py'
|
||||
]
|
||||
```
|
||||
|
||||
Besides, users can also choose to write the whole contents rather than use inheritance, e.g. `configs/mnist/lenet5.py`.
|
||||
|
||||
## Modify head
|
||||
|
||||
Then the new config needs to modify the head according to the class numbers of the new datasets. By only changing `num_classes` in the head, the weights of the pre-trained models are mostly reused except the final prediction head.
|
||||
|
||||
```python
|
||||
_base_ = ['./resnet50.py']
|
||||
model = dict(
|
||||
pretrained=None,
|
||||
head=dict(
|
||||
type='LinearClsHead',
|
||||
num_classes=10,
|
||||
in_channels=2048,
|
||||
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
|
||||
))
|
||||
```
|
||||
|
||||
## Modify dataset
|
||||
|
||||
The users may also need to prepare the dataset and write the configs about dataset. We currently support MNIST, CIFAR and ImageNet Dataset.
|
||||
For fintuning on CIFAR10, its original input size is 32 and thus we should resize it to 224, to fit the input size of models pretrained on ImageNet.
|
||||
|
||||
```python
|
||||
_base_ = ['./cifar10.py']
|
||||
img_norm_cfg = dict(
|
||||
mean=[125.307, 122.961, 113.8575],
|
||||
std=[51.5865, 50.847, 51.255],
|
||||
to_rgb=True)
|
||||
train_pipeline = [
|
||||
dict(type='RandomCrop', size=32, padding=4),
|
||||
dict(type='RandomFlip', flip_prob=0.5, direction='horizontal'),
|
||||
dict(type='Resize', size=224)
|
||||
dict(type='Normalize', **img_norm_cfg),
|
||||
dict(type='ImageToTensor', keys=['img']),
|
||||
dict(type='ToTensor', keys=['gt_label']),
|
||||
dict(type='Collect', keys=['img', 'gt_label'])
|
||||
]
|
||||
test_pipeline = [
|
||||
dict(type='Resize', size=224)
|
||||
dict(type='Normalize', **img_norm_cfg),
|
||||
dict(type='ImageToTensor', keys=['img']),
|
||||
dict(type='Collect', keys=['img'])
|
||||
]
|
||||
```
|
||||
|
||||
## Modify training schedule
|
||||
|
||||
The finetuning hyperparameters vary from the default schedule. It usually requires smaller learning rate and less training epochs.
|
||||
|
||||
```python
|
||||
# optimizer
|
||||
# lr is set for a batch size of 128
|
||||
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
|
||||
optimizer_config = dict(grad_clip=None)
|
||||
# learning policy
|
||||
lr_config = dict(
|
||||
policy='step',
|
||||
step=[15])
|
||||
runner = dict(type='EpochBasedRunner', max_epochs=200)
|
||||
log_config = dict(interval=100)
|
||||
```
|
||||
|
||||
## Use pre-trained model
|
||||
|
||||
To use the pre-trained model, the new config add the link of pre-trained models in the `load_from`. The users might need to download the model weights before training to avoid the download time during training.
|
||||
|
||||
```python
|
||||
load_from = 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/mmclassification/models/tbd.pth' # noqa
|
||||
```
|
129
docs_zh-CN/tutorials/new_dataset.md
Normal file
129
docs_zh-CN/tutorials/new_dataset.md
Normal file
@ -0,0 +1,129 @@
|
||||
# Tutorial 2: Adding New Dataset
|
||||
|
||||
## Customize datasets by reorganizing data
|
||||
|
||||
### Reorganize dataset to existing format
|
||||
|
||||
The simplest way is to convert your dataset to existing dataset formats (ImageNet).
|
||||
|
||||
For training, it differentiates classes by folders. The directory of training data is as follows:
|
||||
|
||||
```
|
||||
imagenet
|
||||
├── ...
|
||||
├── train
|
||||
│ ├── n01440764
|
||||
│ │ ├── n01440764_10026.JPEG
|
||||
│ │ ├── n01440764_10027.JPEG
|
||||
│ │ ├── ...
|
||||
│ ├── ...
|
||||
│ ├── n15075141
|
||||
│ │ ├── n15075141_999.JPEG
|
||||
│ │ ├── n15075141_9993.JPEG
|
||||
│ │ ├── ...
|
||||
```
|
||||
|
||||
For validation, we provide a annotation list. Each line of the list contrains a filename and its corresponding ground-truth labels. The format is as follows:
|
||||
|
||||
```
|
||||
ILSVRC2012_val_00000001.JPEG 65
|
||||
ILSVRC2012_val_00000002.JPEG 970
|
||||
ILSVRC2012_val_00000003.JPEG 230
|
||||
ILSVRC2012_val_00000004.JPEG 809
|
||||
ILSVRC2012_val_00000005.JPEG 516
|
||||
```
|
||||
|
||||
Note: The value of ground-truth labels should fall in range `[0, num_classes - 1]`.
|
||||
|
||||
### An example of customized dataset
|
||||
|
||||
You can write a new Dataset class inherited from `BaseDataset`, and overwrite `load_annotations(self)`,
|
||||
like [CIFAR10](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/datasets/cifar.py) and [ImageNet](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/datasets/imagenet.py).
|
||||
Typically, this function returns a list, where each sample is a dict, containing necessary data informations, e.g., `img` and `gt_label`.
|
||||
|
||||
Assume we are going to implement a `Filelist` dataset, which takes filelists for both training and testing. The format of annotation list is as follows:
|
||||
|
||||
```
|
||||
000001.jpg 0
|
||||
000002.jpg 1
|
||||
```
|
||||
|
||||
We can create a new dataset in `mmcls/datasets/filelist.py` to load the data.
|
||||
|
||||
```python
|
||||
import mmcv
|
||||
import numpy as np
|
||||
|
||||
from .builder import DATASETS
|
||||
from .base_dataset import BaseDataset
|
||||
|
||||
|
||||
@DATASETS.register_module()
|
||||
class MyDataset(BaseDataset):
|
||||
|
||||
def load_annotations(self):
|
||||
assert isinstance(self.ann_file, str)
|
||||
|
||||
data_infos = []
|
||||
with open(self.ann_file) as f:
|
||||
samples = [x.strip().split(' ') for x in f.readlines()]
|
||||
for filename, gt_label in samples:
|
||||
info = {'img_prefix': self.data_prefix}
|
||||
info['img_info'] = {'filename': filename}
|
||||
info['gt_label'] = np.array(gt_label, dtype=np.int64)
|
||||
data_infos.append(info)
|
||||
return data_infos
|
||||
|
||||
```
|
||||
|
||||
Then in the config, to use `Filelist` you can modify the config as the following
|
||||
|
||||
```python
|
||||
dataset_A_train = dict(
|
||||
type='Filelist',
|
||||
ann_file = 'image_list.txt',
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
```
|
||||
|
||||
## Customize datasets by mixing dataset
|
||||
|
||||
MMClassification also supports to mix dataset for training.
|
||||
Currently it supports to concat and repeat datasets.
|
||||
|
||||
### Repeat dataset
|
||||
|
||||
We use `RepeatDataset` as wrapper to repeat the dataset. For example, suppose the original dataset is `Dataset_A`, to repeat it, the config looks like the following
|
||||
|
||||
```python
|
||||
dataset_A_train = dict(
|
||||
type='RepeatDataset',
|
||||
times=N,
|
||||
dataset=dict( # This is the original config of Dataset_A
|
||||
type='Dataset_A',
|
||||
...
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
### Class balanced dataset
|
||||
|
||||
We use `ClassBalancedDataset` as wrapper to repeat the dataset based on category
|
||||
frequency. The dataset to repeat needs to instantiate function `self.get_cat_ids(idx)`
|
||||
to support `ClassBalancedDataset`.
|
||||
For example, to repeat `Dataset_A` with `oversample_thr=1e-3`, the config looks like the following
|
||||
|
||||
```python
|
||||
dataset_A_train = dict(
|
||||
type='ClassBalancedDataset',
|
||||
oversample_thr=1e-3,
|
||||
dataset=dict( # This is the original config of Dataset_A
|
||||
type='Dataset_A',
|
||||
...
|
||||
pipeline=train_pipeline
|
||||
)
|
||||
)
|
||||
```
|
||||
|
||||
You may refer to [source code](../../mmcls/datasets/dataset_wrappers.py) for details.
|
236
docs_zh-CN/tutorials/new_modules.md
Normal file
236
docs_zh-CN/tutorials/new_modules.md
Normal file
@ -0,0 +1,236 @@
|
||||
# Tutorial 4: Adding New Modules
|
||||
|
||||
## Develop new components
|
||||
|
||||
We basically categorize model components into 3 types.
|
||||
|
||||
- backbone: usually an feature extraction network, e.g., ResNet, MobileNet.
|
||||
- neck: the component between backbones and heads, e.g., GlobalAveragePooling.
|
||||
- head: the component for specific tasks, e.g., classification or regression.
|
||||
|
||||
### Add new backbones
|
||||
|
||||
Here we show how to develop new components with an example of ResNet_CIFAR.
|
||||
As the input size of CIFAR is 32x32, this backbone replaces the `kernel_size=7, stride=2` to `kernel_size=3, stride=1` and remove the MaxPooling after stem, to avoid forwarding small feature maps to residual blocks.
|
||||
It inherits from ResNet and only modifies the stem layers.
|
||||
|
||||
1. Create a new file `mmcls/models/backbones/resnet_cifar.py`.
|
||||
|
||||
```python
|
||||
import torch.nn as nn
|
||||
|
||||
from ..builder import BACKBONES
|
||||
from .resnet import ResNet
|
||||
|
||||
|
||||
@BACKBONES.register_module()
|
||||
class ResNet_CIFAR(ResNet):
|
||||
|
||||
"""ResNet backbone for CIFAR.
|
||||
|
||||
short description of the backbone
|
||||
|
||||
Args:
|
||||
depth(int): Network depth, from {18, 34, 50, 101, 152}.
|
||||
...
|
||||
"""
|
||||
|
||||
def __init__(self, depth, **kwargs):
|
||||
super(ResNet_CIFAR, self).__init__(depth, **kwargs) # call ResNet init
|
||||
pass # other specific initialization
|
||||
|
||||
def forward(self, x): # should return a tuple
|
||||
# implementation is ignored
|
||||
pass
|
||||
|
||||
def init_weights(self, pretrained=None):
|
||||
pass # override ResNet init_weights if necessary
|
||||
|
||||
def train(self, mode=True):
|
||||
pass # override ResNet train if necessary
|
||||
```
|
||||
|
||||
2. Import the module in `mmcls/models/backbones/__init__.py`.
|
||||
|
||||
```python
|
||||
from .resnet_cifar import ResNet_CIFAR
|
||||
```
|
||||
|
||||
3. Use it in your config file.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
...
|
||||
backbone=dict(
|
||||
type='ResNet_CIFAR',
|
||||
depth=18,
|
||||
other_arg=xxx),
|
||||
...
|
||||
```
|
||||
|
||||
### Add new necks
|
||||
|
||||
Here we take `GlobalAveragePooling` as an example. It is a very simple neck without any arguments.
|
||||
To add a new neck, we mainly implement the `forward` function, which applies some operation on the output from backbone and forward the results to head.
|
||||
|
||||
1. Create a new file in `mmcls/models/necks/gap.py`.
|
||||
|
||||
```python
|
||||
import torch.nn as nn
|
||||
|
||||
from ..builder import NECKS
|
||||
|
||||
@NECKS.register_module()
|
||||
class GlobalAveragePooling(nn.Module):
|
||||
|
||||
def __init__(self):
|
||||
self.gap = nn.AdaptiveAvgPool2d((1, 1))
|
||||
|
||||
def forward(self, inputs):
|
||||
# we regard inputs as tensor for simplicity
|
||||
outs = self.gap(inputs)
|
||||
outs = outs.view(inputs.size(0), -1)
|
||||
return outs
|
||||
```
|
||||
|
||||
2. Import the module in `mmcls/models/necks/__init__.py`.
|
||||
|
||||
```python
|
||||
from .gap import GlobalAveragePooling
|
||||
```
|
||||
|
||||
3. Modify the config file.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
neck=dict(type='GlobalAveragePooling'),
|
||||
)
|
||||
```
|
||||
|
||||
### Add new heads
|
||||
|
||||
Here we show how to develop a new head with the example of `LinearClsHead` as the following.
|
||||
To implement a new head, basically we need to implement `forward_train`, which takes the feature maps from necks or backbones as input and compute loss based on ground-truth labels.
|
||||
|
||||
1. Create a new file in `mmcls/models/heads/linear_head.py`.
|
||||
|
||||
```python
|
||||
from ..builder import HEADS
|
||||
from .cls_head import ClsHead
|
||||
|
||||
|
||||
@HEADS.register_module()
|
||||
class LinearClsHead(ClsHead):
|
||||
|
||||
def __init__(self,
|
||||
num_classes,
|
||||
in_channels,
|
||||
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
|
||||
topk=(1, )):
|
||||
super(LinearClsHead, self).__init__(loss=loss, topk=topk)
|
||||
self.in_channels = in_channels
|
||||
self.num_classes = num_classes
|
||||
|
||||
if self.num_classes <= 0:
|
||||
raise ValueError(
|
||||
f'num_classes={num_classes} must be a positive integer')
|
||||
|
||||
self._init_layers()
|
||||
|
||||
def _init_layers(self):
|
||||
self.fc = nn.Linear(self.in_channels, self.num_classes)
|
||||
|
||||
def init_weights(self):
|
||||
normal_init(self.fc, mean=0, std=0.01, bias=0)
|
||||
|
||||
def forward_train(self, x, gt_label):
|
||||
cls_score = self.fc(x)
|
||||
losses = self.loss(cls_score, gt_label)
|
||||
return losses
|
||||
|
||||
```
|
||||
|
||||
2. Import the module in `mmcls/models/heads/__init__.py`.
|
||||
|
||||
```python
|
||||
from .linear_head import LinearClsHead
|
||||
```
|
||||
|
||||
3. Modify the config file.
|
||||
|
||||
Together with the added GlobalAveragePooling neck, an entire config for a model is as follows.
|
||||
|
||||
```python
|
||||
model = dict(
|
||||
type='ImageClassifier',
|
||||
backbone=dict(
|
||||
type='ResNet',
|
||||
depth=50,
|
||||
num_stages=4,
|
||||
out_indices=(3, ),
|
||||
style='pytorch'),
|
||||
neck=dict(type='GlobalAveragePooling'),
|
||||
head=dict(
|
||||
type='LinearClsHead',
|
||||
num_classes=1000,
|
||||
in_channels=2048,
|
||||
loss=dict(type='CrossEntropyLoss', loss_weight=1.0),
|
||||
topk=(1, 5),
|
||||
))
|
||||
|
||||
```
|
||||
|
||||
### Add new loss
|
||||
|
||||
To add a new loss function, we mainly implement the `forward` function in the loss module.
|
||||
In addition, it is helpful to leverage the decorator `weighted_loss` to weight the loss for each element.
|
||||
Assuming that we want to mimic a probablistic distribution generated from anther classification model, we implement a L1Loss to fulfil the purpose as below.
|
||||
|
||||
1. Create a new file in `mmcls/models/losses/l1_loss.py`.
|
||||
|
||||
```python
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from ..builder import LOSSES
|
||||
from .utils import weighted_loss
|
||||
|
||||
@weighted_loss
|
||||
def l1_loss(pred, target):
|
||||
assert pred.size() == target.size() and target.numel() > 0
|
||||
loss = torch.abs(pred - target)
|
||||
return loss
|
||||
|
||||
@LOSSES.register_module()
|
||||
class L1Loss(nn.Module):
|
||||
|
||||
def __init__(self, reduction='mean', loss_weight=1.0):
|
||||
super(L1Loss, self).__init__()
|
||||
self.reduction = reduction
|
||||
self.loss_weight = loss_weight
|
||||
|
||||
def forward(self,
|
||||
pred,
|
||||
target,
|
||||
weight=None,
|
||||
avg_factor=None,
|
||||
reduction_override=None):
|
||||
assert reduction_override in (None, 'none', 'mean', 'sum')
|
||||
reduction = (
|
||||
reduction_override if reduction_override else self.reduction)
|
||||
loss = self.loss_weight * l1_loss(
|
||||
pred, target, weight, reduction=reduction, avg_factor=avg_factor)
|
||||
return loss
|
||||
```
|
||||
|
||||
2. Import the module in `mmcls/models/losses/__init__.py`.
|
||||
|
||||
```python
|
||||
from .l1_loss import L1Loss, l1_loss
|
||||
```
|
||||
|
||||
3. Modify loss field in the config.
|
||||
|
||||
```python
|
||||
loss=dict(type='L1Loss', loss_weight=1.0))
|
||||
```
|
76
docs_zh-CN/tutorials/onnx2tensorrt.md
Normal file
76
docs_zh-CN/tutorials/onnx2tensorrt.md
Normal file
@ -0,0 +1,76 @@
|
||||
# Tutorial 6: ONNX to TensorRT (Experimental)
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [Tutorial 6: ONNX to TensorRT (Experimental)](#tutorial-6-onnx-to-tensorrt-experimental)
|
||||
- [How to convert models from ONNX to TensorRT](#how-to-convert-models-from-onnx-to-tensorrt)
|
||||
- [Prerequisite](#prerequisite)
|
||||
- [Usage](#usage)
|
||||
- [List of supported models convertable to TensorRT](#list-of-supported-models-convertable-to-tensorrt)
|
||||
- [Reminders](#reminders)
|
||||
- [FAQs](#faqs)
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
## How to convert models from ONNX to TensorRT
|
||||
|
||||
### Prerequisite
|
||||
|
||||
1. Please refer to [install.md](https://mmclassification.readthedocs.io/en/latest/install.html#install-mmclassification) for installation of MMClassification from source.
|
||||
2. Use our tool [pytorch2onnx.md](./pytorch2onnx.md) to convert the model from PyTorch to ONNX.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
python tools/deployment/onnx2tensorrt.py \
|
||||
${MODEL} \
|
||||
--trt-file ${TRT_FILE} \
|
||||
--shape ${IMAGE_SHAPE} \
|
||||
--workspace-size {WORKSPACE_SIZE} \
|
||||
--show \
|
||||
--verify \
|
||||
```
|
||||
|
||||
Description of all arguments:
|
||||
|
||||
- `model` : The path of an ONNX model file.
|
||||
- `--trt-file`: The Path of output TensorRT engine file. If not specified, it will be set to `tmp.trt`.
|
||||
- `--shape`: The height and width of model input. If not specified, it will be set to `224 224`.
|
||||
- `--workspace-size` : The required GPU workspace size in GiB to build TensorRT engine. If not specified, it will be set to `1` GiB.
|
||||
- `--show`: Determines whether to show the outputs of the model. If not specified, it will be set to `False`.
|
||||
- `--verify`: Determines whether to verify the correctness of models between ONNXRuntime and TensorRT. If not specified, it will be set to `False`.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
python tools/onnx2tensorrt.py \
|
||||
checkpoints/resnet/resnet18_b16x8_cifar10.onnx \
|
||||
--trt-file checkpoints/resnet/resnet18_b16x8_cifar10.trt \
|
||||
--shape 224 224 \
|
||||
--show \
|
||||
--verify \
|
||||
```
|
||||
|
||||
## List of supported models convertable to TensorRT
|
||||
|
||||
The table below lists the models that are guaranteed to be convertable to TensorRT.
|
||||
|
||||
| Model | Config | Status |
|
||||
| :----------: | :----------------------------------------------------------: | :----: |
|
||||
| MobileNetV2 | `configs/mobilenet_v2/mobilenet_v2_b32x8_imagenet.py` | Y |
|
||||
| ResNet | `configs/resnet/resnet18_b16x8_cifar10.py` | Y |
|
||||
| ResNeXt | `configs/resnext/resnext50_32x4d_b32x8_imagenet.py` | Y |
|
||||
| ShuffleNetV1 | `configs/shufflenet_v1/shufflenet_v1_1x_b64x16_linearlr_bn_nowd_imagenet.py` | Y |
|
||||
| ShuffleNetV2 | `configs/shufflenet_v2/shufflenet_v2_1x_b64x16_linearlr_bn_nowd_imagenet.py` | Y |
|
||||
|
||||
Notes:
|
||||
|
||||
- *All models above are tested with Pytorch==1.6.0 and TensorRT-7.2.1.6.Ubuntu-16.04.x86_64-gnu.cuda-10.2.cudnn8.0*
|
||||
|
||||
## Reminders
|
||||
|
||||
- If you meet any problem with the listed models above, please create an issue and it would be taken care of soon. For models not included in the list, we may not provide much help here due to the limited resources. Please try to dig a little deeper and debug by yourself.
|
||||
|
||||
## FAQs
|
||||
|
||||
- None
|
89
docs_zh-CN/tutorials/pytorch2onnx.md
Normal file
89
docs_zh-CN/tutorials/pytorch2onnx.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Tutorial 5: Pytorch to ONNX (Experimental)
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [Tutorial 5: Pytorch to ONNX (Experimental)](#tutorial-5-pytorch-to-onnx-experimental)
|
||||
- [How to convert models from Pytorch to ONNX](#how-to-convert-models-from-pytorch-to-onnx)
|
||||
- [Prerequisite](#prerequisite)
|
||||
- [Usage](#usage)
|
||||
- [List of supported models exportable to ONNX](#list-of-supported-models-exportable-to-onnx)
|
||||
- [Reminders](#reminders)
|
||||
- [FAQs](#faqs)
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
## How to convert models from Pytorch to ONNX
|
||||
|
||||
### Prerequisite
|
||||
|
||||
1. Please refer to [install](https://mmclassification.readthedocs.io/en/latest/install.html#install-mmclassification) for installation of MMClassification.
|
||||
2. Install onnx and onnxruntime
|
||||
|
||||
```shell
|
||||
pip install onnx onnxruntime==1.5.1
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
python tools/pytorch2onnx.py \
|
||||
${CONFIG_FILE} \
|
||||
--checkpoint ${CHECKPOINT_FILE} \
|
||||
--output-file ${OUTPUT_FILE} \
|
||||
--shape ${IMAGE_SHAPE} \
|
||||
--opset-version ${OPSET_VERSION} \
|
||||
--dynamic-shape \
|
||||
--show \
|
||||
--simplify \
|
||||
--verify \
|
||||
```
|
||||
|
||||
Description of all arguments:
|
||||
|
||||
- `config` : The path of a model config file.
|
||||
- `--checkpoint` : The path of a model checkpoint file.
|
||||
- `--output-file`: The path of output ONNX model. If not specified, it will be set to `tmp.onnx`.
|
||||
- `--shape`: The height and width of input tensor to the model. If not specified, it will be set to `224 224`.
|
||||
- `--opset-version` : The opset version of ONNX. If not specified, it will be set to `11`.
|
||||
- `--dynamic-shape` : Determines whether to export ONNX with dynamic input shape. If not specified, it will be set to `False`.
|
||||
- `--show`: Determines whether to print the architecture of the exported model. If not specified, it will be set to `False`.
|
||||
- `--simplify`: Determines whether to simplify the exported ONNX model. If not specified, it will be set to `False`.
|
||||
- `--verify`: Determines whether to verify the correctness of an exported model. If not specified, it will be set to `False`.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
python tools/pytorch2onnx.py \
|
||||
configs/resnet/resnet18_b16x8_cifar10.py \
|
||||
--checkpoint checkpoints/resnet/resnet18_b16x8_cifar10.pth \
|
||||
--output-file checkpoints/resnet/resnet18_b16x8_cifar10.onnx \
|
||||
--dynamic-shape \
|
||||
--show \
|
||||
--simplify \
|
||||
--verify \
|
||||
```
|
||||
|
||||
## List of supported models exportable to ONNX
|
||||
|
||||
The table below lists the models that are guaranteed to be exportable to ONNX and runnable in ONNX Runtime.
|
||||
|
||||
| Model | Config | Batch Inference | Dynamic Shape | Note |
|
||||
| :----------: | :----------------------------------------------------------: | :-------------: | :-----------: | ---- |
|
||||
| MobileNetV2 | `configs/mobilenet_v2/mobilenet_v2_b32x8_imagenet.py` | Y | Y | |
|
||||
| ResNet | `configs/resnet/resnet18_b16x8_cifar10.py` | Y | Y | |
|
||||
| ResNeXt | `configs/resnext/resnext50_32x4d_b32x8_imagenet.py` | Y | Y | |
|
||||
| SE-ResNet | `configs/seresnet/seresnet50_b32x8_imagenet.py` | Y | Y | |
|
||||
| ShuffleNetV1 | `configs/shufflenet_v1/shufflenet_v1_1x_b64x16_linearlr_bn_nowd_imagenet.py` | Y | Y | |
|
||||
| ShuffleNetV2 | `configs/shufflenet_v2/shufflenet_v2_1x_b64x16_linearlr_bn_nowd_imagenet.py` | Y | Y | |
|
||||
|
||||
Notes:
|
||||
|
||||
- *All models above are tested with Pytorch==1.6.0*
|
||||
|
||||
## Reminders
|
||||
|
||||
- If you meet any problem with the listed models above, please create an issue and it would be taken care of soon. For models not included in the list, please try to dig a little deeper and debug a little bit more and hopefully solve them by yourself.
|
||||
|
||||
## FAQs
|
||||
|
||||
- None
|
Loading…
x
Reference in New Issue
Block a user