Commit Graph

22 Commits (9b6c4b7e988c4a5156a3ae39cdd904094e42134d)

Author SHA1 Message Date
谢昕辰 7ff58d7074
[Feature] Support albu transform (#2943)
## Motivation


3a14c35974/mmseg/datasets/pipelines/transforms.py (L1348)

## Modification

Add albu to dev-1.x
2023-04-24 13:44:20 +08:00
谢昕辰 997d14701e
[CI] update mmdet dependency (#2848) 2023-04-06 16:18:25 +08:00
谢昕辰 3312c505af
[Doc] Update readme (#2834)
## Motivation

As title, lead users to follow our migration document.

## Checklist

- [x] https://github.com/open-mmlab/mmsegmentation/pull/2801
2023-04-06 14:57:25 +08:00
谢昕辰 413f12066e
[CI] Update ci image (#2801)
## Motivation

https://github.com/actions/runner-images/issues/6002
2023-04-06 11:12:14 +08:00
Qingyun a092fea8c1
[Fix] Fix MaskFormer and Mask2Former of MMSegmentation (#2532)
## Motivation

The DETR-related modules have been refactored in
open-mmlab/mmdetection#8763, which causes breakings of MaskFormer and
Mask2Former in both MMDetection (has been fixed in
open-mmlab/mmdetection#9515) and MMSegmentation. This pr fix the bugs in
MMSegmentation.

### TO-DO List

- [x] update configs
- [x] check and modify data flow
- [x] fix unit test
- [x] aligning inference
- [x] write a ckpt converter
- [x] write ckpt update script
- [x] update model zoo
- [x] update model link in readme
- [x] update
[faq.md](https://github.com/open-mmlab/mmsegmentation/blob/dev-1.x/docs/en/notes/faq.md#installation)

## Tips of Fixing other implementations based on MaskXFormer of mmseg

1. The Transformer modules should be built directly. The original
building with register manner has been refactored.
2. The config requires to be modified. Delete `type` and modify several
keys, according to the modifications in this pr.
3. The `batch_first` is set `True` uniformly in the new implementations.
Hence the data flow requires to be transposed and config of
`batch_first` needs to be modified.
4. The checkpoint trained on the old implementation should be converted
to be used in the new one.

### Convert script

```Python
import argparse
from copy import deepcopy
from collections import OrderedDict

import torch

from mmengine.config import Config
from mmseg.models import build_segmentor
from mmseg.utils import register_all_modules
register_all_modules(init_default_scope=True)


def parse_args():
    parser = argparse.ArgumentParser(
        description='MMSeg convert MaskXFormer model, by Li-Qingyun')
    parser.add_argument('Mask_what_former', type=int,
                        help='Mask what former, can be a `1` or `2`',
                        choices=[1, 2])
    parser.add_argument('CFG_FILE', help='config file path')
    parser.add_argument('OLD_CKPT_FILEPATH', help='old ckpt file path')
    parser.add_argument('NEW_CKPT_FILEPATH', help='new ckpt file path')
    args = parser.parse_args()
    return args


args = parse_args()

def get_new_name(old_name: str):
    new_name = old_name

    if 'encoder.layers' in new_name:
        new_name = new_name.replace('attentions.0', 'self_attn')

    new_name = new_name.replace('ffns.0', 'ffn')

    if 'decoder.layers' in new_name:

        if args.Mask_what_former == 2:
            # for Mask2Former
            new_name = new_name.replace('attentions.0', 'cross_attn')
            new_name = new_name.replace('attentions.1', 'self_attn')
        else:
            # for Mask2Former
            new_name = new_name.replace('attentions.0', 'self_attn')
            new_name = new_name.replace('attentions.1', 'cross_attn')

    return new_name
    
def cvt_sd(old_sd: OrderedDict):
    new_sd = OrderedDict()
    for name, param in old_sd.items():
        new_name = get_new_name(name)
        assert new_name not in new_sd
        new_sd[new_name] = param
    assert len(new_sd) == len(old_sd)
    return new_sd
    
if __name__ == '__main__':
    cfg = Config.fromfile(args.CFG_FILE)
    model_cfg = cfg.model

    segmentor = build_segmentor(model_cfg)

    refer_sd = segmentor.state_dict()
    old_ckpt = torch.load(args.OLD_CKPT_FILEPATH)
    old_sd = old_ckpt['state_dict']

    new_sd = cvt_sd(old_sd)
    print(segmentor.load_state_dict(new_sd))

    new_ckpt = deepcopy(old_ckpt)
    new_ckpt['state_dict'] = new_sd
    torch.save(new_ckpt, args.NEW_CKPT_FILEPATH)
    print(f'{args.NEW_CKPT_FILEPATH} has been saved!')
```

Usage:
```bash
# for example
python ckpt4pr2532.py 1 configs/maskformer/maskformer_r50-d32_8xb2-160k_ade20k-512x512.py original_ckpts/maskformer_r50-d32_8xb2-160k_ade20k-512x512_20221030_182724-cbd39cc1.pth cvt_outputs/maskformer_r50-d32_8xb2-160k_ade20k-512x512_20221030_182724.pth
python ckpt4pr2532.py 2 configs/mask2former/mask2former_r50_8xb2-160k_ade20k-512x512.py original_ckpts/mask2former_r50_8xb2-160k_ade20k-512x512_20221204_000055-4c62652d.pth cvt_outputs/mask2former_r50_8xb2-160k_ade20k-512x512_20221204_000055.pth
```

---------

Co-authored-by: MeowZheng <meowzheng@outlook.com>
2023-02-01 18:58:21 +08:00
谢昕辰 124b87ce90
[Refactor] Refactor fileio (#2543)
## Motivation

Use the new fileio from mmengine
https://github.com/open-mmlab/mmengine/pull/533

## Modification

1. Use `mmengine.fileio` to repalce FileClient  in mmseg/datasets
2. Use `mmengine.fileio` to repalce FileClient in
mmseg/datasets/transforms
3. Use `mmengine.fileio` to repalce FileClient in mmseg/visualization

## BC-breaking (Optional)

we modify all the dataset configurations, so please use the latest config file.
2023-02-01 17:53:22 +08:00
谢昕辰 b9b5d8bf52
[CI] Upgrade the version of isort to fix lint error (#2519)
## Motivation

https://github.com/open-mmlab/mmeval/pull/85

---------

Co-authored-by: Miao Zheng <76149310+MeowZheng@users.noreply.github.com>
2023-01-30 10:31:12 +08:00
Miao Zheng 4e759bb1d2
[CI] Remove test py3.6 (#2468)
## Motivation

as title

## Modification

1. .circleci/test.yml
2. .github/workflows/merge_stage_test.yml
2023-01-10 17:11:59 +08:00
xiexinch f4dad5f921 [CI] Add torch1.13 checking in CI (#2402)
* Add torch1.13 in CI

* use mim install mm packages

* install all requirements

* install wheel

* add ref
2022-12-30 22:52:07 +08:00
MengzhangLI 933e4d3cb6
[Feature] Support MaskFormer(NeurIPS'2021) in MMSeg 1.x (#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
2022-12-01 19:03:10 +08:00
MeowZheng 96996271f2 lint 2022-11-02 18:14:20 +08:00
MeowZheng e9a1c7e0ae Merge branch '1.x' into dev-1.x 2022-11-02 18:09:15 +08:00
Miao Zheng b07bb163a1 [Enhancement] Fix ci for 1.x (#2011)
* [Enhancement] Fix ci for 1.x

* circle ci

* lint and engien

* typo

* typo

* mim install mmcv

* python -m pip

* python -m pip

* python -m pip

* remove pt1.5

* remove pt1.5

* ignore high memory in win

* fix win and lint

* fix lint

* fix lint

* fix lint

* win

* win
2022-11-01 22:46:02 +08:00
Miao Zheng 7f4fb80047 [Fix] circle ci (#2019)
* [Fix] circle ci

* importlib

* python -m mim

* python -m cpverage

* typo
2022-11-01 22:40:39 +08:00
Miao Zheng 00c5e80026
[Fix] Ignore test timm when torch<1.7 (#2158) 2022-10-08 17:32:12 +08:00
MengzhangLI 8aca73e187
[CI] Fix CI (#2029)
* [CI] Fix CI

* fix wrong command

* remove mmcv

* fix lint error

* add pytorch install

* fix pytorch installation

* fix mmengine error

* fix mmcv installation in pr_stage

* fix docstring coverage in lint and delete cu102 in pr_stage windows

* fix lint.yml and reset test.yml

* ignore some ut in build_windows of pr_stage

* test merge stage test

* fix mmseg dependencies in pr_stage_test.yml

* delete redundant lines in pr_stage and fix mmseg dependencies in mr_stage

* fix error in merge_stage

* delete python -m in merge_stage

* fix error in merge_stage

* let mmcv installation before mmengine

* fix error of mmcv not found

* fix ut error in merge)stage_test.yml

* fix build_windows ut in metge_stage

* fix error

* fix windows error of merge_stag

* Update .github/workflows/merge_stage_test.yml

* Update .github/workflows/merge_stage_test.yml

* Update .github/workflows/merge_stage_test.yml

* fix error

* delete skip timm ut

* add requitements/optinal.txt in test.yml

* Update .github/workflows/merge_stage_test.yml

Co-authored-by: Miao Zheng <76149310+MeowZheng@users.noreply.github.com>
2022-09-13 13:43:13 +08:00
Miao Zheng 6cdc2c4a8a
[Fix] circle ci (#2019)
* [Fix] circle ci

* importlib

* python -m mim

* python -m cpverage

* typo
2022-09-05 18:54:21 +08:00
Miao Zheng a57855b634
[Enhancement] Fix ci for 1.x (#2011)
* [Enhancement] Fix ci for 1.x

* circle ci

* lint and engien

* typo

* typo

* mim install mmcv

* python -m pip

* python -m pip

* python -m pip

* remove pt1.5

* remove pt1.5

* ignore high memory in win

* fix win and lint

* fix lint

* fix lint

* fix lint

* win

* win
2022-09-02 20:42:16 +08:00
Miao Zheng 7e83c1dd97
[Enhancement] Add mmcls installation in circle ci (#1898) 2022-08-09 19:47:40 +08:00
Miao Zheng fdaf8ea7d6
[Enhancement] Set up circle-ci on test-1.x branch (#1852) 2022-08-01 19:58:47 +08:00
Miao Zheng d326471dca
set circle ci (#1804) 2022-07-21 22:20:09 +08:00
MengzhangLI ae8d5ff0d4 [Enhancement] CircleCI Setup (#1086)
* uploading circle-ci

* uploading circle-ci

* uploading circle-ci

* correct circleci folder

* change mmsegmentation to mmseg in config.yml

* adding timm package in circleci

* adding timm package in circleci

* fix original lint error
2021-11-30 00:25:35 -08:00