[가상환경] Segformer를 위한 가상환경 설치하기

최가윤·2024년 4월 7일
0
post-thumbnail

Segformer

Segformer

Segformer는 Transformer 구조의 open-source 모델 중 준수한 성능을 보여 다양한 논문에 사용되고 있다.

Segformer는 mmcv library를 기반으로 코드가 작성되었다. 확인해보니 mmcv는 Classification, Segmentation, Detection 등 다양한 Task를 지원한다. 이 중 mmSegmentation은 MaskFormer, SegFormer, SETR 등의 유명한 SOTA 모델을 지원하고 있어서 경험해보면 좋을 것 같다.

Segformer에서 공식적으로 안내한 설치 방법은 다음과 같다.

For install and data preparation, please refer to the guidelines in MMSegmentation v0.13.0.
Other requirements: pip install timm==0.3.2
An example (works for me): CUDA 10.1 and pytorch 1.7.1

pip install torchvision==0.8.2
pip install timm==0.3.2
pip install mmcv-full==1.2.7
pip install opencv-python==4.5.1.48
cd SegFormer && pip install -e . --user

문제는 Segformer가 오래된 버전의 mmcv 기반이라 설치가 까다롭다는 점이다. 예를 들어서 내가 연구하는 환경에서는CUDA 10.1를 지원하지 않아 설치가 막혔다...

따라서 필수적으로 맞춰야 할 pytorch 1.7.1mmcv-full==1.2.7를 바탕으로 다른 버전을 바꾸어서 설치했다. 글로 정리해보니 어렵지 않은 내용인데, 당시에 설치를 실패했을 때 당황스럽기도 했고 기록삼아 남겨둔다.

가상환경 설치하기

  1. Conda 가상환경 만들기
    !다른 패키지들과의 충돌을 막기 위해 3.8 버전으로 설치해준다!
conda create -n segformer python==3.8 
  1. 구버전 Pytorch 설치하기
    Pytorch에서는 구버전 설치 명령어를 제공하고 있다.
    pytorch v1.7.1 설치 명령어는 다음과 같다. 자신의 연구환경에서 지원하는 CUDA 버전 따라 설치하자. 참고로 나는 CUDA 11.0 버전으로 설치했다.
# CUDA 9.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2 -c pytorch

# CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch

# CPU Only
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cpuonly -c pytorch

or

# CUDA 11.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2

# CUDA 10.1
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
  1. mmcv와 그 외의 패키지 설치하기
pip install timm==0.3.2
pip install mmcv-full==1.2.7 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
pip install opencv-python==4.5.1.48
pip install -e . --user

참고자료

mmcv 설치하기

profile
Study AI (2022 - )

1개의 댓글

comment-user-thumbnail
2024년 10월 30일

안녕하세요. Segformer 관련해서 글 잘 봣습니다.
다름이 아니고 pip install -e . --user 를 입력했을 떄
Running setup.py develop for mmsegmentation
error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
╰─> [32 lines of output]
    running develop
    running egg_info
    writing mmsegmentation.egg-info/PKG-INFO
    /home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'tests_require'
      warnings.warn(msg)
    /home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/command/develop.py:41: EasyInstallDeprecationWarning: easy_install command is deprecated.
    !!
   
            ********************************************************************************
            Please avoid running ``setup.py`` and ``easy_install``.
            Instead, use pypa/build, pypa/installer or other
            standards-based tools.
   
            See https://github.com/pypa/setuptools/issues/917 for details.
            ********************************************************************************
   
    !!
      easy_install.initialize_options(self)
    /home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
    !!
   
            ********************************************************************************
            Please avoid running ``setup.py`` directly.
            Instead, use pypa/build, pypa/installer or other
            standards-based tools.
   
            See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
            ********************************************************************************
   
    !!
      self.initialize_options()
    error: [Errno 1] Operation not permitted: '/mnt/d/segFormer-master/mmsegmentation.egg-info/tmpjnni924x'
    [end of output]

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

error: subprocess-exited-with-error

× python setup.py develop did not run successfully.
│ exit code: 1
╰─> [32 lines of output]
running develop
running egg_info
writing mmsegmentation.egg-info/PKG-INFO
/home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option: 'tests_require'
warnings.warn(msg)
/home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/command/develop.py:41: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  easy_install.initialize_options(self)
/home/mangoggul/anaconda3/envs/mmlab/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated. 
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
error: [Errno 1] Operation not permitted: '/mnt/d/segFormer-master/mmsegmentation.egg-info/tmpjnni924x'
[end of output]

와 같은 에러가 발생합니다. 혹시 아시는 바가 있으실까요..

답글 달기