2022-08-17 12:06:41 +08:00
# Segmentation
- [Segmentation ](#segmentation )
- [Train ](#train )
2022-08-29 14:31:06 +08:00
- [Test ](#test )
2022-08-17 12:06:41 +08:00
For semantic segmentation task, we use MMSegmentation. 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 'mmsegmentation>=1.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 MMSegmentation for [installation ](https://mmsegmentation.readthedocs.io/en/dev-1.x/get_started.html ) and [data preparation ](https://mmsegmentation.readthedocs.io/en/dev-1.x/user_guides/2_dataset_prepare.html ).
2022-08-17 12:06:41 +08:00
## Train
After installation, you can run MMSeg with simple command.
```shell
# distributed version
bash tools/benchmarks/mmsegmentation/mim_dist_train.sh ${CONFIG} ${PRETRAIN} ${GPUS}
# slurm version
bash tools/benchmarks/mmsegmentation/mim_slurm_train.sh ${PARTITION} ${CONFIG} ${PRETRAIN}
```
Remarks:
2023-01-11 19:48:41 +08:00
- `${CONFIG}` : Use config files under `configs/benchmarks/mmsegmentation/` . Since repositories of OpenMMLab have support referring config files across different
2022-08-29 14:31:06 +08:00
repositories, we can easily leverage the configs from MMSegmentation like:
```shell
2022-10-28 17:06:05 +08:00
_base_ = 'mmseg::fcn/fcn_r50-d8_4xb2-40k_cityscapes-769x769.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 4 GPUs for segmentation tasks by default.
2022-08-29 14:31:06 +08:00
Example:
```shell
bash ./tools/benchmarks/mmsegmentation/mim_dist_train.sh \
2022-10-28 17:06:05 +08:00
configs/benchmarks/mmsegmentation/voc12aug/fcn_r50-d8_4xb4-20k_voc12aug-512x512.py \
https://download.openmmlab.com/mmselfsup/1.x/byol/byol_resnet50_16xb256-coslr-200e_in1k/byol_resnet50_16xb256-coslr-200e_in1k_20220825-de817331.pth 4
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/mmsegmentation/mim_dist_test.sh ${CONFIG} ${CHECKPOINT} ${GPUS}
# slurm version
bash tools/benchmarks/mmsegmentation/mim_slurm_test.sh ${PARTITION} ${CONFIG} ${CHECKPOINT}
```
Remarks:
2023-01-11 19:48:41 +08:00
- `${CHECKPOINT}` : The well-trained segmentation model that you want to test.
2022-08-29 14:31:06 +08:00
Example:
```shell
bash ./tools/benchmarks/mmsegmentation/mim_dist_test.sh \
2022-10-28 17:06:05 +08:00
configs/benchmarks/mmsegmentation/voc12aug/fcn_r50-d8_4xb4-20k_voc12aug-512x512.py \
https://download.openmmlab.com/mmselfsup/1.x/byol/byol_resnet50_16xb256-coslr-200e_in1k/byol_resnet50_16xb256-coslr-200e_in1k_20220825-de817331.pth 4
2022-08-29 14:31:06 +08:00
```