isPowerfulBlog
[환경구축] StyleGAN2 | Setting up StyleGAN2 TensorFlow in GoogleColab 본문
우여곡절 많았던 StyleGAN2 TensorFlow 모델 코랩 환경에서의 세팅 정리...
StyleGAN2 ADA TensorFlow 모델도 동일하게 환경 세팅해주면 된다.
https://github.com/NVlabs/stylegan2-ada
Requirements
Python 3.6.9
- Colab 환경이니까 Anaconda는 따로 X
- TensorFlow 1.15 is also supported on Linux
- NVIDIA drivers, CUDA 10.0 toolkit
이 정도로 준비하면 되겠다
Python Version Downgrade
%python --version
- tensorflow 1.x version 사용을 위해 python 버전을 3.6.x로 다운그레이드해줘야함
!wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
!tar xvfz Python-3.6.9.tgz
!Python-3.6.9/configure
!make
!sudo make install
- python install
Cuda Install
!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
- colab에 default로 설치되어있는 cuda를 uninstall해준다
!wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
!sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
!sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
!sudo apt-get update
!wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
!sudo apt install -y ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
!sudo apt-get update
- Ubuntu 18.04에서 CUDA 10.0 install
NVIDIA Driver Intsall
# Install NVIDIA driver
#!sudo apt-get install --no-install-recommends nvidia-driver-418
!sudo apt-get -y installnvidia-driver-418
# Reboot. Check that GPUs are visible using the command: nvidia-smi
# Install development and runtime libraries (~4GB)
#!sudo apt-get install --no-install-recommends \
!sudo apt-get install -y \
cuda-10-0 \
libcudnn7=7.6.2.24-1+cuda10.0 \
libcudnn7-dev=7.6.2.24-1+cuda10.0
# Install TensorRT. Requires that libcudnn7 is installed above.
# !sudo apt-get install -y --no-install-recommends libnvinfer5=5.1.5-1+cuda10.0 \
!sudo apt-get install -y libnvinfer5=5.1.5-1+cuda10.0 \
libnvinfer-dev=5.1.5-1+cuda10.0
!apt --fix-broken install
- NVIDIA driver로 설치
Pip Install
!python -m pip install pip==20.0.2
- python을 재설치했으니 pip도 다시 설치해줘야한다
TensorFlow Install
%pip install tensorflow-gpu==1.15.3
- tensorflow-gpu==1.15.3 으로 install
- tensorflow==1.15.3으로 install하면 gpu를 찾지 못 해서 cpu로 동작 됨
Install Packages
%pip install requests==2.22.0
%pip install scipy==1.3.3
%pip install Pillow==6.2.1
%pip install https://github.com/podgorskiy/dnnlib/releases/download/0.0.1/dnnlib-0.0.1-py3-none-any.whl
%pip install tqdm
- 각종 패키지들 설치
Google Drive Mount
try:
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
COLAB = True
print("Note: using Google CoLab")
except:
print("Note: not using Google CoLab")
COLAB = False
- 구글 드라이브 마운트 해준다
Git Clone Repository
!git clone https://github.com/NVlabs/stylegan2-ada
- stylegan2 ada repository install
%cd stylegan2-ada
NVCC Test
!echo 'export PATH=/usr/local/cuda/bin:$PATH' >>~/.bashrc
- /usr/local/cuda/bin에 있는 nvcc 디렉터리를 .bashrc의 PATH에 추가
!nvcc test_nvcc.cu -o test_nvcc -run
>> CPU hello
>> GPU hello
- TensorFlow ops 컴파일에 필요한 NVCC가 제대로 실행되는지 테스트해보기
!nvidia-smi
!nvcc -V
- GPU 확인
References
'AI' 카테고리의 다른 글
[Numpy] npz: 파일 구조 확인하기 (1) | 2023.01.16 |
---|---|
[Error] StyleGAN2 | AssertionError : assert state["version"] in [2, 3, 4] (0) | 2023.01.06 |
[GoogleColab] How to Downgrade to an Older Version of TensorFlow (0) | 2023.01.03 |
[논문리뷰] GANSpace: Discovering Interpretable GAN Controls (0) | 2022.11.28 |
[OCR] 개념 (0) | 2022.09.18 |