Skip to content

Commit d5e79fa

Browse files
authored
Merge branch 'open-mmlab:master' into custom/face_occlusion
2 parents e9e196f + 356215b commit d5e79fa

25 files changed

+406
-46
lines changed

.circleci/config.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ jobs:
6161
name: Install mmseg dependencies
6262
command: |
6363
python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cpu/torch<< parameters.torch >>/index.html
64-
python -m pip install mmdet
6564
python -m pip install -r requirements.txt
6665
- run:
6766
name: Build and install
6867
command: |
6968
python -m pip install -e .
7069
- run:
71-
name: Run unittests
70+
name: Run unittests but skip timm unittests
7271
command: |
73-
python -m pip install timm
74-
python -m coverage run --branch --source mmseg -m pytest tests/
72+
python -m coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
7573
python -m coverage xml
7674
python -m coverage report -m
7775
@@ -102,18 +100,16 @@ jobs:
102100
# python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch${{matrix.torch_version}}/index.html
103101
command: |
104102
python -m pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
105-
python -m pip install mmdet
106103
python -m pip install -r requirements.txt
107104
- run:
108105
name: Build and install
109106
command: |
110107
python setup.py check -m -s
111108
TORCH_CUDA_ARCH_LIST=7.0 python -m pip install -e .
112109
- run:
113-
name: Run unittests
110+
name: Run unittests but skip timm unittests
114111
command: |
115-
python -m pip install timm
116-
python -m pytest tests/
112+
python -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
117113
118114
workflows:
119115
unit_tests:

.github/workflows/build.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ jobs:
7070
coverage run --branch --source mmseg -m pytest tests/
7171
coverage xml
7272
coverage report -m
73-
if: ${{matrix.torch >= '1.5.0'}}
73+
# timm from v0.6.11 requires torch>=1.7
74+
if: ${{matrix.torch >= '1.7.0'}}
7475
- name: Skip timm unittests and generate coverage report
7576
run: |
7677
coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
7778
coverage xml
7879
coverage report -m
79-
if: ${{matrix.torch < '1.5.0'}}
80+
if: ${{matrix.torch < '1.7.0'}}
8081

8182
build_cuda101:
8283
runs-on: ubuntu-18.04
@@ -144,13 +145,14 @@ jobs:
144145
coverage run --branch --source mmseg -m pytest tests/
145146
coverage xml
146147
coverage report -m
147-
if: ${{matrix.torch >= '1.5.0'}}
148+
# timm from v0.6.11 requires torch>=1.7
149+
if: ${{matrix.torch >= '1.7.0'}}
148150
- name: Skip timm unittests and generate coverage report
149151
run: |
150152
coverage run --branch --source mmseg -m pytest tests/ --ignore tests/test_models/test_backbones/test_timm_backbone.py
151153
coverage xml
152154
coverage report -m
153-
if: ${{matrix.torch < '1.5.0'}}
155+
if: ${{matrix.torch < '1.7.0'}}
154156
- name: Upload coverage to Codecov
155157
uses: codecov/[email protected]
156158
with:
@@ -249,7 +251,7 @@ jobs:
249251
run: pip install -e .
250252
- name: Run unittests
251253
run: |
252-
python -m pip install timm
254+
python -m pip install 'timm<0.6.11'
253255
coverage run --branch --source mmseg -m pytest tests/
254256
- name: Generate coverage report
255257
run: |

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
repos:
22
- repo: https://gitlab.com/pycqa/flake8.git
3-
rev: 3.8.3
3+
rev: 5.0.4
44
hooks:
55
- id: flake8
66
- repo: https://github.com/PyCQA/isort
77
rev: 5.10.1
88
hooks:
99
- id: isort
1010
- repo: https://github.com/pre-commit/mirrors-yapf
11-
rev: v0.30.0
11+
rev: v0.32.0
1212
hooks:
1313
- id: yapf
1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v3.1.0
15+
rev: v4.3.0
1616
hooks:
1717
- id: trailing-whitespace
1818
- id: check-yaml
@@ -34,7 +34,7 @@ repos:
3434
- mdformat_frontmatter
3535
- linkify-it-py
3636
- repo: https://github.com/codespell-project/codespell
37-
rev: v2.1.0
37+
rev: v2.2.1
3838
hooks:
3939
- id: codespell
4040
- repo: https://github.com/myint/docformatter

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ The master branch works with **PyTorch 1.5+**.
7777

7878
### 💎 Stable version
7979

80-
v0.28.0 was released in 9/08/2022:
80+
v0.29.0 was released on 10/10/2022:
8181

