본문 바로가기
열정/연구 일지

Ubuntu 기반 Docker를 통한 환경 구축 방법

by lime9 2024. 7. 8.

기본 환경

  • Ubuntu 22.04
  • RTX 4090 1개

참고 코드

https://github.com/jz462/Large-Scale-VRD.pytorch?tab=readme-ov-file

 

GitHub - jz462/Large-Scale-VRD.pytorch: Implementation for the AAAI2019 paper "Large-scale Visual Relationship Understanding"

Implementation for the AAAI2019 paper "Large-scale Visual Relationship Understanding" - jz462/Large-Scale-VRD.pytorch

github.com

 

1. Docker file를 통해 기본 환경 구축

Base image 탐색

https://hub.docker.com/r/nvidia/cuda/tags?page=&page_size=&ordering=&name=

 

https://hub.docker.com/r/nvidia/cuda/tags?name=&ordering=&page=&page_size=

 

hub.docker.com

 

해당 이미지를 기반으로 docker file 구성

# Base image
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu18.04

# Install necessary dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    git \
    curl \
    vim \
    wget \
    ca-certificates \
    libjpeg-dev \
    libpng-dev \
    software-properties-common \
    && rm -rf /var/lib/apt/lists/*

# Install Python 3.7 and pip
RUN add-apt-repository ppa:deadsnakes/ppa && apt-get update \
    && apt-get install -y python3.7 python3.7-dev python3.7-distutils python3-pip \
    && ln -s /usr/bin/python3.7 /usr/local/bin/python3 \
    && ln -s /usr/bin/python3.7 /usr/local/bin/python \
    && python3.7 -m pip install pip --upgrade

# Install PyTorch 0.4.1
RUN pip install torch==0.4.1 torchvision==0.2.1 -f https://download.pytorch.org/whl/torch_stable.html

# Set environment variables
ENV PATH="/opt/conda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
ENV CUDA_HOME="/usr/local/cuda"

 

이미지 생성 및 container 실행

docker build -t jeein:py3.7-torch0.4.1-cuda11.8-cudnn8-ubuntu18.04 .
docker run --runtime=nvidia --gpus all -it --name semcom -v /home/:/home/ jeein:py3.7-torch0.4.1-cuda11.8-cudnn8-ubuntu18.04

 

2. Miniconda를 통한 conda 환경 구축

https://repo.anaconda.com/miniconda/index.html

 

Index of /

 

repo.anaconda.com

 

wget https://repo.anaconda.com/miniconda/Miniconda3-py37_23.1.0-1-Linux-x86_64.sh
chmod +x Miniconda3-py37_23.1.0-1-Linux-x86_64.sh
./Miniconda3-py37_23.1.0-1-Linux-x86_64.sh
source ~/.bashrc

 

버전 확인은 다음으로 진행한다.

conda --version

 

3. 필요 패키지 설치

conda install pytorch=0.4.1
pip install cython
pip install matplotlib numpy scipy pyyaml packaging pycocotools tensorboardX tqdm pillow scikit-image gensim
conda install opencv
conda install torchvision

 

4. 컴파일

cd $ROOT/lib
sh make.sh

 

5. 검증

SGDET

python ./tools/test_net_rel.py --dataset vg --cfg configs/e2e_relcnn_VGG16_8_epochs_vg_y_loss_only.yaml --load_ckpt trained_models/vg_VGG16/model_step62722.pth --output_dir Outputs/vg_VGG16 --do_val