公開されたソフトウエア,データを使い,Windows で pix2pix を動かしてみる. Python, TensorFlow を使う.
手順の要点: Python 3.6, TensorFlow 1.15, Python の仮想環境(Windows では C:\venv\tf115py36)
ソフトウエア等の利用条件等は,利用者で確認すること.
謝辞:ソフトウエアの作者に感謝します.
参考Webページ: affinelayer/pix2pix-tensorflow のページ, https://github.com/affinelayer/pix2pix-tensorflow
このWebページでは,pix2pix の Python 版が公開されているとともに,次のような 5種類のデータセットが公開されている.
サイト内の関連ページ
Python の URL: http://www.python.org/
インストール手順の詳細は: 別ページで説明している.
コマンドプロンプトを管理者として実行し,次のコマンドを実行.
python -m pip install -U pip setuptools python -m pip install -U jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
システム Python を使用(インストール操作は不要)
端末で,次のコマンドを実行.
sudo apt -y install python3-dev python3-pip python3-setuptools python3-venv sudo pip3 uninstall ptyprocess sniffio terminado tornado jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder sudo apt -y install jupyter jupyter-qtconsole spyder3 sudo apt -y install python3-ptyprocess python3-sniffio python3-terminado python3-tornado sudo pip3 install -U jupyterlab nteract_on_jupyter
sudo apt -y install git
※ GPU とは,グラフィックス・プロセッシング・ユニットの略で、コンピュータグラフィックス関連の機能,乗算や加算の並列処理の機能などがある.
ダウンロードページ
詳細説明
※ CUDA とは,NVIDIA社が提供している GPU 用のプラットフォームである.
指定されているバージョンより高いものは使わない. その根拠は次のページ. URL: https://www.tensorflow.org/install/source#common_installation_problems
詳細説明
ダウンロードページ
ダウンロードして展開(解凍)したら,パスを通しておくこと.
TensorFlow 2.4 の GPU 版での,cuDNN のバージョンは 8.0.5(現時点で,NVIDIA CUDA ツールキット 11 で動く最新版).
TensorFlow 2.3, 2.2, 2.1 の GPU 版での,cuDNN のバージョンは 7.6.そして,TensorFlow 1.13 以上 TensorFlow 2.0 までの GPU 版での,cuDNN のバージョンは7.4 .それより高いバージョンよりは使わないこと.
詳細説明
Python 3.6 を起動するコマンドを確認しておくこと.
C:\venv\tf115py36\Scripts\activate.bat
Python の使用は,隔離された Python 仮想環境の有効化の後,「python」で行う. Windows で,隔離された Python 仮想環境を使用しないときは,「python」ではなく「py -3.6」を使う.
python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow_datasets tensorflow-hub keras python -m pip install -U tensorflow==1.15.5 tensorflow_datasets tensorflow-hub keras==2.3.1 matplotlib opencv-python python -m pip install git+https://github.com/tensorflow/docs python -m pip install git+https://github.com/tensorflow/examples.git
python -c "import tensorflow as tf; print( tf.__version__ )"
TensorFlow が GPU を認識できているかの確認は,端末で,次を実行して行う.
python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"
端末で,次のコマンドを実行.
pyenv shell 3.6.12
隔離された Python 仮想環境を使用するときは, 「pyenv shell 3.6.12」は実行しないで, 次のようなコマンドで Python 仮想環境を有効化する.
source ~/tf115py36/bin/activate
Python の使用は,「python」で行う.
python -m pip uninstall -y tensorflow tensorflow-cpu tensorflow-gpu tensorflow_datasets tensorflow-hub keras python -m pip install -U tensorflow==1.15.5 tensorflow_datasets tensorflow-hub keras==2.3.1 matplotlib opencv-python python -m pip install git+https://github.com/tensorflow/docs python -m pip install git+https://github.com/tensorflow/examples.git
python -c "import tensorflow as tf; print( tf.__version__ )"
TensorFlow が GPU を認識できているかの確認は,端末で,次を実行して行う.
python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())"
謝辞:https://github.com/affinelayer/pix2pix-tensorflow で公開されている著作物を利用している
Windows での手順を下に示す.Ubuntu でも同様の手順になる.
Windows の場合での,有効化のコマンドの例.
C:\venv\tf115py36\Scripts\activate.bat
Ubuntu の場合での,有効化のコマンドの例.
source ~/tf115py36/bin/activate
※ 以下,Windows での手順を示す.Ubuntu でも同様の手順になる.
cd C:\venv\tf115py36 rmdir /s /q pix2pix-tensorflow
git clone https://github.com/affinelayer/pix2pix-tensorflow
※ affinelayer/pix2pix-tensorflow の Web ページ に記載の通り行う.
cd C:\venv\tf115py36\pix2pix-tensorflow python tools\download-dataset.py facades
※ これも,affinelayer/pix2pix-tensorflow の Web ページ に記載の通り行う.
※ GPU のときは数時間.CPUのときはさらに時間がかかる.
python pix2pix.py --mode train --output_dir facades_train --max_epochs 100 --input_dir facades\train --which_direction BtoA
BtoA について.
「--which_direction BtoA」と指定したので, 「右側」のような画像をコンピュータに与えたら,「左側」のような画像が生成されるように,モデルのトレーニングを行いなさいという指示になる.
※ GPU 版の TensorFlow を使わない場合は,終了まで,かなり待つ.終了したらエラーメッセージが出ていないことを確認する.
次に,「学習結果の出力先 (--output_dir オプション)」として指定した facades_train に,ファイルができていることを確認する.
次の手順で表示してみる
このとき,起動メッセージに,URLが「http://hoge:6006」のように表示されるので確認する.
実行手順例
tensorboard --logdir=facades_train
※ これも,affinelayer/pix2pix-tensorflow の Web ページ に記載の通り行う.
python pix2pix.py --mode test --output_dir facades_test --input_dir facades\val --checkpoint facades_train