82-
- Support Tversky Loss
83-
- Fix binary segmentation
82+
- Support PoolFormer (CVPR'2022)
8483

8584
Please refer to [changelog.md](docs/en/changelog.md) for details and release history.
8685

@@ -130,6 +129,7 @@ Supported backbones:
130129
- [x] [BEiT (ICLR'2022)](configs/beit)
131130
- [x] [ConvNeXt (CVPR'2022)](configs/convnext)
132131
- [x] [MAE (CVPR'2022)](configs/mae)
132+
- [x] [PoolFormer (CVPR'2022)](configs/poolformer)
133133

134134
Supported methods:
135135

README_zh-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ MMSegmentation 是一个基于 PyTorch 的语义分割开源工具箱。它是 O
7474

7575
### 💎 稳定版本
7676

77-
最新版本 v0.28.0 在 2022.9.8 发布:
77+
最新版本 v0.29.0 在 2022.10.10 发布:
7878

79-
- 支持 Tversky Loss
80-
- 修复二值分割
79+
- 支持 PoolFormer (CVPR'2022)
8180

8281
如果想了解更多版本更新细节和历史信息,请阅读[更新日志](docs/en/changelog.md)
8382

@@ -127,6 +126,7 @@ MMSegmentation 是一个基于 PyTorch 的语义分割开源工具箱。它是 O
127126
- [x] [BEiT (ICLR'2022)](configs/beit)
128127
- [x] [ConvNeXt (CVPR'2022)](configs/convnext)
129128
- [x] [MAE (CVPR'2022)](configs/mae)
129+
- [x] [PoolFormer (CVPR'2022)](configs/poolformer)
130130

131131
已支持的算法:
132132

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# model settings
2+
norm_cfg = dict(type='SyncBN', requires_grad=True)
3+
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/poolformer/poolformer-s12_3rdparty_32xb128_in1k_20220414-f8d83051.pth' # noqa
4+
custom_imports = dict(imports='mmcls.models', allow_failed_imports=False)
5+
model = dict(
6+
type='EncoderDecoder',
7+
backbone=dict(
8+
type='mmcls.PoolFormer',
9+
arch='s12',
10+
init_cfg=dict(
11+
type='Pretrained', checkpoint=checkpoint_file, prefix='backbone.'),
12+
in_patch_size=7,
13+
in_stride=4,
14+
in_pad=2,
15+
down_patch_size=3,
16+
down_stride=2,
17+
down_pad=1,
18+
drop_rate=0.,
19+
drop_path_rate=0.,
20+
out_indices=(0, 2, 4, 6),
21+
frozen_stages=0,
22+
),
23+
neck=dict(
24+
type='FPN',
25+
in_channels=[256, 512, 1024, 2048],
26+
out_channels=256,
27+
num_outs=4),
28+
decode_head=dict(
29+
type='FPNHead',
30+
in_channels=[256, 256, 256, 256],
31+
in_index=[0, 1, 2, 3],
32+
feature_strides=[4, 8, 16, 32],
33+
channels=128,
34+
dropout_ratio=0.1,
35+
num_classes=19,
36+
norm_cfg=norm_cfg,
37+
align_corners=False,
38+
loss_decode=dict(
39+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)),
40+
# model training and testing settings
41+
train_cfg=dict(),
42+
test_cfg=dict(mode='whole'))

configs/poolformer/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PoolFormer
2+
3+
[MetaFormer is Actually What You Need for Vision](https://arxiv.org/abs/2111.11418)
4+
5+
## Introduction
6+
7+
<!-- [BACKBONE] -->
8+
9+
<a href="https://github.com/sail-sg/poolformer/tree/main/segmentation">Official Repo</a>
10+
11+
<a href="https://github.com/open-mmlab/mmclassification/blob/v0.23.0/mmcls/models/backbones/poolformer.py#L198">Code Snippet</a>
12+
13+
## Abstract
14+
15+
<!-- [ABSTRACT] -->
16+
17+
Transformers have shown great potential in computer vision tasks. A common belief is their attention-based token mixer module contributes most to their competence. However, recent works show the attention-based module in transformers can be replaced by spatial MLPs and the resulted models still perform quite well. Based on this observation, we hypothesize that the general architecture of the transformers, instead of the specific token mixer module, is more essential to the model's performance. To verify this, we deliberately replace the attention module in transformers with an embarrassingly simple spatial pooling operator to conduct only the most basic token mixing. Surprisingly, we observe that the derived model, termed as PoolFormer, achieves competitive performance on multiple computer vision tasks. For example, on ImageNet-1K, PoolFormer achieves 82.1% top-1 accuracy, surpassing well-tuned vision transformer/MLP-like baselines DeiT-B/ResMLP-B24 by 0.3%/1.1% accuracy with 35%/52% fewer parameters and 48%/60% fewer MACs. The effectiveness of PoolFormer verifies our hypothesis and urges us to initiate the concept of "MetaFormer", a general architecture abstracted from transformers without specifying the token mixer. Based on the extensive experiments, we argue that MetaFormer is the key player in achieving superior results for recent transformer and MLP-like models on vision tasks. This work calls for more future research dedicated to improving MetaFormer instead of focusing on the token mixer modules. Additionally, our proposed PoolFormer could serve as a starting baseline for future MetaFormer architecture design. Code is available at [this https URL](https://github.com/sail-sg/poolformer)
18+
19+
<!-- [IMAGE] -->
20+
21+
<div align=center>
22+
<img src="https://user-images.githubusercontent.com/15921929/144710761-1635f59a-abde-4946-984c-a2c3f22a19d2.png" width="70%"/>
23+
</div>
24+
25+
## Citation
26+
27+
```bibtex
28+
@inproceedings{yu2022metaformer,
29+
title={Metaformer is actually what you need for vision},
30+
author={Yu, Weihao and Luo, Mi and Zhou, Pan and Si, Chenyang and Zhou, Yichen and Wang, Xinchao and Feng, Jiashi and Yan, Shuicheng},
31+
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
32+
pages={10819--10829},
33+
year={2022}
34+
}
35+
```
36+
37+
### Usage
38+
39+
- PoolFormer backbone needs to install [MMClassification](https://github.com/open-mmlab/mmclassification) first, which has abundant backbones for downstream tasks.
40+
41+
```shell
42+
pip install mmcls>=0.23.0
43+
```
44+
45+
- The pretrained models could also be downloaded from [PoolFormer config of MMClassification](https://github.com/open-mmlab/mmclassification/tree/master/configs/poolformer).
46+
47+
## Results and models
48+
49+
### ADE20K
50+
51+
| Method | Backbone | Crop Size | pretrain | Batch Size | Lr schd | Mem (GB) | Inf time (fps) | mIoU | mIoU(ms+flip) | mIoU\* | mIoU\*(ms+flip) | config | download |
52+
| ------ | -------------- | --------- | ----------- | ---------- | ------- | -------- | -------------- | ----- | ------------: | ------ | --------------: | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53+
| FPN | PoolFormer-S12 | 512x512 | ImageNet-1K | 32 | 40000 | 4.17 | 23.48 | 36.0 | 36.42 | 37.07 | 38.44 | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer/fpn_poolformer_s12_8x4_512x512_40k_ade20k.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s12_8x4_512x512_40k_ade20k/fpn_poolformer_s12_8x4_512x512_40k_ade20k_20220501_115154-b5aa2f49.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s12_8x4_512x512_40k_ade20k/fpn_poolformer_s12_8x4_512x512_40k_ade20k_20220501_115154.log.json) |
54+
| FPN | PoolFormer-S24 | 512x512 | ImageNet-1K | 32 | 40000 | 5.47 | 15.74 | 39.35 | 39.73 | 40.36 | 41.08 | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer/fpn_poolformer_s24_8x4_512x512_40k_ade20k.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s24_8x4_512x512_40k_ade20k/fpn_poolformer_s24_8x4_512x512_40k_ade20k_20220503_222049-394a7cf7.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s24_8x4_512x512_40k_ade20k/fpn_poolformer_s24_8x4_512x512_40k_ade20k_20220503_222049.log.json) |
55+
| FPN | PoolFormer-S36 | 512x512 | ImageNet-1K | 32 | 40000 | 6.77 | 11.34 | 40.64 | 40.99 | 41.81 | 42.72 | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer/fpn_poolformer_s36_8x4_512x512_40k_ade20k.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s36_8x4_512x512_40k_ade20k/fpn_poolformer_s36_8x4_512x512_40k_ade20k_20220501_151122-b47e607d.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_s36_8x4_512x512_40k_ade20k/fpn_poolformer_s36_8x4_512x512_40k_ade20k_20220501_151122.log.json) |
56+
| FPN | PoolFormer-M36 | 512x512 | ImageNet-1K | 32 | 40000 | 8.59 | 8.97 | 40.91 | 41.28 | 42.35 | 43.34 | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer/fpn_poolformer_m36_8x4_512x512_40k_ade20k.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_m36_8x4_512x512_40k_ade20k/fpn_poolformer_m36_8x4_512x512_40k_ade20k_20220501_164230-3dc83921.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_m36_8x4_512x512_40k_ade20k/fpn_poolformer_m36_8x4_512x512_40k_ade20k_20220501_164230.log.json) |
57+
| FPN | PoolFormer-M48 | 512x512 | ImageNet-1K | 32 | 40000 | 10.48 | 6.69 | 41.82 | 42.2 | 42.76 | 43.57 | [config](https://github.com/open-mmlab/mmsegmentation/blob/master/configs/poolformer/fpn_poolformer_m48_8x4_512x512_40k_ade20k.py) | [model](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_m48_8x4_512x512_40k_ade20k/fpn_poolformer_m48_8x4_512x512_40k_ade20k_20220504_003923-64168d3b.pth) \| [log](https://download.openmmlab.com/mmsegmentation/v0.5/poolformer/fpn_poolformer_m48_8x4_512x512_40k_ade20k/fpn_poolformer_m48_8x4_512x512_40k_ade20k_20220504_003923.log.json) |
58+
59+
Note:
60+
61+
- We replace `AlignedResize` in original PoolFormer implementation to `Resize + ResizeToMultiple`.
62+
63+
- `mIoU` with * is collected when `Resize + ResizeToMultiple` is adopted in `test_pipeline`, so do `mIoU` in logs.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_base_ = './fpn_poolformer_s12_8x4_512x512_40k_ade20k.py'
2+
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/poolformer/poolformer-m36_3rdparty_32xb128_in1k_20220414-c55e0949.pth' # noqa
3+
4+
# model settings
5+
model = dict(
6+
backbone=dict(
7+
arch='m36',
8+
init_cfg=dict(
9+
type='Pretrained', checkpoint=checkpoint_file,
10+
prefix='backbone.')),
11+
neck=dict(in_channels=[96, 192, 384, 768]))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_base_ = './fpn_poolformer_s12_8x4_512x512_40k_ade20k.py'
2+
checkpoint_file = 'https://download.openmmlab.com/mmclassification/v0/poolformer/poolformer-m48_3rdparty_32xb128_in1k_20220414-9378f3eb.pth' # noqa
3+
4+
# model settings
5+
model = dict(
6+
backbone=dict(
7+
arch='m48',
8+
init_cfg=dict(
9+
type='Pretrained', checkpoint=checkpoint_file,
10+
prefix='backbone.')),
11+
neck=dict(in_channels=[96, 192, 384, 768]))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
_base_ = [
2+
'../_base_/models/fpn_poolformer_s12.py', '../_base_/default_runtime.py',
3+
'../_base_/schedules/schedule_40k.py'
4+
]
5+
6+
# model settings
7+
model = dict(
8+
neck=dict(in_channels=[64, 128, 320, 512]),
9+
decode_head=dict(num_classes=150))
10+
11+
# optimizer
12+
optimizer = dict(_delete_=True, type='AdamW', lr=0.0002, weight_decay=0.0001)
13+
optimizer_config = dict()
14+
# learning policy
15+
lr_config = dict(policy='poly', power=0.9, min_lr=0.0, by_epoch=False)
16+
17+
# dataset settings
18+
dataset_type = 'ADE20KDataset'
19+
data_root = 'data/ade/ADEChallengeData2016'
20+
img_norm_cfg = dict(
21+
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
22+
crop_size = (512, 512)
23+
train_pipeline = [
24+
dict(type='LoadImageFromFile'),
25+
dict(type='LoadAnnotations', reduce_zero_label=True),
26+
dict(type='Resize', img_scale=(2048, 512), ratio_range=(0.5, 2.0)),
27+
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
28+
dict(type='RandomFlip', prob=0.5),
29+
dict(type='PhotoMetricDistortion'),
30+
dict(type='Normalize', **img_norm_cfg),
31+
dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
32+
dict(type='DefaultFormatBundle'),
33+
dict(type='Collect', keys=['img', 'gt_semantic_seg']),
34+
]
35+
test_pipeline = [
36+
dict(type='LoadImageFromFile'),
37+
dict(
38+
type='MultiScaleFlipAug',
39+
img_scale=(2048, 512),
40+
# img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],
41+
flip=False,
42+
transforms=[
43+
dict(type='Resize', keep_ratio=True),
44+
dict(type='ResizeToMultiple', size_divisor=32),
45+
dict(type='RandomFlip'),
46+
dict(type='Normalize', **img_norm_cfg),
47+
dict(type='ImageToTensor', keys=['img']),
48+
dict(type='Collect', keys=['img']),
49+
])
50+
]
51+
data = dict(
52+
samples_per_gpu=4,
53+
workers_per_gpu=4,
54+
train=dict(
55+
type='RepeatDataset',
56+
times=50,
57+
dataset=dict(
58+
type=dataset_type,
59+
data_root=data_root,
60+
img_dir='images/training',
61+
ann_dir='annotations/training',
62+
pipeline=train_pipeline)),
63+
val=dict(
64+
type=dataset_type,
65+
data_root=data_root,
66+
img_dir='images/validation',
67+
ann_dir='annotations/validation',
68+
pipeline=test_pipeline),
69+
test=dict(
70+
type=dataset_type,
71+
data_root=data_root,
72+
img_dir='images/validation',
73+
ann_dir='annotations/validation',
74+
pipeline=test_pipeline))

0 commit comments

Comments
 (0)