Skip to content

Commit d487dd8

Browse files
MengzhangLIMeowZheng
authored andcommitted
[Feature] Support MaskFormer(NeurIPS'2021) in MMSeg 1.x (open-mmlab#2215)
* [Feature] Support MaskFormer(NeurIPS'2021) in MMSeg 1.x * add mmdet try except logic * refactor config files * add readme * fix config * update models & logs * add MMDET installation and fix info * fix comments * fix * fix config norm optimizer setting * update models & logs & unittest * add docstring of MaskFormerHead * wait for mmdet 3.0.0rc4 * replace seg_mask with seg_logits & add docstring for batch_input_shape * use mmdet3.0.0rc4 * fix readme and modify config comments * add mmdet installation in pr_stage_test.yml * update mmcv version in pr_stage_test.yml * add mmdet in build_cpu of pr_stage_test.yml * modify mmdet& mmcv installation in merge_stage_test.yml * fix typo * update test.yml * update test.yml
1 parent 45a2c03 commit d487dd8

16 files changed

+724
-11
lines changed

.circleci/test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ jobs:
6161
command: |
6262
pip install git+https://github.com/open-mmlab/mmengine.git@main
6363
pip install -U openmim
64-
mim install 'mmcv>=2.0.0rc1'
64+
mim install 'mmcv>=2.0.0rc3'
6565
pip install git+https://github.com/open-mmlab/mmclassification@dev-1.x
66+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
6667
pip install -r requirements/tests.txt -r requirements/optional.txt
6768
- run:
6869
name: Build and install
@@ -96,18 +97,20 @@ jobs:
9697
command: |
9798
git clone -b main --depth 1 https://github.com/open-mmlab/mmengine.git /home/circleci/mmengine
9899
git clone -b dev-1.x --depth 1 https://github.com/open-mmlab/mmclassification.git /home/circleci/mmclassification
100+
git clone -b dev-3.x --depth 1 https://github.com/open-mmlab/mmdetection.git /home/circleci/mmdetection
99101
- run:
100102
name: Build Docker image
101103
command: |
102104
docker build .circleci/docker -t mmseg:gpu --build-arg PYTORCH=<< parameters.torch >> --build-arg CUDA=<< parameters.cuda >> --build-arg CUDNN=<< parameters.cudnn >>
103-
docker run --gpus all -t -d -v /home/circleci/project:/mmseg -v /home/circleci/mmengine:/mmengine -v /home/circleci/mmclassification:/mmclassification -w /mmseg --name mmseg mmseg:gpu
105+
docker run --gpus all -t -d -v /home/circleci/project:/mmseg -v /home/circleci/mmengine:/mmengine -v /home/circleci/mmclassification:/mmclassification -v /home/circleci/mmdetection:/mmdetection -w /mmseg --name mmseg mmseg:gpu
104106
- run:
105107
name: Install mmseg dependencies
106108
command: |
107109
docker exec mmseg pip install -e /mmengine
108110
docker exec mmseg pip install -U openmim
109-
docker exec mmseg mim install 'mmcv>=2.0.0rc1'
111+
docker exec mmseg mim install 'mmcv>=2.0.0rc3'
110112
docker exec mmseg pip install -e /mmclassification
113+
docker exec mmseg pip install -e /mmdetection
111114
docker exec mmseg pip install -r requirements/tests.txt -r requirements/optional.txt
112115
- run:
113116
name: Build and install

.github/workflows/merge_stage_test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ jobs:
4444
python -V
4545
pip install -U openmim
4646
pip install git+https://github.com/open-mmlab/mmengine.git
47-
mim install 'mmcv>=2.0.0rc1'
47+
mim install 'mmcv>=2.0.0rc3'
4848
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
49+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
4950
- name: Install unittest dependencies
5051
run: pip install -r requirements/tests.txt -r requirements/optional.txt
5152
- name: Build and install
@@ -92,8 +93,9 @@ jobs:
9293
python -V
9394
pip install -U openmim
9495
pip install git+https://github.com/open-mmlab/mmengine.git
95-
mim install 'mmcv>=2.0.0rc1'
96+
mim install 'mmcv>=2.0.0rc3'
9697
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
98+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
9799
- name: Install unittest dependencies
98100
run: pip install -r requirements/tests.txt -r requirements/optional.txt
99101
- name: Build and install
@@ -155,8 +157,9 @@ jobs:
155157
python -V
156158
pip install -U openmim
157159
pip install git+https://github.com/open-mmlab/mmengine.git
158-
mim install 'mmcv>=2.0.0rc1'
160+
mim install 'mmcv>=2.0.0rc3'
159161
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
162+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
160163
- name: Install unittest dependencies
161164
run: pip install -r requirements/tests.txt -r requirements/optional.txt
162165
- name: Build and install
@@ -187,8 +190,9 @@ jobs:
187190
python -V
188191
pip install -U openmim
189192
pip install git+https://github.com/open-mmlab/mmengine.git
190-
mim install 'mmcv>=2.0.0rc1'
193+
mim install 'mmcv>=2.0.0rc3'
191194
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
195+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
192196
- name: Install unittest dependencies
193197
run: pip install -r requirements/tests.txt -r requirements/optional.txt
194198
- name: Build and install

.github/workflows/pr_stage_test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ jobs:
4040
run: |
4141
pip install -U openmim
4242
pip install git+https://github.com/open-mmlab/mmengine.git
43-
mim install 'mmcv>=2.0.0rc1'
43+
mim install 'mmcv>=2.0.0rc3'
4444
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
45+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
4546
- name: Install unittest dependencies
4647
run: pip install -r requirements/tests.txt -r requirements/optional.txt
4748
- name: Build and install
@@ -92,8 +93,9 @@ jobs:
9293
python -V
9394
pip install -U openmim
9495
pip install git+https://github.com/open-mmlab/mmengine.git
95-
mim install 'mmcv>=2.0.0rc1'
96+
mim install 'mmcv>=2.0.0rc3'
9697
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
98+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
9799
- name: Install unittest dependencies
98100
run: pip install -r requirements/tests.txt -r requirements/optional.txt
99101
- name: Build and install
@@ -124,8 +126,9 @@ jobs:
124126
python -V
125127
pip install -U openmim
126128
pip install git+https://github.com/open-mmlab/mmengine.git
127-
mim install 'mmcv>=2.0.0rc1'
129+
mim install 'mmcv>=2.0.0rc3'
128130
pip install git+https://github.com/open-mmlab/mmclassification.git@dev-1.x
131+
pip install git+https://github.com/open-mmlab/mmdetection.git@dev-3.x
129132
- name: Install unittest dependencies
130133
run: pip install -r requirements/tests.txt -r requirements/optional.txt
131134
- name: Build and install

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Supported methods:
139139
- [x] [Segmenter (ICCV'2021)](configs/segmenter)
140140
- [x] [SegFormer (NeurIPS'2021)](configs/segformer)
141141
- [x] [K-Net (NeurIPS'2021)](configs/knet)
142+
- [x] [MaskFormer (NeurIPS'2021)](configs/maskformer)
142143

143144
Supported datasets:
144145

README_zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ MMSegmentation 是一个基于 PyTorch 的语义分割开源工具箱。它是 O
134134
- [x] [Segmenter (ICCV'2021)](configs/segmenter)
135135
- [x] [SegFormer (NeurIPS'2021)](configs/segformer)
136136
- [x] [K-Net (NeurIPS'2021)](configs/knet)
137+
- [x] [MaskFormer (NeurIPS'2021)](configs/maskformer)
137138

138139
已支持的数据集:
139140

configs/maskformer/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# MaskFormer
2+
3+
[MaskFormer: Per-Pixel Classification is Not All You Need for Semantic Segmentation](https://arxiv.org/abs/2107.06278)
4+
5+
## Introduction
6+
7+
<!-- [ALGORITHM] -->
8+
9+
<a href="https://github.com/facebookresearch/MaskFormer/">Official Repo</a>
10+
11+
<a href="https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/models/dense_heads/maskformer_head.py#L21">Code Snippet</a>
12+
13+
## Abstract
14+
15+
<!-- [ABSTRACT] -->
16+
17+
Modern approaches typically formulate semantic segmentation as a per-pixel classification task, while instance-level segmentation is handled with an alternative mask classification. Our key insight: mask classification is sufficiently general to solve both semantic- and instance-level segmentation tasks in a unified manner using the exact same model, loss, and training procedure. Following this observation, we propose MaskFormer, a simple mask classification model which predicts a set of binary masks, each associated with a single global class label prediction. Overall, the proposed mask classification-based method simplifies the landscape of effective approaches to semantic and panoptic segmentation tasks and shows excellent empirical results. In particular, we observe that MaskFormer outperforms per-pixel classification baselines when the number of classes is large. Our mask classification-based method outperforms both current state-of-the-art semantic (55.6 mIoU on ADE20K) and panoptic segmentation (52.7 PQ on COCO) models.
18+
19+
<!-- [IMAGE] -->
20+
21+
<div align=center>
22+
<img src="https://user-images.githubusercontent.com/24582831/199215459-ea507126-aafe-4823-8eb1-ae6487509d5c.png" width="90%"/>
23+
</div>
24+
25+
```bibtex
26+
@article{cheng2021per,
27+
title={Per-pixel classification is not all you need for semantic segmentation},
28+
author={Cheng, Bowen and Schwing, Alex and Kirillov, Alexander},
29+
journal={Advances in Neural Information Processing Systems},
30+
volume={34},
31+
pages={17864--17875},
32+
year={2021}
33+
}
34+
```
35+
36+
### Usage
37+
38+
- MaskFormer model needs to install [MMDetection](https://github.com/open-mmlab/mmdetection) first.
39+
40+
```shell
41+
pip install "mmdet>=3.0.0rc4"
42+
```
43+
44+
## Results and models
45+
46+
### ADE20K
47+
48+
| Method | Backbone | Crop Size | Lr schd | Mem (GB) | Inf time (fps) | mIoU | mIoU(ms+flip) | config | download |
49+
| ---------- | --------- | --------- | ------- | -------- | -------------- | ----- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
50+
| MaskFormer | R-50-D32 | 512x512 | 160000 | 3.29 | 42.20 | 44.29 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/configs/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512/maskformer_r50-d32_8xb2-160k_ade20k-512x512_20221030_182724-cbd39cc1.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512/maskformer_r50-d32_8xb2-160k_ade20k-512x512_20221030_182724.json) |
51+
| MaskFormer | R-101-D32 | 512x512 | 160000 | 4.12 | 34.90 | 45.11 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/configs/maskformer/maskformer_r101-d32_8xb2-160k_ade20k-512x512.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r101-d32_8xb2-160k_ade20k-512x512/maskformer_r101-d32_8xb2-160k_ade20k-512x512_20221031_223053-c8e0931d.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r101-d32_8xb2-160k_ade20k-512x512/maskformer_r101-d32_8xb2-160k_ade20k-512x512_20221031_223053.json) |
52+
| MaskFormer | Swin-T | 512x512 | 160000 | 3.73 | 40.53 | 46.69 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/configs/maskformer/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512_20221114_232813-03550716.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512_20221114_232813.json) |
53+
| MaskFormer | Swin-S | 512x512 | 160000 | 5.33 | 26.98 | 49.36 | - | [config](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/configs/maskformer/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512_20221115_114710-5ab67e58.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512_20221115_114710.json) |
54+
55+
Note:
56+
57+
- All experiments of MaskFormer are implemented with 8 V100 (32G) GPUs with 2 samplers per GPU.
58+
- The results of MaskFormer are relatively not stable. The accuracy (mIoU) of model with `R-101-D32` is from 44.7 to 46.0, and with `Swin-S` is from 49.0 to 49.8.
59+
- The ResNet backbones utilized in MaskFormer models are standard `ResNet` rather than `ResNetV1c`.
60+
- Test time augmentation is not supported in MMSegmentation 1.x version yet, we would add "ms+flip" results as soon as possible.

configs/maskformer/maskformer.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Collections:
2+
- Name: MaskFormer
3+
Metadata:
4+
Training Data:
5+
- Usage
6+
- ADE20K
7+
Paper:
8+
URL: https://arxiv.org/abs/2107.06278
9+
Title: 'MaskFormer: Per-Pixel Classification is Not All You Need for Semantic
10+
Segmentation'
11+
README: configs/maskformer/README.md
12+
Code:
13+
URL: https://github.com/open-mmlab/mmdetection/blob/dev-3.x/mmdet/models/dense_heads/maskformer_head.py#L21
14+
Version: dev-3.x
15+
Converted From:
16+
Code: https://github.com/facebookresearch/MaskFormer/
17+
Models:
18+
- Name: maskformer_r50-d32_8xb2-160k_ade20k-512x512
19+
In Collection: MaskFormer
20+
Metadata:
21+
backbone: R-50-D32
22+
crop size: (512,512)
23+
lr schd: 160000
24+
inference time (ms/im):
25+
- value: 23.7
26+
hardware: V100
27+
backend: PyTorch
28+
batch size: 1
29+
mode: FP32
30+
resolution: (512,512)
31+
Training Memory (GB): 3.29
32+
Results:
33+
- Task: Semantic Segmentation
34+
Dataset: ADE20K
35+
Metrics:
36+
mIoU: 44.29
37+
Config: configs/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512.py
38+
Weights: https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512/maskformer_r50-d32_8xb2-160k_ade20k-512x512_20221030_182724-cbd39cc1.pth
39+
- Name: maskformer_r101-d32_8xb2-160k_ade20k-512x512
40+
In Collection: MaskFormer
41+
Metadata:
42+
backbone: R-101-D32
43+
crop size: (512,512)
44+
lr schd: 160000
45+
inference time (ms/im):
46+
- value: 28.65
47+
hardware: V100
48+
backend: PyTorch
49+
batch size: 1
50+
mode: FP32
51+
resolution: (512,512)
52+
Training Memory (GB): 4.12
53+
Results:
54+
- Task: Semantic Segmentation
55+
Dataset: ADE20K
56+
Metrics:
57+
mIoU: 45.11
58+
Config: configs/maskformer/maskformer_r101-d32_8xb2-160k_ade20k-512x512.py
59+
Weights: https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_r101-d32_8xb2-160k_ade20k-512x512/maskformer_r101-d32_8xb2-160k_ade20k-512x512_20221031_223053-c8e0931d.pth
60+
- Name: maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512
61+
In Collection: MaskFormer
62+
Metadata:
63+
backbone: Swin-T
64+
crop size: (512,512)
65+
lr schd: 160000
66+
inference time (ms/im):
67+
- value: 24.67
68+
hardware: V100
69+
backend: PyTorch
70+
batch size: 1
71+
mode: FP32
72+
resolution: (512,512)
73+
Training Memory (GB): 3.73
74+
Results:
75+
- Task: Semantic Segmentation
76+
Dataset: ADE20K
77+
Metrics:
78+
mIoU: 46.69
79+
Config: configs/maskformer/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512.py
80+
Weights: https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-t_upernet_8xb2-160k_ade20k-512x512_20221114_232813-03550716.pth
81+
- Name: maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512
82+
In Collection: MaskFormer
83+
Metadata:
84+
backbone: Swin-S
85+
crop size: (512,512)
86+
lr schd: 160000
87+
inference time (ms/im):
88+
- value: 37.06
89+
hardware: V100
90+
backend: PyTorch
91+
batch size: 1
92+
mode: FP32
93+
resolution: (512,512)
94+
Training Memory (GB): 5.33
95+
Results:
96+
- Task: Semantic Segmentation
97+
Dataset: ADE20K
98+
Metrics:
99+
mIoU: 49.36
100+
Config: configs/maskformer/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512.py
101+
Weights: https://download.openmmlab.com/mmsegmentation/v0.5/maskformer/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512/maskformer_swin-s_upernet_8xb2-160k_ade20k-512x512_20221115_114710-5ab67e58.pth
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_base_ = './maskformer_r50-d32_8xb2-160k_ade20k-512x512.py'
2+
3+
model = dict(
4+
backbone=dict(
5+
depth=101,
6+
init_cfg=dict(type='Pretrained',
7+
checkpoint='torchvision://resnet101')))

0 commit comments

Comments
 (0)