2022-08-17 12:06:41 +08:00
# Detection
- [Detection ](#detection )
- [Train ](#train )
2022-08-29 14:31:06 +08:00
- [Test ](#test )
2022-08-17 12:06:41 +08:00
Here, we prefer to use MMDetection to do the detection task. First, make sure you have installed [MIM ](https://github.com/open-mmlab/mim ), which is also a project of OpenMMLab.
```shell
pip install openmim
2022-10-28 17:06:05 +08:00
mim install 'mmdet>=3.0.0rc0'
2022-08-17 12:06:41 +08:00
```
It is very easy to install the package.
2022-10-28 17:06:05 +08:00
Besides, please refer to MMDet for [installation ](https://mmdetection.readthedocs.io/en/dev-3.x/get_started.html ) and [data preparation ](https://mmdetection.readthedocs.io/en/dev-3.x/user_guides/dataset_prepare.html )
2022-08-17 12:06:41 +08:00
## Train
2022-08-29 14:31:06 +08:00
After installation, you can run MMDetection with simple command.
2022-08-17 12:06:41 +08:00
```shell
# distributed version
2022-08-29 14:31:06 +08:00
bash tools/benchmarks/mmdetection/mim_dist_train_c4.sh ${CONFIG} ${PRETRAIN} ${GPUS}
bash tools/benchmarks/mmdetection/mim_dist_train_fpn.sh ${CONFIG} ${PRETRAIN} ${GPUS}
2022-08-17 12:06:41 +08:00
# slurm version
2022-08-29 14:31:06 +08:00
bash tools/benchmarks/mmdetection/mim_slurm_train_c4.sh ${PARTITION} ${CONFIG} ${PRETRAIN}
bash tools/benchmarks/mmdetection/mim_slurm_train_fpn.sh ${PARTITION} ${CONFIG} ${PRETRAIN}
2022-08-17 12:06:41 +08:00
```
Remarks:
2023-01-11 19:48:41 +08:00
- `${CONFIG}` : Use config files under `configs/benchmarks/mmdetection/` . Since repositories of OpenMMLab have support referring config files across different repositories, we can easily leverage the configs from MMDetection like:
2022-08-29 14:31:06 +08:00
```shell
2022-10-28 17:06:05 +08:00
_base_ = 'mmdet::mask_rcnn/mask-rcnn_r50-caffe-c4_1x_coco.py'
2022-08-29 14:31:06 +08:00
```
Writing your config files from scratch is also supported.
2023-01-11 19:48:41 +08:00
- `${PRETRAIN}` : the pre-trained model file.
- `${GPUS}` : The number of GPUs that you want to use to train. We adopt 8 GPUs for detection tasks by default.
2022-08-29 14:31:06 +08:00
Example:
2022-08-17 12:06:41 +08:00
2022-08-29 14:31:06 +08:00
```shell
bash ./tools/benchmarks/mmdetection/mim_dist_train_c4.sh \
2022-10-28 17:06:05 +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-29 14:31:06 +08:00
```
Or if you want to do detection task with [detectron2 ](https://github.com/facebookresearch/detectron2 ), we also provide some config files.
2022-08-17 12:06:41 +08:00
Please refer to [INSTALL.md ](https://github.com/facebookresearch/detectron2/blob/main/INSTALL.md ) for installation and follow the [directory structure ](https://github.com/facebookresearch/detectron2/tree/main/datasets ) to prepare your datasets required by detectron2.
```shell
conda activate detectron2 # use detectron2 environment here, otherwise use open-mmlab environment
2022-08-29 14:31:06 +08:00
cd tools/benchmarks/detectron2
2022-08-17 12:06:41 +08:00
python convert-pretrain-to-detectron2.py ${WEIGHT_FILE} ${OUTPUT_FILE} # must use .pkl as the output extension.
bash run.sh ${DET_CFG} ${OUTPUT_FILE}
```
2022-08-29 14:31:06 +08:00
## Test
After training, you can also run the command below to test your model.
```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}
```
Remarks:
2023-01-11 19:48:41 +08:00
- `${CHECKPOINT}` : The well-trained detection model that you want to test.
2022-08-29 14:31:06 +08:00
Example:
```shell
bash ./tools/benchmarks/mmdetection/mim_dist_test.sh \
2022-10-28 17:06:05 +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-29 14:31:06 +08:00
```