Skip to content

Commit c11da07

Browse files
谢昕辰xvjiaruiJunjun2016
authored
[Enhancement] Delete convert function and add instruction to ViT/Swin README.md (open-mmlab#791)
* delete convert function and add instruction to README.md * unified model convert and README * remove url * fix import error * fix unittest * rename pretrain * rename vit and deit pretrain * Update upernet_deit-b16_512x512_160k_ade20k.py * Update upernet_deit-b16_512x512_80k_ade20k.py * Update upernet_deit-b16_ln_mln_512x512_160k_ade20k.py * Update upernet_deit-b16_mln_512x512_160k_ade20k.py * Update upernet_deit-s16_512x512_160k_ade20k.py * Update upernet_deit-s16_512x512_80k_ade20k.py * Update upernet_deit-s16_ln_mln_512x512_160k_ade20k.py * Update upernet_deit-s16_mln_512x512_160k_ade20k.py Co-authored-by: Jiarui XU <[email protected]> Co-authored-by: Junjun2016 <[email protected]>
1 parent e235c1a commit c11da07

35 files changed

+131
-217
lines changed

configs/_base_/models/setr_mla.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
norm_cfg = dict(type='SyncBN', requires_grad=True)
44
model = dict(
55
type='EncoderDecoder',
6-
pretrained=\
7-
'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-vitjx/jx_vit_large_p16_384-b3be5167.pth', # noqa
6+
pretrained='pretrain/jx_vit_large_p16_384-b3be5167.pth',
87
backbone=dict(
98
type='VisionTransformer',
109
img_size=(768, 768),

configs/_base_/models/setr_naive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
norm_cfg = dict(type='SyncBN', requires_grad=True)
44
model = dict(
55
type='EncoderDecoder',
6-
pretrained=\
7-
'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-vitjx/jx_vit_large_p16_384-b3be5167.pth', # noqa
6+
pretrained='pretrain/jx_vit_large_p16_384-b3be5167.pth',
87
backbone=dict(
98
type='VisionTransformer',
109
img_size=(768, 768),

configs/_base_/models/setr_pup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
norm_cfg = dict(type='SyncBN', requires_grad=True)
44
model = dict(
55
type='EncoderDecoder',
6-
pretrained=\
7-
'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-vitjx/jx_vit_large_p16_384-b3be5167.pth', # noqa
6+
pretrained='pretrain/jx_vit_large_p16_384-b3be5167.pth',
87
backbone=dict(
98
type='VisionTransformer',
109
img_size=(768, 768),

configs/_base_/models/upernet_vit-b16_ln_mln.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
norm_cfg = dict(type='SyncBN', requires_grad=True)
33
model = dict(
44
type='EncoderDecoder',
5-
pretrained='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-vitjx/jx_vit_base_p16_224-80ecf9dd.pth', # noqa
5+
pretrained='pretrain/jx_vit_base_p16_224-80ecf9dd.pth',
66
backbone=dict(
77
type='VisionTransformer',
88
img_size=(512, 512),

configs/segformer/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
}
1414
```
1515

16+
## Usage
17+
18+
To use other repositories' pre-trained models, it is necessary to convert keys.
19+
20+
We provide a script [`mit2mmseg.py`](../../tools/model_converters/mit2mmseg.py) in the tools directory to convert the key of models from [the official repo](https://github.com/NVlabs/SegFormer) to MMSegmentation style.
21+
22+
```shell
23+
python tools/model_converters/swin2mmseg.py ${PRETRAIN_PATH} ${STORE_PATH}
24+
```
25+
26+
This script convert model from `PRETRAIN_PATH` and store the converted model in `STORE_PATH`.
27+
1628
## Results and models
1729

1830
### ADE20k
@@ -61,13 +73,3 @@ test_pipeline = [
6173
])
6274
]
6375
```
64-
65-
## How to use segformer official pretrain weights
66-
67-
We convert the backbone weights from the official repo (https://github.com/NVlabs/SegFormer) with `tools/model_converters/mit_convert.py`.
68-
69-
You may follow below steps to start segformer training preparation:
70-
71-
1. Download segformer pretrain weights (Suggest put in `pretrain/`);
72-
2. Run convert script to convert official pretrain weights: `python tools/model_converters/mit_convert.py pretrain/mit_b0.pth pretrain/mit_b0.pth`;
73-
3. Modify `pretrained` of segformer model config, for example, `pretrained` of `segformer_mit-b0_512x512_160k_ade20k.py` is set to `pretrain/mit_b0.pth`;

configs/setr/setr_mla_512x512_160k_b8_ade20k.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
]
55
norm_cfg = dict(type='SyncBN', requires_grad=True)
66
model = dict(
7+
pretrained='pretrain/vit_large_patch16_384.pth',
78
backbone=dict(img_size=(512, 512), drop_rate=0.),
89
decode_head=dict(num_classes=150),
910
auxiliary_head=[

configs/setr/setr_naive_512x512_160k_b16_ade20k.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
]
55
norm_cfg = dict(type='SyncBN', requires_grad=True)
66
model = dict(
7+
pretrained='pretrain/vit_large_patch16_384.pth',
78
backbone=dict(img_size=(512, 512), drop_rate=0.),
89
decode_head=dict(num_classes=150),
910
auxiliary_head=[

configs/setr/setr_pup_512x512_160k_b16_ade20k.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
]
55
norm_cfg = dict(type='SyncBN', requires_grad=True)
66
model = dict(
7+
pretrained='pretrain/vit_large_patch16_384.pth',
78
backbone=dict(img_size=(512, 512), drop_rate=0.),
89
decode_head=dict(num_classes=150),
910
auxiliary_head=[

configs/swin/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@
1313
}
1414
```
1515

16+
## Usage
17+
18+
To use other repositories' pre-trained models, it is necessary to convert keys.
19+
20+
We provide a script [`swin2mmseg.py`](../../tools/model_converters/swin2mmseg.py) in the tools directory to convert the key of models from [the official repo](https://github.com/SwinTransformer/Swin-Transformer-Semantic-Segmentation) to MMSegmentation style.
21+
22+
```shell
23+
python tools/model_converters/swin2mmseg.py ${PRETRAIN_PATH} ${STORE_PATH}
24+
```
25+
26+
E.g.
27+
28+
```shell
29+
python tools/model_converters/swin2mmseg.py https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window7_224.pth pretrain/swin_base_patch4_window7_224.pth
30+
```
31+
32+
This script convert model from `PRETRAIN_PATH` and store the converted model in `STORE_PATH`.
33+
1634
## Results and models
1735

1836
### ADE20K

configs/swin/upernet_swin_base_patch4_window12_512x512_160k_ade20k_pretrain_384x384_1K.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
'pretrain_224x224_1K.py'
44
]
55
model = dict(
6-
pretrained=\
7-
'https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window12_384.pth', # noqa
6+
pretrained='pretrain/swin_base_patch4_window12_384.pth',
87
backbone=dict(
98
pretrain_img_size=384,
109
embed_dims=128,

0 commit comments

Comments
 (0)