mirror of
https://github.com/open-mmlab/mmsegmentation.git
synced 2025-06-03 22:03:48 +08:00
Doc refactor (#311)
* refactor docs * add docs * add modelzoo * refactor getting started
This commit is contained in:
parent
a5d15ae228
commit
aba6d62c65
165
docs/dataset_prepare.md
Normal file
165
docs/dataset_prepare.md
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
## Prepare datasets
|
||||||
|
|
||||||
|
It is recommended to symlink the dataset root to `$MMSEGMENTATION/data`.
|
||||||
|
If your folder structure is different, you may need to change the corresponding paths in config files.
|
||||||
|
|
||||||
|
```none
|
||||||
|
mmsegmentation
|
||||||
|
├── mmseg
|
||||||
|
├── tools
|
||||||
|
├── configs
|
||||||
|
├── data
|
||||||
|
│ ├── cityscapes
|
||||||
|
│ │ ├── leftImg8bit
|
||||||
|
│ │ │ ├── train
|
||||||
|
│ │ │ ├── val
|
||||||
|
│ │ ├── gtFine
|
||||||
|
│ │ │ ├── train
|
||||||
|
│ │ │ ├── val
|
||||||
|
│ ├── VOCdevkit
|
||||||
|
│ │ ├── VOC2012
|
||||||
|
│ │ │ ├── JPEGImages
|
||||||
|
│ │ │ ├── SegmentationClass
|
||||||
|
│ │ │ ├── ImageSets
|
||||||
|
│ │ │ │ ├── Segmentation
|
||||||
|
│ │ ├── VOC2010
|
||||||
|
│ │ │ ├── JPEGImages
|
||||||
|
│ │ │ ├── SegmentationClassContext
|
||||||
|
│ │ │ ├── ImageSets
|
||||||
|
│ │ │ │ ├── SegmentationContext
|
||||||
|
│ │ │ │ │ ├── train.txt
|
||||||
|
│ │ │ │ │ ├── val.txt
|
||||||
|
│ │ │ ├── trainval_merged.json
|
||||||
|
│ │ ├── VOCaug
|
||||||
|
│ │ │ ├── dataset
|
||||||
|
│ │ │ │ ├── cls
|
||||||
|
│ ├── ade
|
||||||
|
│ │ ├── ADEChallengeData2016
|
||||||
|
│ │ │ ├── annotations
|
||||||
|
│ │ │ │ ├── training
|
||||||
|
│ │ │ │ ├── validation
|
||||||
|
│ │ │ ├── images
|
||||||
|
│ │ │ │ ├── training
|
||||||
|
│ │ │ │ ├── validation
|
||||||
|
│ ├── CHASE_DB1
|
||||||
|
│ │ ├── images
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ │ ├── annotations
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ ├── DRIVE
|
||||||
|
│ │ ├── images
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ │ ├── annotations
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ ├── HRF
|
||||||
|
│ │ ├── images
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ │ ├── annotations
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ ├── STARE
|
||||||
|
│ │ ├── images
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
│ │ ├── annotations
|
||||||
|
│ │ │ ├── training
|
||||||
|
│ │ │ ├── validation
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cityscapes
|
||||||
|
|
||||||
|
The data could be found [here](https://www.cityscapes-dataset.com/downloads/) after registration.
|
||||||
|
|
||||||
|
By convention, `**labelTrainIds.png` are used for cityscapes training.
|
||||||
|
We provided a [scripts](https://github.com/open-mmlab/mmsegmentation/blob/master/tools/convert_datasets/cityscapes.py) based on [cityscapesscripts](https://github.com/mcordts/cityscapesScripts)
|
||||||
|
to generate `**labelTrainIds.png`.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||||
|
python tools/convert_datasets/cityscapes.py data/cityscapes --nproc 8
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pascal VOC
|
||||||
|
|
||||||
|
Pascal VOC 2012 could be downloaded from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar).
|
||||||
|
Beside, most recent works on Pascal VOC dataset usually exploit extra augmentation data, which could be found [here](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz).
|
||||||
|
|
||||||
|
If you would like to use augmented VOC dataset, please run following command to convert augmentation annotations into proper format.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# --nproc means 8 process for conversion, which could be omitted as well.
|
||||||
|
python tools/convert_datasets/voc_aug.py data/VOCdevkit data/VOCdevkit/VOCaug --nproc 8
|
||||||
|
```
|
||||||
|
|
||||||
|
Please refer to [concat dataset](https://github.com/open-mmlab/mmsegmentation/blob/master/docs/tutorials/new_dataset.md#concatenate-dataset) for details about how to concatenate them and train them together.
|
||||||
|
|
||||||
|
### ADE20K
|
||||||
|
|
||||||
|
The training and validation set of ADE20K could be download from this [link](http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip).
|
||||||
|
We may also download test set from [here](http://data.csail.mit.edu/places/ADEchallenge/release_test.zip).
|
||||||
|
|
||||||
|
### Pascal Context
|
||||||
|
|
||||||
|
The training and validation set of Pascal Context could be download from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar). You may also download test set from [here](http://host.robots.ox.ac.uk:8080/eval/downloads/VOC2010test.tar) after registration.
|
||||||
|
|
||||||
|
To split the training and validation set from original dataset, you may download trainval_merged.json from [here](https://codalabuser.blob.core.windows.net/public/trainval_merged.json).
|
||||||
|
|
||||||
|
If you would like to use Pascal Context dataset, please install [Detail](https://github.com/zhanghang1989/detail-api) and then run the following command to convert annotations into proper format.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/convert_datasets/pascal_context.py data/VOCdevkit data/VOCdevkit/VOC2010/trainval_merged.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### CHASE DB1
|
||||||
|
|
||||||
|
The training and validation set of CHASE DB1 could be download from [here](https://staffnet.kingston.ac.uk/~ku15565/CHASE_DB1/assets/CHASEDB1.zip).
|
||||||
|
|
||||||
|
To convert CHASE DB1 dataset to MMSegmentation format, you should run the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/convert_datasets/chase_db1.py /path/to/CHASEDB1.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will make directory structure automatically.
|
||||||
|
|
||||||
|
### DRIVE
|
||||||
|
|
||||||
|
The training and validation set of DRIVE could be download from [here](https://drive.grand-challenge.org/). Before that, you should register an account. Currently '1st_manual' is not provided officially.
|
||||||
|
|
||||||
|
To convert DRIVE dataset to MMSegmentation format, you should run the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/convert_datasets/drive.py /path/to/training.zip /path/to/test.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will make directory structure automatically.
|
||||||
|
|
||||||
|
### HRF
|
||||||
|
|
||||||
|
First, download [healthy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy.zip), [glaucoma.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma.zip), [diabetic_retinopathy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy.zip), [healthy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy_manualsegm.zip), [glaucoma_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma_manualsegm.zip) and [diabetic_retinopathy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy_manualsegm.zip).
|
||||||
|
|
||||||
|
To convert HRF dataset to MMSegmentation format, you should run the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/convert_datasets/hrf.py /path/to/healthy.zip /path/to/healthy_manualsegm.zip /path/to/glaucoma.zip /path/to/glaucoma_manualsegm.zip /path/to/diabetic_retinopathy.zip /path/to/diabetic_retinopathy_manualsegm.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will make directory structure automatically.
|
||||||
|
|
||||||
|
### STARE
|
||||||
|
|
||||||
|
First, download [stare-images.tar](http://cecas.clemson.edu/~ahoover/stare/probing/stare-images.tar), [labels-ah.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-ah.tar) and [labels-vk.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-vk.tar).
|
||||||
|
|
||||||
|
To convert STARE dataset to MMSegmentation format, you should run the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/convert_datasets/stare.py /path/to/stare-images.tar /path/to/labels-ah.tar /path/to/labels-vk.tar
|
||||||
|
```
|
||||||
|
|
||||||
|
The script will make directory structure automatically.
|
@ -1,9 +1,14 @@
|
|||||||
## Requirements
|
## Prerequisites
|
||||||
|
|
||||||
- Linux or Windows(Experimental)
|
- Linux or macOS (Windows is in experimental support)
|
||||||
- Python 3.6+
|
- Python 3.6+
|
||||||
- PyTorch 1.3 or higher
|
- PyTorch 1.3+
|
||||||
- [mmcv](https://github.com/open-mmlab/mmcv)
|
- CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
|
||||||
|
- GCC 5+
|
||||||
|
- [MMCV](https://mmcv.readthedocs.io/en/latest/#installation)
|
||||||
|
|
||||||
|
Note: You need to run `pip uninstall mmcv` first if you have mmcv installed.
|
||||||
|
If mmcv and mmcv-full are both installed, there will be `ModuleNotFoundError`.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -91,9 +96,9 @@ Note:
|
|||||||
5. Some dependencies are optional. Simply running `pip install -e .` will only install the minimum runtime requirements.
|
5. Some dependencies are optional. Simply running `pip install -e .` will only install the minimum runtime requirements.
|
||||||
To use optional dependencies like `cityscapessripts` either install them manually with `pip install -r requirements/optional.txt` or specify desired extras when calling `pip` (e.g. `pip install -e .[optional]`). Valid keys for the extras field are: `all`, `tests`, `build`, and `optional`.
|
To use optional dependencies like `cityscapessripts` either install them manually with `pip install -r requirements/optional.txt` or specify desired extras when calling `pip` (e.g. `pip install -e .[optional]`). Valid keys for the extras field are: `all`, `tests`, `build`, and `optional`.
|
||||||
|
|
||||||
## A from-scratch setup script
|
### A from-scratch setup script
|
||||||
|
|
||||||
### Linux
|
#### Linux
|
||||||
|
|
||||||
Here is a full script for setting up mmsegmentation with conda and link the dataset path (supposing that your dataset path is $DATA_ROOT).
|
Here is a full script for setting up mmsegmentation with conda and link the dataset path (supposing that your dataset path is $DATA_ROOT).
|
||||||
|
|
||||||
@ -111,7 +116,7 @@ mkdir data
|
|||||||
ln -s $DATA_ROOT data
|
ln -s $DATA_ROOT data
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows(Experimental)
|
#### Windows(Experimental)
|
||||||
|
|
||||||
Here is a full script for setting up mmsegmentation with conda and link the dataset path (supposing that your dataset path is
|
Here is a full script for setting up mmsegmentation with conda and link the dataset path (supposing that your dataset path is
|
||||||
%DATA_ROOT%. Notice: It must be an absolute path).
|
%DATA_ROOT%. Notice: It must be an absolute path).
|
||||||
@ -130,3 +135,59 @@ pip install -e . # or "python setup.py develop"
|
|||||||
|
|
||||||
mklink /D data %DATA_ROOT%
|
mklink /D data %DATA_ROOT%
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Developing with multiple MMSegmentation versions
|
||||||
|
|
||||||
|
The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMSegmentation in the current directory.
|
||||||
|
|
||||||
|
To use the default MMSegmentation installed in the environment rather than that you are working with, you can remove the following line in those scripts
|
||||||
|
|
||||||
|
```shell
|
||||||
|
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
To verify whether MMSegmentation and the required environment are installed correctly, we can run sample python codes to initialize a detector and inference a demo image:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from mmseg.apis import inference_segmentor, init_segmentor
|
||||||
|
import mmcv
|
||||||
|
|
||||||
|
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
|
||||||
|
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
||||||
|
|
||||||
|
# build the model from a config file and a checkpoint file
|
||||||
|
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
|
||||||
|
|
||||||
|
# test a single image and show the results
|
||||||
|
img = 'test.jpg' # or img = mmcv.imread(img), which will only load it once
|
||||||
|
result = inference_segmentor(model, img)
|
||||||
|
# visualize the results in a new window
|
||||||
|
model.show_result(img, result, show=True)
|
||||||
|
# or save the visualization results to image files
|
||||||
|
model.show_result(img, result, out_file='result.jpg')
|
||||||
|
|
||||||
|
# test a video and show the results
|
||||||
|
video = mmcv.VideoReader('video.mp4')
|
||||||
|
for frame in video:
|
||||||
|
result = inference_segmentor(model, frame)
|
||||||
|
model.show_result(frame, result, wait_time=1)
|
||||||
|
```
|
||||||
|
|
||||||
|
The above code is supposed to run successfully upon you finish the installation.
|
||||||
|
|
||||||
|
We also provide a demo script to test a single image.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${DEVICE_NAME}] [--palette-thr ${PALETTE}]
|
||||||
|
```
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python demo/image_demo.py demo/demo.jpg configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --palette cityscapes
|
||||||
|
```
|
||||||
|
|
||||||
|
A notebook demo can be found in [demo/inference_demo.ipynb](../demo/inference_demo.ipynb).
|
@ -1,449 +0,0 @@
|
|||||||
# Getting Started
|
|
||||||
|
|
||||||
This page provides basic tutorials about the usage of MMSegmentation.
|
|
||||||
For installation instructions, please see [install.md](install.md).
|
|
||||||
|
|
||||||
## Prepare datasets
|
|
||||||
|
|
||||||
It is recommended to symlink the dataset root to `$MMSEGMENTATION/data`.
|
|
||||||
If your folder structure is different, you may need to change the corresponding paths in config files.
|
|
||||||
|
|
||||||
```none
|
|
||||||
mmsegmentation
|
|
||||||
├── mmseg
|
|
||||||
├── tools
|
|
||||||
├── configs
|
|
||||||
├── data
|
|
||||||
│ ├── cityscapes
|
|
||||||
│ │ ├── leftImg8bit
|
|
||||||
│ │ │ ├── train
|
|
||||||
│ │ │ ├── val
|
|
||||||
│ │ ├── gtFine
|
|
||||||
│ │ │ ├── train
|
|
||||||
│ │ │ ├── val
|
|
||||||
│ ├── VOCdevkit
|
|
||||||
│ │ ├── VOC2012
|
|
||||||
│ │ │ ├── JPEGImages
|
|
||||||
│ │ │ ├── SegmentationClass
|
|
||||||
│ │ │ ├── ImageSets
|
|
||||||
│ │ │ │ ├── Segmentation
|
|
||||||
│ │ ├── VOC2010
|
|
||||||
│ │ │ ├── JPEGImages
|
|
||||||
│ │ │ ├── SegmentationClassContext
|
|
||||||
│ │ │ ├── ImageSets
|
|
||||||
│ │ │ │ ├── SegmentationContext
|
|
||||||
│ │ │ │ │ ├── train.txt
|
|
||||||
│ │ │ │ │ ├── val.txt
|
|
||||||
│ │ │ ├── trainval_merged.json
|
|
||||||
│ │ ├── VOCaug
|
|
||||||
│ │ │ ├── dataset
|
|
||||||
│ │ │ │ ├── cls
|
|
||||||
│ ├── ade
|
|
||||||
│ │ ├── ADEChallengeData2016
|
|
||||||
│ │ │ ├── annotations
|
|
||||||
│ │ │ │ ├── training
|
|
||||||
│ │ │ │ ├── validation
|
|
||||||
│ │ │ ├── images
|
|
||||||
│ │ │ │ ├── training
|
|
||||||
│ │ │ │ ├── validation
|
|
||||||
│ ├── CHASE_DB1
|
|
||||||
│ │ ├── images
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ │ ├── annotations
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ ├── DRIVE
|
|
||||||
│ │ ├── images
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ │ ├── annotations
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ ├── HRF
|
|
||||||
│ │ ├── images
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ │ ├── annotations
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ ├── STARE
|
|
||||||
│ │ ├── images
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
│ │ ├── annotations
|
|
||||||
│ │ │ ├── training
|
|
||||||
│ │ │ ├── validation
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Cityscapes
|
|
||||||
|
|
||||||
The data could be found [here](https://www.cityscapes-dataset.com/downloads/) after registration.
|
|
||||||
|
|
||||||
By convention, `**labelTrainIds.png` are used for cityscapes training.
|
|
||||||
We provided a [scripts](https://github.com/open-mmlab/mmsegmentation/blob/master/tools/convert_datasets/cityscapes.py) based on [cityscapesscripts](https://github.com/mcordts/cityscapesScripts)
|
|
||||||
to generate `**labelTrainIds.png`.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
|
||||||
python tools/convert_datasets/cityscapes.py data/cityscapes --nproc 8
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pascal VOC
|
|
||||||
|
|
||||||
Pascal VOC 2012 could be downloaded from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar).
|
|
||||||
Beside, most recent works on Pascal VOC dataset usually exploit extra augmentation data, which could be found [here](http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz).
|
|
||||||
|
|
||||||
If you would like to use augmented VOC dataset, please run following command to convert augmentation annotations into proper format.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# --nproc means 8 process for conversion, which could be omitted as well.
|
|
||||||
python tools/convert_datasets/voc_aug.py data/VOCdevkit data/VOCdevkit/VOCaug --nproc 8
|
|
||||||
```
|
|
||||||
|
|
||||||
Please refer to [concat dataset](https://github.com/open-mmlab/mmsegmentation/blob/master/docs/tutorials/new_dataset.md#concatenate-dataset) for details about how to concatenate them and train them together.
|
|
||||||
|
|
||||||
### ADE20K
|
|
||||||
|
|
||||||
The training and validation set of ADE20K could be download from this [link](http://data.csail.mit.edu/places/ADEchallenge/ADEChallengeData2016.zip).
|
|
||||||
We may also download test set from [here](http://data.csail.mit.edu/places/ADEchallenge/release_test.zip).
|
|
||||||
|
|
||||||
### Pascal Context
|
|
||||||
|
|
||||||
The training and validation set of Pascal Context could be download from [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2010/VOCtrainval_03-May-2010.tar). You may also download test set from [here](http://host.robots.ox.ac.uk:8080/eval/downloads/VOC2010test.tar) after registration.
|
|
||||||
|
|
||||||
To split the training and validation set from original dataset, you may download trainval_merged.json from [here](https://codalabuser.blob.core.windows.net/public/trainval_merged.json).
|
|
||||||
|
|
||||||
If you would like to use Pascal Context dataset, please install [Detail](https://github.com/zhanghang1989/detail-api) and then run the following command to convert annotations into proper format.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/convert_datasets/pascal_context.py data/VOCdevkit data/VOCdevkit/VOC2010/trainval_merged.json
|
|
||||||
```
|
|
||||||
|
|
||||||
### CHASE DB1
|
|
||||||
|
|
||||||
The training and validation set of CHASE DB1 could be download from [here](https://staffnet.kingston.ac.uk/~ku15565/CHASE_DB1/assets/CHASEDB1.zip).
|
|
||||||
|
|
||||||
To convert CHASE DB1 dataset to MMSegmentation format, you should run the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/convert_datasets/chase_db1.py /path/to/CHASEDB1.zip
|
|
||||||
```
|
|
||||||
|
|
||||||
The script will make directory structure automatically.
|
|
||||||
|
|
||||||
### DRIVE
|
|
||||||
|
|
||||||
The training and validation set of DRIVE could be download from [here](https://drive.grand-challenge.org/). Before that, you should register an account. Currently '1st_manual' is not provided officially.
|
|
||||||
|
|
||||||
To convert DRIVE dataset to MMSegmentation format, you should run the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/convert_datasets/drive.py /path/to/training.zip /path/to/test.zip
|
|
||||||
```
|
|
||||||
|
|
||||||
The script will make directory structure automatically.
|
|
||||||
|
|
||||||
### HRF
|
|
||||||
|
|
||||||
First, download [healthy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy.zip), [glaucoma.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma.zip), [diabetic_retinopathy.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy.zip), [healthy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/healthy_manualsegm.zip), [glaucoma_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/glaucoma_manualsegm.zip) and [diabetic_retinopathy_manualsegm.zip](https://www5.cs.fau.de/fileadmin/research/datasets/fundus-images/diabetic_retinopathy_manualsegm.zip).
|
|
||||||
|
|
||||||
To convert HRF dataset to MMSegmentation format, you should run the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/convert_datasets/hrf.py /path/to/healthy.zip /path/to/healthy_manualsegm.zip /path/to/glaucoma.zip /path/to/glaucoma_manualsegm.zip /path/to/diabetic_retinopathy.zip /path/to/diabetic_retinopathy_manualsegm.zip
|
|
||||||
```
|
|
||||||
|
|
||||||
The script will make directory structure automatically.
|
|
||||||
|
|
||||||
### STARE
|
|
||||||
|
|
||||||
First, download [stare-images.tar](http://cecas.clemson.edu/~ahoover/stare/probing/stare-images.tar), [labels-ah.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-ah.tar) and [labels-vk.tar](http://cecas.clemson.edu/~ahoover/stare/probing/labels-vk.tar).
|
|
||||||
|
|
||||||
To convert STARE dataset to MMSegmentation format, you should run the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/convert_datasets/stare.py /path/to/stare-images.tar /path/to/labels-ah.tar /path/to/labels-vk.tar
|
|
||||||
```
|
|
||||||
|
|
||||||
The script will make directory structure automatically.
|
|
||||||
|
|
||||||
## Inference with pretrained models
|
|
||||||
|
|
||||||
We provide testing scripts to evaluate a whole dataset (Cityscapes, PASCAL VOC, ADE20k, etc.),
|
|
||||||
and also some high-level apis for easier integration to other projects.
|
|
||||||
|
|
||||||
### 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}] [--eval ${EVAL_METRICS}] [--show]
|
|
||||||
|
|
||||||
# multi-gpu testing
|
|
||||||
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}] [--eval ${EVAL_METRICS}]
|
|
||||||
```
|
|
||||||
|
|
||||||
Optional arguments:
|
|
||||||
|
|
||||||
- `RESULT_FILE`: Filename of the output results in pickle format. If not specified, the results will not be saved to a file.
|
|
||||||
- `EVAL_METRICS`: Items to be evaluated on the results. Allowed values depend on the dataset, e.g., `mIoU` is available for all dataset. Cityscapes could be evaluated by `cityscapes` as well as standard `mIoU` metrics.
|
|
||||||
- `--show`: If specified, segmentation results will be plotted on the images and shown in a new window. It is only applicable to single GPU testing and used for debugging and visualization. Please make sure that GUI is available in your environment, otherwise you may encounter the error like `cannot connect to X server`.
|
|
||||||
- `--show-dir`: If specified, segmentation results will be plotted on the images and saved to the specified directory. It is only applicable to single GPU testing and used for debugging and visualization. You do NOT need a GUI available in your environment for using this option.
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
Assume that you have already downloaded the checkpoints to the directory `checkpoints/`.
|
|
||||||
|
|
||||||
1. Test PSPNet and visualize the results. Press any key for the next image.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
|
||||||
--show
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Test PSPNet and save the painted images for latter visualization.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
|
||||||
--show-dir psp_r50_512x1024_40ki_cityscapes_results
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Test PSPNet on PASCAL VOC (without saving the test results) and evaluate the mIoU.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_20k_voc12aug.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_20k_voc12aug_20200605_003338-c57ef100.pth \
|
|
||||||
--eval mAP
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Test PSPNet with 4 GPUs, and evaluate the standard mIoU and cityscapes metric.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
|
||||||
4 --out results.pkl --eval mIoU cityscapes
|
|
||||||
```
|
|
||||||
|
|
||||||
Note: There is some gap (~0.1%) between cityscapes mIoU and our mIoU. The reason is that cityscapes average each class with class size by default.
|
|
||||||
We use the simple version without average for all datasets.
|
|
||||||
|
|
||||||
5. Test PSPNet on cityscapes test split with 4 GPUs, and generate the png files to be submit to the official evaluation server.
|
|
||||||
|
|
||||||
First, add following to config file `configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py`,
|
|
||||||
|
|
||||||
```python
|
|
||||||
data = dict(
|
|
||||||
test=dict(
|
|
||||||
img_dir='leftImg8bit/test',
|
|
||||||
ann_dir='gtFine/test'))
|
|
||||||
```
|
|
||||||
|
|
||||||
Then run test.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
|
||||||
4 --format-only --eval-options "imgfile_prefix=./pspnet_test_results"
|
|
||||||
```
|
|
||||||
|
|
||||||
You will get png files under `./pspnet_test_results` directory.
|
|
||||||
You may run `zip -r results.zip pspnet_test_results/` and submit the zip file to [evaluation server](https://www.cityscapes-dataset.com/submit/).
|
|
||||||
|
|
||||||
### Image demo
|
|
||||||
|
|
||||||
We provide a demo script to test a single image.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python demo/image_demo.py ${IMAGE_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${DEVICE_NAME}] [--palette-thr ${PALETTE}]
|
|
||||||
```
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python demo/image_demo.py demo/demo.jpg configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
|
||||||
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth --device cuda:0 --palette cityscapes
|
|
||||||
```
|
|
||||||
|
|
||||||
### High-level APIs for testing images
|
|
||||||
|
|
||||||
Here is an example of building the model and test given images.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from mmseg.apis import inference_segmentor, init_segmentor
|
|
||||||
import mmcv
|
|
||||||
|
|
||||||
config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'
|
|
||||||
checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'
|
|
||||||
|
|
||||||
# build the model from a config file and a checkpoint file
|
|
||||||
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
|
|
||||||
|
|
||||||
# test a single image and show the results
|
|
||||||
img = 'test.jpg' # or img = mmcv.imread(img), which will only load it once
|
|
||||||
result = inference_segmentor(model, img)
|
|
||||||
# visualize the results in a new window
|
|
||||||
model.show_result(img, result, show=True)
|
|
||||||
# or save the visualization results to image files
|
|
||||||
model.show_result(img, result, out_file='result.jpg')
|
|
||||||
|
|
||||||
# test a video and show the results
|
|
||||||
video = mmcv.VideoReader('video.mp4')
|
|
||||||
for frame in video:
|
|
||||||
result = inference_segmentor(model, frame)
|
|
||||||
model.show_result(frame, result, wait_time=1)
|
|
||||||
```
|
|
||||||
|
|
||||||
A notebook demo can be found in [demo/inference_demo.ipynb](../demo/inference_demo.ipynb).
|
|
||||||
|
|
||||||
## Train a model
|
|
||||||
|
|
||||||
MMSegmentation implements distributed training and non-distributed training,
|
|
||||||
which uses `MMDistributedDataParallel` and `MMDataParallel` respectively.
|
|
||||||
|
|
||||||
All outputs (log files and checkpoints) will be saved to the working directory,
|
|
||||||
which is specified by `work_dir` in the config file.
|
|
||||||
|
|
||||||
By default we evaluate the model on the validation set after some iterations, you can change the evaluation interval by adding the interval argument in the training config.
|
|
||||||
|
|
||||||
```python
|
|
||||||
evaluation = dict(interval=4000) # This evaluate the model per 4000 iterations.
|
|
||||||
```
|
|
||||||
|
|
||||||
**\*Important\***: The default learning rate in config files is for 4 GPUs and 2 img/gpu (batch size = 4x2 = 8).
|
|
||||||
Equivalently, you may also use 8 GPUs and 1 imgs/gpu since all models using cross-GPU SyncBN.
|
|
||||||
|
|
||||||
To trade speed with GPU memory, you may pass in `--options model.backbone.with_cp=True` to enable checkpoint in backbone.
|
|
||||||
|
|
||||||
### Train with a single GPU
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/train.py ${CONFIG_FILE} [optional arguments]
|
|
||||||
```
|
|
||||||
|
|
||||||
If you want to specify the working directory in the command, you can add an argument `--work-dir ${YOUR_WORK_DIR}`.
|
|
||||||
|
|
||||||
### Train with multiple GPUs
|
|
||||||
|
|
||||||
```shell
|
|
||||||
./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [optional arguments]
|
|
||||||
```
|
|
||||||
|
|
||||||
Optional arguments are:
|
|
||||||
|
|
||||||
- `--no-validate` (**not suggested**): By default, the codebase will perform evaluation at every k iterations during the training. To disable this behavior, use `--no-validate`.
|
|
||||||
- `--work-dir ${WORK_DIR}`: Override the working directory specified in the config file.
|
|
||||||
- `--resume-from ${CHECKPOINT_FILE}`: Resume from a previous checkpoint file (to continue the training process).
|
|
||||||
- `--load-from ${CHECKPOINT_FILE}`: Load weights from a checkpoint file (to start finetuning for another task).
|
|
||||||
|
|
||||||
Difference between `resume-from` and `load-from`:
|
|
||||||
|
|
||||||
- `resume-from` loads both the model weights and optimizer state including the iteration number.
|
|
||||||
- `load-from` loads only the model weights, starts the training from iteration 0.
|
|
||||||
|
|
||||||
### Train with multiple machines
|
|
||||||
|
|
||||||
If you run MMSegmentation on a cluster managed with [slurm](https://slurm.schedmd.com/), you can use the script `slurm_train.sh`. (This script also supports single machine training.)
|
|
||||||
|
|
||||||
```shell
|
|
||||||
[GPUS=${GPUS}] ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} --work-dir ${WORK_DIR}
|
|
||||||
```
|
|
||||||
|
|
||||||
Here is an example of using 16 GPUs to train PSPNet on the dev partition.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
GPUS=16 ./tools/slurm_train.sh dev pspr50 configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py /nfs/xxxx/psp_r50_512x1024_40ki_cityscapes
|
|
||||||
```
|
|
||||||
|
|
||||||
You can check [slurm_train.sh](../tools/slurm_train.sh) for full arguments and environment variables.
|
|
||||||
|
|
||||||
If you have just multiple machines connected with ethernet, you can refer to
|
|
||||||
PyTorch [launch utility](https://pytorch.org/docs/stable/distributed_deprecated.html#launch-utility).
|
|
||||||
Usually it is slow if you do not have high speed networking like InfiniBand.
|
|
||||||
|
|
||||||
### Launch multiple jobs on a single machine
|
|
||||||
|
|
||||||
If you launch multiple jobs on a single machine, e.g., 2 jobs of 4-GPU training on a machine with 8 GPUs,
|
|
||||||
you need to specify different ports (29500 by default) for each job to avoid communication conflict. Otherwise, there will be error message saying `RuntimeError: Address already in use`.
|
|
||||||
|
|
||||||
If you use `dist_train.sh` to launch training jobs, you can set the port in commands with environment variable `PORT`.
|
|
||||||
|
|
||||||
```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
|
|
||||||
```
|
|
||||||
|
|
||||||
If you use `slurm_train.sh` to launch training jobs, you can set the port in commands with environment variable `MASTER_PORT`.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
MASTER_PORT=29500 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE}
|
|
||||||
MASTER_PORT=29501 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Useful tools
|
|
||||||
|
|
||||||
We provide lots of useful tools under `tools/` directory.
|
|
||||||
|
|
||||||
### Get the FLOPs and params (experimental)
|
|
||||||
|
|
||||||
We provide a script adapted from [flops-counter.pytorch](https://github.com/sovrasov/flops-counter.pytorch) to compute the FLOPs and params of a given model.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]
|
|
||||||
```
|
|
||||||
|
|
||||||
You will get the result like this.
|
|
||||||
|
|
||||||
```none
|
|
||||||
==============================
|
|
||||||
Input shape: (3, 2048, 1024)
|
|
||||||
Flops: 1429.68 GMac
|
|
||||||
Params: 48.98 M
|
|
||||||
==============================
|
|
||||||
```
|
|
||||||
|
|
||||||
**Note**: This tool is still experimental and we do not guarantee that the number is correct. You may well use the result for simple comparisons, but double check it before you adopt it in technical reports or papers.
|
|
||||||
|
|
||||||
(1) FLOPs are related to the input shape while parameters are not. The default input shape is (1, 3, 1280, 800).
|
|
||||||
(2) Some operators are not counted into FLOPs like GN and custom operators.
|
|
||||||
|
|
||||||
### 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
|
|
||||||
(3) compute the hash of the checkpoint file and append the hash id to the filename.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}
|
|
||||||
```
|
|
||||||
|
|
||||||
E.g.,
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/publish_model.py work_dirs/pspnet/latest.pth psp_r50_hszhao_200ep.pth
|
|
||||||
```
|
|
||||||
|
|
||||||
The final output filename will be `psp_r50_512x1024_40ki_cityscapes-{hash id}.pth`.
|
|
||||||
|
|
||||||
### Convert to ONNX (experimental)
|
|
||||||
|
|
||||||
We provide a script to convert model to [ONNX](https://github.com/onnx/onnx) format. The converted model could be visualized by tools like [Netron](https://github.com/lutzroeder/netron). Besides, we also support comparing the output results between Pytorch and ONNX model.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python tools/pytorch2onnx.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FILE} --output-file ${ONNX_FILE} [--shape ${INPUT_SHAPE} --verify]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Note**: This tool is still experimental. Some customized operators are not supported for now.
|
|
||||||
|
|
||||||
## Tutorials
|
|
||||||
|
|
||||||
Currently, we provide four tutorials for users to [add new dataset](tutorials/new_dataset.md), [design data pipeline](tutorials/data_pipeline.md) and [add new modules](tutorials/new_modules.md), [use training tricks](tutorials/training_tricks.md).
|
|
||||||
We also provide a full description about the [config system](config.md).
|
|
@ -1,14 +1,31 @@
|
|||||||
Welcome to MMSegmenation's documentation!
|
Welcome to MMSegmenation's documentation!
|
||||||
=========================================
|
=======================================
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
:caption: Get Started
|
||||||
|
|
||||||
|
get_started.md
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
:caption: Dataset Preparation
|
||||||
|
|
||||||
|
dataset_prepare.md
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
:caption: Model Zoo
|
||||||
|
|
||||||
install.md
|
|
||||||
getting_started.md
|
|
||||||
config.md
|
|
||||||
modelzoo_statistics.md
|
|
||||||
model_zoo.md
|
model_zoo.md
|
||||||
|
modelzoo_statistics.md
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Quick Run
|
||||||
|
|
||||||
|
train.md
|
||||||
|
inference.md
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
@ -16,12 +33,23 @@ Welcome to MMSegmenation's documentation!
|
|||||||
|
|
||||||
tutorials/index.rst
|
tutorials/index.rst
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Useful Tools and Scripts
|
||||||
|
|
||||||
|
useful_tools.md
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Notes
|
||||||
|
|
||||||
|
changelog.md
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:caption: API Reference
|
:caption: API Reference
|
||||||
|
|
||||||
api.rst
|
api.rst
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
88
docs/inference.md
Normal file
88
docs/inference.md
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
## Inference with pretrained models
|
||||||
|
|
||||||
|
We provide testing scripts to evaluate a whole dataset (Cityscapes, PASCAL VOC, ADE20k, etc.),
|
||||||
|
and also some high-level apis for easier integration to other projects.
|
||||||
|
|
||||||
|
### 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}] [--eval ${EVAL_METRICS}] [--show]
|
||||||
|
|
||||||
|
# multi-gpu testing
|
||||||
|
./tools/dist_test.sh ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [--out ${RESULT_FILE}] [--eval ${EVAL_METRICS}]
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional arguments:
|
||||||
|
|
||||||
|
- `RESULT_FILE`: Filename of the output results in pickle format. If not specified, the results will not be saved to a file.
|
||||||
|
- `EVAL_METRICS`: Items to be evaluated on the results. Allowed values depend on the dataset, e.g., `mIoU` is available for all dataset. Cityscapes could be evaluated by `cityscapes` as well as standard `mIoU` metrics.
|
||||||
|
- `--show`: If specified, segmentation results will be plotted on the images and shown in a new window. It is only applicable to single GPU testing and used for debugging and visualization. Please make sure that GUI is available in your environment, otherwise you may encounter the error like `cannot connect to X server`.
|
||||||
|
- `--show-dir`: If specified, segmentation results will be plotted on the images and saved to the specified directory. It is only applicable to single GPU testing and used for debugging and visualization. You do NOT need a GUI available in your environment for using this option.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
Assume that you have already downloaded the checkpoints to the directory `checkpoints/`.
|
||||||
|
|
||||||
|
1. Test PSPNet and visualize the results. Press any key for the next image.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||||
|
--show
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Test PSPNet and save the painted images for latter visualization.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||||
|
--show-dir psp_r50_512x1024_40ki_cityscapes_results
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Test PSPNet on PASCAL VOC (without saving the test results) and evaluate the mIoU.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/test.py configs/pspnet/pspnet_r50-d8_512x1024_20k_voc12aug.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_20k_voc12aug_20200605_003338-c57ef100.pth \
|
||||||
|
--eval mAP
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Test PSPNet with 4 GPUs, and evaluate the standard mIoU and cityscapes metric.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||||
|
4 --out results.pkl --eval mIoU cityscapes
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: There is some gap (~0.1%) between cityscapes mIoU and our mIoU. The reason is that cityscapes average each class with class size by default.
|
||||||
|
We use the simple version without average for all datasets.
|
||||||
|
|
||||||
|
5. Test PSPNet on cityscapes test split with 4 GPUs, and generate the png files to be submit to the official evaluation server.
|
||||||
|
|
||||||
|
First, add following to config file `configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py`,
|
||||||
|
|
||||||
|
```python
|
||||||
|
data = dict(
|
||||||
|
test=dict(
|
||||||
|
img_dir='leftImg8bit/test',
|
||||||
|
ann_dir='gtFine/test'))
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run test.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./tools/dist_test.sh configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
|
||||||
|
checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
|
||||||
|
4 --format-only --eval-options "imgfile_prefix=./pspnet_test_results"
|
||||||
|
```
|
||||||
|
|
||||||
|
You will get png files under `./pspnet_test_results` directory.
|
||||||
|
You may run `zip -r results.zip pspnet_test_results/` and submit the zip file to [evaluation server](https://www.cityscapes-dataset.com/submit/).
|
83
docs/train.md
Normal file
83
docs/train.md
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
## Train a model
|
||||||
|
|
||||||
|
MMSegmentation implements distributed training and non-distributed training,
|
||||||
|
which uses `MMDistributedDataParallel` and `MMDataParallel` respectively.
|
||||||
|
|
||||||
|
All outputs (log files and checkpoints) will be saved to the working directory,
|
||||||
|
which is specified by `work_dir` in the config file.
|
||||||
|
|
||||||
|
By default we evaluate the model on the validation set after some iterations, you can change the evaluation interval by adding the interval argument in the training config.
|
||||||
|
|
||||||
|
```python
|
||||||
|
evaluation = dict(interval=4000) # This evaluate the model per 4000 iterations.
|
||||||
|
```
|
||||||
|
|
||||||
|
**\*Important\***: The default learning rate in config files is for 4 GPUs and 2 img/gpu (batch size = 4x2 = 8).
|
||||||
|
Equivalently, you may also use 8 GPUs and 1 imgs/gpu since all models using cross-GPU SyncBN.
|
||||||
|
|
||||||
|
To trade speed with GPU memory, you may pass in `--options model.backbone.with_cp=True` to enable checkpoint in backbone.
|
||||||
|
|
||||||
|
### Train with a single GPU
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/train.py ${CONFIG_FILE} [optional arguments]
|
||||||
|
```
|
||||||
|
|
||||||
|
If you want to specify the working directory in the command, you can add an argument `--work-dir ${YOUR_WORK_DIR}`.
|
||||||
|
|
||||||
|
### Train with multiple GPUs
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./tools/dist_train.sh ${CONFIG_FILE} ${GPU_NUM} [optional arguments]
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional arguments are:
|
||||||
|
|
||||||
|
- `--no-validate` (**not suggested**): By default, the codebase will perform evaluation at every k iterations during the training. To disable this behavior, use `--no-validate`.
|
||||||
|
- `--work-dir ${WORK_DIR}`: Override the working directory specified in the config file.
|
||||||
|
- `--resume-from ${CHECKPOINT_FILE}`: Resume from a previous checkpoint file (to continue the training process).
|
||||||
|
- `--load-from ${CHECKPOINT_FILE}`: Load weights from a checkpoint file (to start finetuning for another task).
|
||||||
|
|
||||||
|
Difference between `resume-from` and `load-from`:
|
||||||
|
|
||||||
|
- `resume-from` loads both the model weights and optimizer state including the iteration number.
|
||||||
|
- `load-from` loads only the model weights, starts the training from iteration 0.
|
||||||
|
|
||||||
|
### Train with multiple machines
|
||||||
|
|
||||||
|
If you run MMSegmentation on a cluster managed with [slurm](https://slurm.schedmd.com/), you can use the script `slurm_train.sh`. (This script also supports single machine training.)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
[GPUS=${GPUS}] ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} --work-dir ${WORK_DIR}
|
||||||
|
```
|
||||||
|
|
||||||
|
Here is an example of using 16 GPUs to train PSPNet on the dev partition.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
GPUS=16 ./tools/slurm_train.sh dev pspr50 configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py /nfs/xxxx/psp_r50_512x1024_40ki_cityscapes
|
||||||
|
```
|
||||||
|
|
||||||
|
You can check [slurm_train.sh](../tools/slurm_train.sh) for full arguments and environment variables.
|
||||||
|
|
||||||
|
If you have just multiple machines connected with ethernet, you can refer to
|
||||||
|
PyTorch [launch utility](https://pytorch.org/docs/stable/distributed_deprecated.html#launch-utility).
|
||||||
|
Usually it is slow if you do not have high speed networking like InfiniBand.
|
||||||
|
|
||||||
|
### Launch multiple jobs on a single machine
|
||||||
|
|
||||||
|
If you launch multiple jobs on a single machine, e.g., 2 jobs of 4-GPU training on a machine with 8 GPUs,
|
||||||
|
you need to specify different ports (29500 by default) for each job to avoid communication conflict. Otherwise, there will be error message saying `RuntimeError: Address already in use`.
|
||||||
|
|
||||||
|
If you use `dist_train.sh` to launch training jobs, you can set the port in commands with environment variable `PORT`.
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
If you use `slurm_train.sh` to launch training jobs, you can set the port in commands with environment variable `MASTER_PORT`.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
MASTER_PORT=29500 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE}
|
||||||
|
MASTER_PORT=29501 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE}
|
||||||
|
```
|
@ -1,4 +1,4 @@
|
|||||||
# Config System
|
# Tutorial 1: Learn about Configs
|
||||||
|
|
||||||
We incorporate modular and inheritance design into our config system, which is convenient to conduct various experiments.
|
We incorporate modular and inheritance design into our config system, which is convenient to conduct various experiments.
|
||||||
If you wish to inspect the config file, you may run `python tools/print_config.py /PATH/TO/CONFIG` to see the complete config.
|
If you wish to inspect the config file, you may run `python tools/print_config.py /PATH/TO/CONFIG` to see the complete config.
|
@ -1,4 +1,4 @@
|
|||||||
# 1. Adding New Dataset
|
# Tutorial 2: Customize Datasets
|
||||||
|
|
||||||
## Customize datasets by reorganizing data
|
## Customize datasets by reorganizing data
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
# 3. Adding New Modules
|
# Tutorial 4: Customize Models
|
||||||
|
|
||||||
## Customize optimizer
|
## Customize optimizer
|
||||||
|
|
243
docs/tutorials/customize_runtime.md
Normal file
243
docs/tutorials/customize_runtime.md
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
# Tutorial 6: Customize Runtime Settings
|
||||||
|
|
||||||
|
## Customize optimization settings
|
||||||
|
|
||||||
|
### Customize optimizer supported by Pytorch
|
||||||
|
|
||||||
|
We already support to use all the optimizers implemented by PyTorch, and the only modification is to change the `optimizer` field of config files.
|
||||||
|
For example, if you want to use `ADAM` (note that the performance could drop a lot), the modification could be as the following.
|
||||||
|
|
||||||
|
```python
|
||||||
|
optimizer = dict(type='Adam', lr=0.0003, weight_decay=0.0001)
|
||||||
|
```
|
||||||
|
|
||||||
|
To modify the learning rate of the model, the users only need to modify the `lr` in the config of optimizer. The users can directly set arguments following the [API doc](https://pytorch.org/docs/stable/optim.html?highlight=optim#module-torch.optim) of PyTorch.
|
||||||
|
|
||||||
|
### Customize self-implemented optimizer
|
||||||
|
|
||||||
|
#### 1. Define a new optimizer
|
||||||
|
|
||||||
|
A customized optimizer could be defined as following.
|
||||||
|
|
||||||
|
Assume you want to add a optimizer named `MyOptimizer`, which has arguments `a`, `b`, and `c`.
|
||||||
|
You need to create a new directory named `mmseg/core/optimizer`.
|
||||||
|
And then implement the new optimizer in a file, e.g., in `mmseg/core/optimizer/my_optimizer.py`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from .registry import OPTIMIZERS
|
||||||
|
from torch.optim import Optimizer
|
||||||
|
|
||||||
|
|
||||||
|
@OPTIMIZERS.register_module()
|
||||||
|
class MyOptimizer(Optimizer):
|
||||||
|
|
||||||
|
def __init__(self, a, b, c)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. Add the optimizer to registry
|
||||||
|
|
||||||
|
To find the above module defined above, this module should be imported into the main namespace at first. There are two options to achieve it.
|
||||||
|
|
||||||
|
- Modify `mmseg/core/optimizer/__init__.py` to import it.
|
||||||
|
|
||||||
|
The newly defined module should be imported in `mmseg/core/optimizer/__init__.py` so that the registry will
|
||||||
|
find the new module and add it:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from .my_optimizer import MyOptimizer
|
||||||
|
```
|
||||||
|
|
||||||
|
- Use `custom_imports` in the config to manually import it
|
||||||
|
|
||||||
|
```python
|
||||||
|
custom_imports = dict(imports=['mmseg.core.optimizer.my_optimizer'], allow_failed_imports=False)
|
||||||
|
```
|
||||||
|
|
||||||
|
The module `mmseg.core.optimizer.my_optimizer` will be imported at the beginning of the program and the class `MyOptimizer` is then automatically registered.
|
||||||
|
Note that only the package containing the class `MyOptimizer` should be imported.
|
||||||
|
`mmseg.core.optimizer.my_optimizer.MyOptimizer` **cannot** be imported directly.
|
||||||
|
|
||||||
|
Actually users can use a totally different file directory structure using this importing method, as long as the module root can be located in `PYTHONPATH`.
|
||||||
|
|
||||||
|
#### 3. Specify the optimizer in the config file
|
||||||
|
|
||||||
|
Then you can use `MyOptimizer` in `optimizer` field of config files.
|
||||||
|
In the configs, the optimizers are defined by the field `optimizer` like the following:
|
||||||
|
|
||||||
|
```python
|
||||||
|
optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001)
|
||||||
|
```
|
||||||
|
|
||||||
|
To use your own optimizer, the field can be changed to
|
||||||
|
|
||||||
|
```python
|
||||||
|
optimizer = dict(type='MyOptimizer', a=a_value, b=b_value, c=c_value)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize optimizer constructor
|
||||||
|
|
||||||
|
Some models may have some parameter-specific settings for optimization, e.g. weight decay for BatchNorm layers.
|
||||||
|
The users can do those fine-grained parameter tuning through customizing optimizer constructor.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from mmcv.utils import build_from_cfg
|
||||||
|
|
||||||
|
from mmcv.runner.optimizer import OPTIMIZER_BUILDERS, OPTIMIZERS
|
||||||
|
from mmseg.utils import get_root_logger
|
||||||
|
from .my_optimizer import MyOptimizer
|
||||||
|
|
||||||
|
|
||||||
|
@OPTIMIZER_BUILDERS.register_module()
|
||||||
|
class MyOptimizerConstructor(object):
|
||||||
|
|
||||||
|
def __init__(self, optimizer_cfg, paramwise_cfg=None):
|
||||||
|
|
||||||
|
def __call__(self, model):
|
||||||
|
|
||||||
|
return my_optimizer
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The default optimizer constructor is implemented [here](https://github.com/open-mmlab/mmcv/blob/9ecd6b0d5ff9d2172c49a182eaa669e9f27bb8e7/mmcv/runner/optimizer/default_constructor.py#L11), which could also serve as a template for new optimizer constructor.
|
||||||
|
|
||||||
|
### Additional settings
|
||||||
|
|
||||||
|
Tricks not implemented by the optimizer should be implemented through optimizer constructor (e.g., set parameter-wise learning rates) or hooks. We list some common settings that could stabilize the training or accelerate the training. Feel free to create PR, issue for more settings.
|
||||||
|
|
||||||
|
- __Use gradient clip to stabilize training__:
|
||||||
|
Some models need gradient clip to clip the gradients to stabilize the training process. An example is as below:
|
||||||
|
|
||||||
|
```python
|
||||||
|
optimizer_config = dict(
|
||||||
|
_delete_=True, grad_clip=dict(max_norm=35, norm_type=2))
|
||||||
|
```
|
||||||
|
|
||||||
|
If your config inherits the base config which already sets the `optimizer_config`, you might need `_delete_=True` to overide the unnecessary settings. See the [config documenetation](https://mmsegmentation.readthedocs.io/en/latest/config.html) for more details.
|
||||||
|
|
||||||
|
- __Use momentum schedule to accelerate model convergence__:
|
||||||
|
We support momentum scheduler to modify model's momentum according to learning rate, which could make the model converge in a faster way.
|
||||||
|
Momentum scheduler is usually used with LR scheduler, for example, the following config is used in 3D detection to accelerate convergence.
|
||||||
|
For more details, please refer to the implementation of [CyclicLrUpdater](https://github.com/open-mmlab/mmcv/blob/f48241a65aebfe07db122e9db320c31b685dc674/mmcv/runner/hooks/lr_updater.py#L327) and [CyclicMomentumUpdater](https://github.com/open-mmlab/mmcv/blob/f48241a65aebfe07db122e9db320c31b685dc674/mmcv/runner/hooks/momentum_updater.py#L130).
|
||||||
|
|
||||||
|
```python
|
||||||
|
lr_config = dict(
|
||||||
|
policy='cyclic',
|
||||||
|
target_ratio=(10, 1e-4),
|
||||||
|
cyclic_times=1,
|
||||||
|
step_ratio_up=0.4,
|
||||||
|
)
|
||||||
|
momentum_config = dict(
|
||||||
|
policy='cyclic',
|
||||||
|
target_ratio=(0.85 / 0.95, 1),
|
||||||
|
cyclic_times=1,
|
||||||
|
step_ratio_up=0.4,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Customize training schedules
|
||||||
|
|
||||||
|
By default we use step learning rate with 40k/80k schedule, this calls [`PolyLrUpdaterHook`](https://github.com/open-mmlab/mmcv/blob/826d3a7b68596c824fa1e2cb89b6ac274f52179c/mmcv/runner/hooks/lr_updater.py#L196) in MMCV.
|
||||||
|
We support many other learning rate schedule [here](https://github.com/open-mmlab/mmcv/blob/master/mmcv/runner/hooks/lr_updater.py), such as `CosineAnnealing` and `Poly` schedule. Here are some examples
|
||||||
|
|
||||||
|
- Step schedule:
|
||||||
|
|
||||||
|
```python
|
||||||
|
lr_config = dict(policy='step', step=[9, 10])
|
||||||
|
```
|
||||||
|
|
||||||
|
- ConsineAnnealing schedule:
|
||||||
|
|
||||||
|
```python
|
||||||
|
lr_config = dict(
|
||||||
|
policy='CosineAnnealing',
|
||||||
|
warmup='linear',
|
||||||
|
warmup_iters=1000,
|
||||||
|
warmup_ratio=1.0 / 10,
|
||||||
|
min_lr_ratio=1e-5)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Customize workflow
|
||||||
|
|
||||||
|
Workflow is a list of (phase, epochs) to specify the running order and epochs.
|
||||||
|
By default it is set to be
|
||||||
|
|
||||||
|
```python
|
||||||
|
workflow = [('train', 1)]
|
||||||
|
```
|
||||||
|
|
||||||
|
which means running 1 epoch for training.
|
||||||
|
Sometimes user may want to check some metrics (e.g. loss, accuracy) about the model on the validate set.
|
||||||
|
In such case, we can set the workflow as
|
||||||
|
|
||||||
|
```python
|
||||||
|
[('train', 1), ('val', 1)]
|
||||||
|
```
|
||||||
|
|
||||||
|
so that 1 epoch for training and 1 epoch for validation will be run iteratively.
|
||||||
|
|
||||||
|
**Note**:
|
||||||
|
|
||||||
|
1. The parameters of model will not be updated during val epoch.
|
||||||
|
2. Keyword `total_epochs` in the config only controls the number of training epochs and will not affect the validation workflow.
|
||||||
|
3. Workflows `[('train', 1), ('val', 1)]` and `[('train', 1)]` will not change the behavior of `EvalHook` because `EvalHook` is called by `after_train_epoch` and validation workflow only affect hooks that are called through `after_val_epoch`. Therefore, the only difference between `[('train', 1), ('val', 1)]` and `[('train', 1)]` is that the runner will calculate losses on validation set after each training epoch.
|
||||||
|
|
||||||
|
## Customize hooks
|
||||||
|
|
||||||
|
### Use hooks implemented in MMCV
|
||||||
|
|
||||||
|
If the hook is already implemented in MMCV, you can directly modify the config to use the hook as below
|
||||||
|
|
||||||
|
```python
|
||||||
|
custom_hooks = [
|
||||||
|
dict(type='MyHook', a=a_value, b=b_value, priority='NORMAL')
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Modify default runtime hooks
|
||||||
|
|
||||||
|
There are some common hooks that are not registerd through `custom_hooks`, they are
|
||||||
|
|
||||||
|
- log_config
|
||||||
|
- checkpoint_config
|
||||||
|
- evaluation
|
||||||
|
- lr_config
|
||||||
|
- optimizer_config
|
||||||
|
- momentum_config
|
||||||
|
|
||||||
|
In those hooks, only the logger hook has the `VERY_LOW` priority, others' priority are `NORMAL`.
|
||||||
|
The above-mentioned tutorials already covers how to modify `optimizer_config`, `momentum_config`, and `lr_config`.
|
||||||
|
Here we reveals how what we can do with `log_config`, `checkpoint_config`, and `evaluation`.
|
||||||
|
|
||||||
|
#### Checkpoint config
|
||||||
|
|
||||||
|
The MMCV runner will use `checkpoint_config` to initialize [`CheckpointHook`](https://github.com/open-mmlab/mmcv/blob/9ecd6b0d5ff9d2172c49a182eaa669e9f27bb8e7/mmcv/runner/hooks/checkpoint.py#L9).
|
||||||
|
|
||||||
|
```python
|
||||||
|
checkpoint_config = dict(interval=1)
|
||||||
|
```
|
||||||
|
|
||||||
|
The users could set `max_keep_ckpts` to only save only small number of checkpoints or decide whether to store state dict of optimizer by `save_optimizer`. More details of the arguments are [here](https://mmcv.readthedocs.io/en/latest/api.html#mmcv.runner.CheckpointHook)
|
||||||
|
|
||||||
|
#### Log config
|
||||||
|
|
||||||
|
The `log_config` wraps multiple logger hooks and enables to set intervals. Now MMCV supports `WandbLoggerHook`, `MlflowLoggerHook`, and `TensorboardLoggerHook`.
|
||||||
|
The detail usages can be found in the [doc](https://mmcv.readthedocs.io/en/latest/api.html#mmcv.runner.LoggerHook).
|
||||||
|
|
||||||
|
```python
|
||||||
|
log_config = dict(
|
||||||
|
interval=50,
|
||||||
|
hooks=[
|
||||||
|
dict(type='TextLoggerHook'),
|
||||||
|
dict(type='TensorboardLoggerHook')
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Evaluation config
|
||||||
|
|
||||||
|
The config of `evaluation` will be used to initialize the [`EvalHook`](https://github.com/open-mmlab/mmsegmentation/blob/e3f6f655d69b777341aec2fe8829871cc0beadcb/mmseg/core/evaluation/eval_hooks.py#L7).
|
||||||
|
Except the key `interval`, other arguments such as `metric` will be passed to the `dataset.evaluate()`
|
||||||
|
|
||||||
|
```python
|
||||||
|
evaluation = dict(interval=1, metric='mIoU')
|
||||||
|
```
|
@ -1,4 +1,4 @@
|
|||||||
# 2. Custom Data Pipelines
|
# Tutorial 3: Customize Data Pipelines
|
||||||
|
|
||||||
## Design of Data pipelines
|
## Design of Data pipelines
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
new_dataset.md
|
config.md
|
||||||
|
customize_datasets.md
|
||||||
data_pipeline.md
|
data_pipeline.md
|
||||||
new_modules.md
|
customize_models.md
|
||||||
training_tricks.md
|
training_tricks.md
|
||||||
|
customize_runtime.md
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# 4. Training Tricks
|
# Tutorial 6: Training Tricks
|
||||||
|
|
||||||
MMSegmentation support following training tricks out of box.
|
MMSegmentation support following training tricks out of box.
|
||||||
|
|
||||||
|
64
docs/useful_tools.md
Normal file
64
docs/useful_tools.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
Apart from training/testing scripts, We provide lots of useful tools under the
|
||||||
|
`tools/` directory.
|
||||||
|
|
||||||
|
### Get the FLOPs and params (experimental)
|
||||||
|
|
||||||
|
We provide a script adapted from [flops-counter.pytorch](https://github.com/sovrasov/flops-counter.pytorch) to compute the FLOPs and params of a given model.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]
|
||||||
|
```
|
||||||
|
|
||||||
|
You will get the result like this.
|
||||||
|
|
||||||
|
```none
|
||||||
|
==============================
|
||||||
|
Input shape: (3, 2048, 1024)
|
||||||
|
Flops: 1429.68 GMac
|
||||||
|
Params: 48.98 M
|
||||||
|
==============================
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: This tool is still experimental and we do not guarantee that the number is correct. You may well use the result for simple comparisons, but double check it before you adopt it in technical reports or papers.
|
||||||
|
|
||||||
|
(1) FLOPs are related to the input shape while parameters are not. The default input shape is (1, 3, 1280, 800).
|
||||||
|
(2) Some operators are not counted into FLOPs like GN and custom operators.
|
||||||
|
|
||||||
|
### 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
|
||||||
|
(3) compute the hash of the checkpoint file and append the hash id to the filename.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}
|
||||||
|
```
|
||||||
|
|
||||||
|
E.g.,
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/publish_model.py work_dirs/pspnet/latest.pth psp_r50_hszhao_200ep.pth
|
||||||
|
```
|
||||||
|
|
||||||
|
The final output filename will be `psp_r50_512x1024_40ki_cityscapes-{hash id}.pth`.
|
||||||
|
|
||||||
|
### Convert to ONNX (experimental)
|
||||||
|
|
||||||
|
We provide a script to convert model to [ONNX](https://github.com/onnx/onnx) format. The converted model could be visualized by tools like [Netron](https://github.com/lutzroeder/netron). Besides, we also support comparing the output results between Pytorch and ONNX model.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/pytorch2onnx.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FILE} --output-file ${ONNX_FILE} [--shape ${INPUT_SHAPE} --verify]
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: This tool is still experimental. Some customized operators are not supported for now.
|
||||||
|
|
||||||
|
## Miscellaneous
|
||||||
|
|
||||||
|
### Print the entire config
|
||||||
|
|
||||||
|
`tools/print_config.py` prints the whole config verbatim, expanding all its
|
||||||
|
imports.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
python tools/print_config.py ${CONFIG} [-h] [--options ${OPTIONS [OPTIONS...]}]
|
||||||
|
```
|
@ -36,7 +36,7 @@ def generate_labels(img_id, detail, out_dir):
|
|||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Convert PASCAL VOC annotations to mmdetection format')
|
description='Convert PASCAL VOC annotations to mmsegmentation format')
|
||||||
parser.add_argument('devkit_path', help='pascal voc devkit path')
|
parser.add_argument('devkit_path', help='pascal voc devkit path')
|
||||||
parser.add_argument('json_path', help='annoation json filepath')
|
parser.add_argument('json_path', help='annoation json filepath')
|
||||||
parser.add_argument('-o', '--out_dir', help='output path')
|
parser.add_argument('-o', '--out_dir', help='output path')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user