2023-01-11 19:48:41 +08:00
|
|
|
# 检测
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
- [检测](#检测)
|
|
|
|
- [训练](#训练)
|
|
|
|
- [测试](#测试)
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
这里,我们倾向使用 MMDetection 做检测任务。首先确保您已经安装了 [MIM](https://github.com/open-mmlab/mim),这也是 OpenMMLab 的一个项目。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
pip install openmim
|
2022-11-03 14:48:47 +08:00
|
|
|
mim install 'mmdet>=3.0.0rc0'
|
2022-08-31 20:32:46 +08:00
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
非常容易安装这个包。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
此外,请参考 MMDetection 的[安装](https://mmdetection.readthedocs.io/en/dev-3.x/get_started.html)和[数据准备](https://mmdetection.readthedocs.io/en/dev-3.x/user_guides/dataset_prepare.html)
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
## 训练
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
安装完后,您可以使用如下的简单命令运行 MMDetection。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
# distributed version
|
|
|
|
bash tools/benchmarks/mmdetection/mim_dist_train_c4.sh ${CONFIG} ${PRETRAIN} ${GPUS}
|
|
|
|
bash tools/benchmarks/mmdetection/mim_dist_train_fpn.sh ${CONFIG} ${PRETRAIN} ${GPUS}
|
|
|
|
|
|
|
|
# slurm version
|
|
|
|
bash tools/benchmarks/mmdetection/mim_slurm_train_c4.sh ${PARTITION} ${CONFIG} ${PRETRAIN}
|
|
|
|
bash tools/benchmarks/mmdetection/mim_slurm_train_fpn.sh ${PARTITION} ${CONFIG} ${PRETRAIN}
|
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
备注:
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
- `${CONFIG}`: 使用`configs/benchmarks/mmdetection/`下的配置文件。由于 OpenMMLab 的算法库支持跨不同存储库引用配置文件,因此我们可以轻松使用 MMDetection 的配置文件,例如:
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
2022-11-03 14:48:47 +08:00
|
|
|
_base_ = 'mmdet::mask_rcnn/mask-rcnn_r50-caffe-c4_1x_coco.py'
|
2022-08-31 20:32:46 +08:00
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
从头开始写您的配置文件也是支持的。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
- `${PRETRAIN}`:预训练模型文件
|
|
|
|
- `${GPUS}`: 您想用于训练的 GPU 数量,对于检测任务,我们默认采用 8 块 GPU。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
例子:
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
bash ./tools/benchmarks/mmdetection/mim_dist_train_c4.sh \
|
2022-11-03 14:48:47 +08:00
|
|
|
configs/benchmarks/mmdetection/coco/mask-rcnn_r50-c4_ms-1x_coco.py \
|
|
|
|
https://download.openmmlab.com/mmselfsup/1.x/byol/byol_resnet50_16xb256-coslr-200e_in1k/byol_resnet50_16xb256-coslr-200e_in1k_20220825-de817331.pth 8
|
2022-08-31 20:32:46 +08:00
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
或者您想用 [detectron2](https://github.com/facebookresearch/detectron2) 来做检测任务,我们也提供了一些配置文件。
|
|
|
|
请参考 [INSTALL.md](https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md) 用于安装并按照 detectron2 需要的[目录结构](https://github.com/facebookresearch/detectron2/tree/main/datasets)准备您的数据集。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
conda activate detectron2 # use detectron2 environment here, otherwise use open-mmlab environment
|
|
|
|
cd tools/benchmarks/detectron2
|
|
|
|
python convert-pretrain-to-detectron2.py ${WEIGHT_FILE} ${OUTPUT_FILE} # must use .pkl as the output extension.
|
|
|
|
bash run.sh ${DET_CFG} ${OUTPUT_FILE}
|
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
## 测试
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
在训练之后,您可以运行如下命令测试您的模型。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
# distributed version
|
|
|
|
bash tools/benchmarks/mmdetection/mim_dist_test.sh ${CONFIG} ${CHECKPOINT} ${GPUS}
|
|
|
|
|
|
|
|
# slurm version
|
|
|
|
bash tools/benchmarks/mmdetection/mim_slurm_test.sh ${PARTITION} ${CONFIG} ${CHECKPOINT}
|
|
|
|
```
|
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
备注:
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
- `${CHECKPOINT}`:您想测试的训练好的检测模型。
|
2022-08-31 20:32:46 +08:00
|
|
|
|
2023-01-11 19:48:41 +08:00
|
|
|
例子:
|
2022-08-31 20:32:46 +08:00
|
|
|
|
|
|
|
```shell
|
|
|
|
bash ./tools/benchmarks/mmdetection/mim_dist_test.sh \
|
2022-11-03 14:48:47 +08:00
|
|
|
configs/benchmarks/mmdetection/coco/mask-rcnn_r50_fpn_ms-1x_coco.py \
|
|
|
|
https://download.openmmlab.com/mmselfsup/1.x/byol/byol_resnet50_16xb256-coslr-200e_in1k/byol_resnet50_16xb256-coslr-200e_in1k_20220825-de817331.pth 8
|
2022-08-31 20:32:46 +08:00
|
|
|
```
|