mmdeploy/docs/zh_cn/04-developer-guide/do_regression_test.md

229 lines
11 KiB
Markdown
Raw Normal View History

[Feature] Regression test for mmdeploy (#302) * Add regression test script * Add doc * Add test yaml for mmdet * evaluate_outputs Add return result (cherry picked from commit c8c9cd75df7916aa4d80a7b8bfb8a78e04446cad) * object_detection return metric after eval (cherry picked from commit 1b8dcaa39ed14f016bf51d1aee65c2c416cd7c33) * move `deploy_config_dir` to `global_info` in test yaml * fix path error * Improve test yaml structure * Add test env for saving regression report * Fix SDK test report will crash * Get SDK FPS * Add mmcls regression test yaml * Using CMD to test the backend result * Get metric from log file * Imporve coding * Imporve coding * restructure test yaml * resturcture the test yaml and coding, using pipeline style * Fixed wont saving into report when cant find `backend_test` and `sdk_config` * set `metric_info` in test yaml * improve test yaml * Fixed will get black checkpoint file name * Fix lint * Fix yaml * Add common in test yaml * Resturcture mmcla test yaml * Resturcture mmcla test yaml * Improve mmcls test yaml * mmcls test success * Improve tes yaml field * Add `--test-img` only when `test_img_path` is not None * Add `precision_type` in report * Not saving pkl result file any more * Add 'x' install of '-' when script crash * Fix some field in mmcls test yaml * Add mmseg test yaml * Add unknown backend final file name * Improve backend file dict * Add mmseg success * unify the checkpoint path to relate path * unify the checkpoint path to relate path * Add mmpose, need to test * Support backend file list to `--model` when test the backend * Fix lint * Add some common * FPS get from log always get 1:10 line * Add dataset in report when test backend * Get dataset type from model config file * Replace pipeline.json topk * SDK report add backend name * Add txt report, it will save each test * update mmcls config * Add `calib-dataset-cfg` in cmd when it exist in tset yaml * make model path shorter by cutting the work_dir_root * Add `task_name` in test yaml * Add `task_name` in report * Improve test yaml * Add mmocr test yaml * Get mmocr fps metric success * Add `dataset` feild in test yaml * Report will skip when the dataset name not in test yaml * Add dbnet in mmocr test yaml and success get metric * Add mmedit test yaml * Improve some common * Add mmedit success * Fix lint * Fix isort lint * Fix yapf lint * Undo some changes in `evaluate_outputs` * Undo some changes in `evaluate_outputs` * Improve test requirement.txt * Undo some changes in `evaluate_outputs` * Improve doc * Improve mmedit test yaml * Using `--divice` * Fix lint * Using `--performance` replace `--test-type` * Fix lint * Fix page link * Fix backend name * Using `logger` instead of `print` * Fix lint * Add TorchScript in the doc * Add type hint for all the funcs * Fix docformatter lint * Fix path in report have the root of work dir * mmdet add other backend in tast yaml * mmdet add other backend in tast yaml * mmocr add other backend in tast yaml * mmedit add other backend in tast yaml * mmpose add other backend in tast yaml * Delete filed `codebase_model_config_dir` in test yaml * Using `Config` in metafile.yml instal of `Name` from allmodel config files. * Fix yapf lint * update mmpose mmseg config * Fix lint * Imporve mmcls test yaml * Imporve mmedit test yaml * Imporve mmedit test yaml * Imporve mmseg test yaml * update mmdet yml * Not using pth when conver sucess when in only convert mode * Using metafile dataset when can not get `model_cfg.dataset_type` * Fixed `model_name` incorrect in some codebase * Improve mmcls test yaml image * Improve mmedit test yaml image * Improve mmocr test yaml image * Improve mmseg test yaml image * Fix test yaml bug * Support overwirte `metric_tolerance` * Add `metric_tolerance` in mmcls * Fixed yaml bug * mmcls add all models, which had already supported, in test yaml * Fix report will not replace to ${WORK_DIR} * Add metric tolerance in mmcls test yaml * Modefied mmcls global metric tolreance * remove `metric_tolerance` in each pipeline * Improve mmcls test yaml * mmcls add TODO * imporve test yaml `pp`l -> `pplnn` * mmdet add all models, which had already supported, in test yaml * mmedit add all models, which had already supported, in test yaml * mmocr add all models, which had already supported, in test yaml * mmpose add all models, which had already supported, in test yaml * Replace `sdk_xxx_fp32` to `sdk_xxx` * mmseg add all models, which had already supported, in test yaml * Import the backend order of test yaml * Fix mmseg test yaml pplnn static config * Add notes for Windows user in the doc * Fix get metric from different metric name but correct dataset name. * Fix mmedit dataset incorrect * Fix test yaml of mmedit * Fix lint * Fix mmpose can't find metric * Improve mmseg trt testing config * Add dataset in mmdet test yaml * Add logs when continue in the code * Fix mmpose get metric log error * Fix mmdet can not get metric * Add merge report into one * Fix lint * Add version in the report * log2file for each backend * Fix lint * Improve report merge * update mmseg yml to shape 1024x2048 * Fix dependences for merging report * Imporve mmcls yaml, add `ShuffleNetV1` and `ShuffleNetV2` * Fix name of model in test yaml with a space will crash when convert * Add commons for test yaml metric tolerance * Add mmdet seg detail config in test yaml * Improve mmdet test yaml * Fix mmdet mskrcnn metric Co-authored-by: maningsheng <mnsheng@yeah.net>
2022-04-28 08:03:59 +08:00
# 如何进行回归测试
<!-- -->
这篇教程介绍了如何进行回归测试。部署配置文件由`每个codebase的回归配置文件``推理框架配置信息`组成。
<!-- TOC -->
- [如何进行回归测试](#如何进行回归测试)
- [1. 用法](#1-用法)
- [参数解析](#参数解析)
- [示例](#示例)
- [2. 回归测试配置文件](#2-回归测试配置文件)
- [示例及参数解析](#示例及参数解析)
- [3. 生成的报告](#3-生成的报告)
- [模板](#模板)
- [示例](#示例)
- [4. 支持的后端](#4-支持的后端)
- [5. 支持的Codebase及其Metric](#5-支持的Codebase及其Metric)
- [6. 注意事项](#7-注意事项)
- [7. 常见问题](#8-常见问题)
<!-- TOC -->
## 1. 用法
```shell
python ./tools/regression_test.py \
--deploy-yml "${DEPLOY_YML_PATH}" \
--backends "${BACKEND}" \
--work-dir "${WORK_DIR}" \
--device "${DEVICE}" \
--log-level INFO \
[--performance]
```
### 参数解析
- `--deploy-yml` : 需要测试的 codebaseeg.`configs/mmdet/mmdet_regression_test.yaml`,如果设置为 `all` 即全部测试。
- `--backends` : 筛选测试的后端, 默认 `all`: 测全部`backend`, 也可传入若干个后端,例如 `onnxruntime tesnsorrt`
- `--work-dir` : 模型转换、报告生成的路径。
- `--device` : 使用的设备,默认 `cuda`
- `--log-level` : 设置日记的等级,选项包括`'CRITICAL' 'FATAL' 'ERROR' 'WARN' 'WARNING' 'INFO' 'DEBUG' 'NOTSET'`。默认是`INFO`。
- `--performance` : 是否测试精度,加上则测试转换+精度,不加上则只测试转换
### 注意事项
对于 Windows 用户:
1. 要在 shell 命令中使用 `&&` 连接符,需要下载并使用 `PowerShell 7 Preview 5+`
2. 如果您使用 conda env可能需要在 regression_test.py 中将 `python3` 更改为 `python`,因为 `%USERPROFILE%\AppData\Local\Microsoft\WindowsApps` 目录中有 `python3.exe`
## 例子
1. 测试 mmdet 和 mmpose 的所有 backend 的 转换+精度
```shell
python ./tools/regression_test.py \
--deploy-yml ./configs/mmdet/mmdet_regression_test.yaml ./configs/mmpose/mmpose_regression_test.yaml \
--backends all \
--work-dir "../mmdeploy_regression_working_dir" \
--device "cuda" \
--log-level INFO \
--performance
```
2. 测试 mmdet 和 mmpose 的某几个 backend 的 转换+精度
```shell
python ./tools/regression_test.py \
--deploy-yml ./configs/mmdet/mmdet_regression_test.yaml ./configs/mmdet/mmpose.yaml \
--backends onnxruntime tesnsorrt \
--work-dir "../mmdeploy_regression_working_dir" \
--device "cuda" \
--log-level INFO \
--performance
```
3. 测试 mmdet 和 mmpose 的某几个 backend只需测试转换
```shell
python ./tools/regression_test.py \
--deploy-yml ./configs/mmdet/mmdet_regression_test.yaml ./configs/mmdet/mmpose.yaml \
--backends onnxruntime tesnsorrt \
--work-dir "../mmdeploy_regression_working_dir" \
--device "cuda" \
--log-level INFO
```
## 2. 回归测试配置文件
### 示例及参数解析
```yaml
globals:
codebase_name: mmocr # 回归测试的 codebase 名称
codebase_dir: ../mmocr # 回归测试的 codebase 路径
checkpoint_force_download: False # 回归测试是否重新下载模型即使其已经存在
checkpoint_dir: ../mmdeploy_checkpoints # 回归测试是否下载模型的路径
images: # 测试使用图片
img_224x224: &img_224x224 ./tests/data/tiger.jpeg
img_300x300: &img_300x300
img_800x1344: &img_cityscapes_800x1344
img_blank: &img_blank
metric_info: &metric_info # 指标参数
hmean-iou: # 命名根据 metafile.Results.Metrics
eval_name: hmean-iou # 命名根据 test.py --metrics args 入参名称
metric_key: 0_hmean-iou:hmean # 命名根据 eval 写入 log 的 key name
tolerance: 0.1 # 容忍的阈值区间
task_name: Text Detection # 命名根据模型 metafile.Results.Task
dataset: ICDAR2015 #命名根据模型 metafile.Results.Dataset
word_acc: # 同上
eval_name: acc
metric_key: 0_word_acc_ignore_case
tolerance: 0.2
task_name: Text Recognition
dataset: IIIT5K
convert_image: &convert_image # 转换会使用到的图片
input_img: *img_224x224
test_img: *img_300x300
backend_test: &default_backend_test True # 是否对 backend 进行精度测试
sdk: # SDK 配置文件
sdk_detection_dynamic: &sdk_detection_dynamic configs/mmocr/text-detection/text-detection_sdk_dynamic.py
sdk_recognition_dynamic: &sdk_recognition_dynamic configs/mmocr/text-recognition/text-recognition_sdk_dynamic.py
onnxruntime:
pipeline_ort_recognition_static_fp32: &pipeline_ort_recognition_static_fp32
convert_image: *convert_image # 转换过程中使用的图片
backend_test: *default_backend_test # 是否进行后端测试,存在则判断,不存在则视为 False
sdk_config: *sdk_recognition_dynamic # 是否进行SDK测试存在则使用特定的 SDK config 进行测试,不存在则视为不进行 SDK 测试
deploy_config: configs/mmocr/text-recognition/text-recognition_onnxruntime_static.py # 使用的 deploy cfg 路径,基于 mmdeploy 的路径
pipeline_ort_recognition_dynamic_fp32: &pipeline_ort_recognition_dynamic_fp32
convert_image: *convert_image
backend_test: *default_backend_test
sdk_config: *sdk_recognition_dynamic
deploy_config: configs/mmocr/text-recognition/text-recognition_onnxruntime_dynamic.py
pipeline_ort_detection_dynamic_fp32: &pipeline_ort_detection_dynamic_fp32
convert_image: *convert_image
deploy_config: configs/mmocr/text-detection/text-detection_onnxruntime_dynamic.py
tensorrt:
pipeline_trt_recognition_dynamic_fp16: &pipeline_trt_recognition_dynamic_fp16
convert_image: *convert_image
backend_test: *default_backend_test
sdk_config: *sdk_recognition_dynamic
deploy_config: configs/mmocr/text-recognition/text-recognition_tensorrt-fp16_dynamic-1x32x32-1x32x640.py
pipeline_trt_detection_dynamic_fp16: &pipeline_trt_detection_dynamic_fp16
convert_image: *convert_image
backend_test: *default_backend_test
sdk_config: *sdk_detection_dynamic
deploy_config: configs/mmocr/text-detection/text-detection_tensorrt-fp16_dynamic-320x320-1024x1824.py
openvino:
# 此处省略,内容同上
ncnn:
# 此处省略,内容同上
pplnn:
# 此处省略,内容同上
torchscript:
# 此处省略,内容同上
models:
- name: crnn # 模型名称
metafile: configs/textrecog/crnn/metafile.yml # 模型对应的 metafile 的路径,相对于 codebase 的路径
codebase_model_config_dir: configs/textrecog/crnn # `model_configs` 的父文件夹路径,相对于 codebase 的路径
model_configs: # 需要测试的 config 名称
- crnn_academic_dataset.py
pipelines: # 使用的 pipeline
- *pipeline_ort_recognition_dynamic_fp32
- name: dbnet
metafile: configs/textdet/dbnet/metafile.yml
codebase_model_config_dir: configs/textdet/dbnet
model_configs:
- dbnet_r18_fpnc_1200e_icdar2015.py
pipelines:
- *pipeline_ort_detection_dynamic_fp32
- *pipeline_trt_detection_dynamic_fp16
```
## 3. 生成的报告
### 模板
|| model_name | model_config | task_name | model_checkpoint_name | dataset | backend_name | deploy_config | static_or_dynamic | precision_type | conversion_result | fps | metric_1 | metric_2 | metric_n | test_pass |
|------------|--------------|-----------------|-----------------------|----------|--------------|---------------|-------------------|----------------|-------------------|---|----------|----------|-----------|-----------|-----|
| 序号 | 模型名称 | model config 路径 | 执行的 task name | `.pth`模型路径 | 数据集名称 | 后端名称 | deploy cfg 路径 | 动态 or 静态 | 测试精度 | 模型转换结果 | FPS 数值 | 指标 1 数值 | 指标 2 数值 | 指标 n 数值 | 后端测试结果 |
### 示例
这是 MMOCR 生成的报告
|| model_name | model_config | task_name | model_checkpoint_name | dataset | backend_name | deploy_config | static_or_dynamic | precision_type | conversion_result | fps | hmean-iou | word_acc | test_pass |
| ---- | ---------- | ------------------------------------------------------------ | ---------------- | ------------------------------------------------------------ | --------- | --------------- | ------------------------------------------------------------ | ----------------- | -------------- | ----------------- |-----------|----------|-----------| --------- |
| 0 | crnn | ../mmocr/configs/textrecog/crnn/crnn_academic_dataset.py | Text Recognition | ../mmdeploy_checkpoints/mmocr/crnn/crnn_academic-a723a1c5.pth | IIIT5K | Pytorch| -| - | - | - | - | - | 80.5 | -|
| 1 | crnn | ../mmocr/configs/textrecog/crnn/crnn_academic_dataset.py | Text Recognition | ${WORK_DIR}/mmocr/crnn/onnxruntime/static/crnn_academic-a723a1c5/end2end.onnx | x| onnxruntime | configs/mmocr/text-recognition/text-recognition_onnxruntime_dynamic.py | static | fp32 | True | 182.21 | - | 80.67 | True|
| 2 | crnn | ../mmocr/configs/textrecog/crnn/crnn_academic_dataset.py | Text Recognition | ${WORK_DIR}/mmocr/crnn/onnxruntime/static/crnn_academic-a723a1c5 | x| SDK-onnxruntime | configs/mmocr/text-recognition/text-recognition_sdk_dynamic.py | static | fp32 | True | x | - | x | False |
| 3 | dbnet| ../mmocr/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py | Text Detection | ../mmdeploy_checkpoints/mmocr/dbnet/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597.pth | ICDAR2015 | Pytorch| -| - | - | - | - | 0.795 | - | -|
| 4 | dbnet| ../mmocr/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py | Text Detection | ../mmdeploy_checkpoints/mmocr/dbnet/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597.pth | ICDAR | onnxruntime | configs/mmocr/text-detection/text-detection_onnxruntime_dynamic.py | dynamic | fp32 | True | - | - | - | True|
| 5 | dbnet| ../mmocr/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py | Text Detection | ${WORK_DIR}/mmocr/dbnet/tensorrt/dynamic/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597/end2end.engine | ICDAR | tensorrt | configs/mmocr/text-detection/text-detection_tensorrt-fp16_dynamic-320x320-1024x1824.py | dynamic | fp16 | True | 229.06 | 0.793302 | - | True|
| 6 | dbnet| ../mmocr/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py | Text Detection | ${WORK_DIR}/mmocr/dbnet/tensorrt/dynamic/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597 | ICDAR | SDK-tensorrt | configs/mmocr/text-detection/text-detection_sdk_dynamic.py | dynamic | fp16 | True | 140.06 | 0.795073 | - | True|
## 4. 支持的后端
- [x] ONNX Runtime
- [x] TensorRT
- [x] PPLNN
- [x] ncnn
- [x] OpenVINO
- [x] TorchScript
- [x] MMDeploy SDK
## 5. 支持的Codebase及其Metric
- [x] mmdet
- [x] bbox
- [x] mmcls
- [x] accuracy
- [x] mmseg
- [x] mIoU
- [x] mmpose
- [x] AR
- [x] AP
- [x] mmocr
- [x] hmean
- [x] acc
- [x] mmedit
- [x] PSNR
- [x] SSIM