2023年8月現在、Google ColabではPython 3.10、TensorFlow 2.x、CUDA 11が標準になり、Tensorflow 1系統で実装されたStyleGAN2を簡単に動かすことができなくなってしまいました(すべて要件外で動かす術がない)。。
と思いきや、以下のインストールを行うことで、T4 GPUにおいてStyleGAN2、Toonifyの実行に成功しました(2023/08/23時点)。
- Python 3.8
- NVIDIA-TensorFlow 1.15.5+nv22.12
- gcc/g++ 8
スクリプトについては、特に修正する必要はありませんでした。
Colabのセルで対話的にPython 3.8を動かすことはできないため、pyファイルのモジュールとしてあらかじめ作成しておき、!python hoge.py
を実行することで目的の処理ができるようになります。
# Python 3.8
!sudo apt-get install python3.8
!sudo apt-get update -y
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
!sudo update-alternatives --config python3
!sudo apt install python3-pip
!sudo apt-get install python3.8-distutils
# NVIDIA-TensorFlow 1.15.5
!wget https://developer.download.nvidia.com/compute/redist/nvidia-tensorflow/nvidia_tensorflow-1.15.5+nv22.12-6638418-cp38-cp38-linux_x86_64.whl
!wget https://developer.download.nvidia.com/compute/redist/nvidia-dali-nvtf-plugin/nvidia_dali_nvtf_plugin-1.20.0+nv22.12-6638418-cp38-cp38-linux_x86_64.whl
!wget https://developer.download.nvidia.com/compute/redist/nvidia-dali-cuda110/nvidia_dali_cuda110-1.20.0-6562491-py3-none-manylinux2014_x86_64.whl
!pip install nvidia-pyindex
!pip install nvidia_dali_cuda110-1.20.0-6562491-py3-none-manylinux2014_x86_64.whl
!pip install nvidia_dali_nvtf_plugin-1.20.0+nv22.12-6638418-cp38-cp38-linux_x86_64.whl
!pip install nvidia_tensorflow-1.15.5+nv22.12-6638418-cp38-cp38-linux_x86_64.whl
# GCC-8
!sudo apt update
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/gcc-8_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.edge.kernel.org/ubuntu/pool/universe/g/gcc-8/gcc-8-base_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libgcc-8-dev_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/cpp-8_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libmpx2_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.kernel.org/ubuntu/pool/main/i/isl/libisl22_0.22.1-1_amd64.deb
!sudo apt install ./libisl22_0.22.1-1_amd64.deb ./libmpx2_8.4.0-3ubuntu2_amd64.deb ./cpp-8_8.4.0-3ubuntu2_amd64.deb ./libgcc-8-dev_8.4.0-3ubuntu2_amd64.deb ./gcc-8-base_8.4.0-3ubuntu2_amd64.deb ./gcc-8_8.4.0-3ubuntu2_amd64.deb
# G++-8
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/libstdc++-8-dev_8.4.0-3ubuntu2_amd64.deb
!wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-8/g++-8_8.4.0-3ubuntu2_amd64.deb
!sudo apt install ./libstdc++-8-dev_8.4.0-3ubuntu2_amd64.deb ./g++-8_8.4.0-3ubuntu2_amd64.deb
# GCCのバージョンを変更(無理やり実行ファイルを変更)
!sudo mv /usr/bin/g++ /usr/bin/g++-11
!sudo mv /usr/bin/gcc /usr/bin/gcc-11
!sudo cp /usr/bin/g++-8 /usr/bin/g++
!sudo cp /usr/bin/gcc-8 /usr/bin/gcc
# ライブラリ
!pip install pillow requests matplotlib
!pip install numpy==1.23.4
-
nvidia-pyindexを事前にインストールしているにもかかわらず、なぜかうまく
nvidia_tensorflow-1.15.5+nv22.12
に依存するライブラリを探せていないようだったので、nvidia_dali_cuda110
、nvidia_dali_nvtf_plugin
については手動でインストールさせました。 -
あとは、
!pip install hoge
で必要なライブラリをインストールすればStyleGAN2を動かすことができました。