본문 바로가기
NaverBoost Camp 4기/[P stage] Semantic Segmentation

[Seg] Segmentation 모델(mmsegmentation) 준비

by 하람 Haram 2023. 6. 21.
728x90

일단 구상하고 있는 아이디어에 사용되는 데이터는

모델 : BEiT (https://arxiv.org/pdf/2106.08254.pdf)
데이터 : ADE20K(https://github.com/CSAILVision/ADE20K/tree/main) 이다

 

BEiT for ADE20K를 사용하기 위해서는 mmsegmentation Framework를 이용하려 한다

이 Backbone을 이용하고 싶어서

MMsegmentation을 이용하고자 한다

conda create -n mmseg python=3.7 -y
conda activate mmseg

https://github.com/open-mmlab/mmsegmentation/blob/main/docs/en/get_started.md

conda install pytorch=1.6.0 torchvision cudatoolkit=10.1 -c pytorch
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html

그 다음 mmsegmentation의 공식 github를 clone 해오자

git clone https://github.com/open-mmlab/mmsegmentation.git .

여기에 들어가 보면

 beit가 딸려서 온다

 

 

예시대로 진행해보자

python tools/model_converters/beit2mmseg.py ${PRETRAIN_PATH} ${STORE_PATH}

에러 슈팅해주고

ModuleNotFoundError: No module named 'mmengine'
pip install mmengine

뭔가 이상해서 직접 pth를 받았다

https://github.com/microsoft/unilm/blob/master/beit/README.md

 

GitHub - microsoft/unilm: Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities

Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities - GitHub - microsoft/unilm: Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities

github.com

공식레포인 아래의 링크 를 MMseg로 바꿔준 것이라고 한다

https://github.com/microsoft/unilm/tree/master/beit/semantic_segmentation

 

 

 

 

그 다음 아래로 트레이닝을 시킨다

tools/dist_train.sh <CONFIG_PATH> <NUM_GPUS>  --work-dir <SAVE_PATH> --seed 0  --deterministic --options model.pretrained=<IMAGENET_CHECKPOINT_PATH/URL>
tools/dist_train.sh /configs/beit/beit-base_upernet_8xb2-160k_ade20k-640x640_ms.py 1  --work-dir ./save --seed 0  --deterministic --options model.pretrained=/pretrain/beit_base_patch16_224_pt22k_ft22k.pth

라고 하는데 

File "/home/kist/Collabot/semantic_seg/mmseg/__init__.py", line 62, in <module> f'MMCV=={mmcv.__version__} is used but incompatible. ' \ AssertionError: MMCV==1.7.1 is used but incompatible. Please install mmcv>=2.0.0rc4.

이 에러가 나서

mim install 'mmcv >= 2.0.0rc1'

를 해줬더니

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> mmcv

이 에러가 나와가지고

pip install --upgrade pip

한 다음 아래의 링크

https://github.com/open-mmlab/mmdetection/issues/10104에서 하라는 데로

pip install mmcv==2.0.0rc4 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9/index.html

를 통해서 mmcv 문제는 해결했고

이 에러를 해결해 보자

UserWarning: Cannot import torch.fx, `merge_dict` is a simple function to merge multiple dicts warnings.warn('Cannot import torch.fx, `merge_dict` is a simple function ' usage: train.py [-h] [--work-dir WORK_DIR] [--resume] [--amp] [--cfg-options CFG_OPTIONS [CFG_OPTIONS ...]] [--launcher {none,pytorch,slurm,mpi}] [--local_rank LOCAL_RANK] config train.py: error: unrecognized arguments: --seed 0 --deterministic --options model.pretrained=/pretrain/beit_base_patch16_224_pt22k_ft22k.pth Traceback (most recent call last): File "/home/kist/anaconda3/envs/mmseg/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/kist/anaconda3/envs/mmseg/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/kist/anaconda3/envs/mmseg/lib/python3.7/site-packages/torch/distributed/launch.py", line 261, in <module> main() File "/home/kist/anaconda3/envs/mmseg/lib/python3.7/site-packages/torch/distributed/launch.py", line 257, in main cmd=cmd) subprocess.CalledProcessError: Command '['/home/kist/anaconda3/envs/mmseg/bin/python', '-u', 'tools/train.py', '--local_rank=0', '/configs/beit/beit-base_upernet_8xb2-160k_ade20k-640x640_ms.py', '--launcher', 'pytorch', '--work-dir', './save', '--seed', '0', '--deterministic', '--options', 'model.pretrained=/pretrain/beit_base_patch16_224_pt22k_ft22k.pth']' returned non-zero exit status 2.

 

 

 

 

 

 

 

 

참고자료

https://github.com/open-mmlab/mmsegmentation/tree/master

 

GitHub - open-mmlab/mmsegmentation: OpenMMLab Semantic Segmentation Toolbox and Benchmark.

OpenMMLab Semantic Segmentation Toolbox and Benchmark. - GitHub - open-mmlab/mmsegmentation: OpenMMLab Semantic Segmentation Toolbox and Benchmark.

github.com

https://www.inflearn.com/questions/614994/mmdet-%EC%84%A4%EC%B9%98%EA%B0%80-%EC%95%88%EB%90%98%EB%84%A4%EC%9A%94-%E3%85%A0%E3%85%A0

 

mmdet 설치가 안되네요 ㅠㅠ - 인프런 | 질문 & 답변

먼저 좋은 강의 감사드립니다. 열심히 따라가면서 배우고 있습니다 ^^다만 mmdet 설치가 계속 안되어서.. 질문 드립니다.Colab 이 아닌, 개인 pc 서버로 실습을 해 오고 있었습니다. GPU 는 RTX3090 이구

www.inflearn.com

 

728x90