Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.
【サイト内の関連ページ】
Windows での Git のインストール: 別ページ »で説明している.
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
【サイト内の関連ページ】
NVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNN のインストールを行う.
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
PyTorch のページ: https://pytorch.org/index.html
次のコマンドは, PyTorch 2.0 (NVIDIA CUDA 11.8 用) をインストールする. 但し,Anaconda3を使いたい場合には別手順になる.
事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).
PyTorch で,GPU が動作している場合には,「torch.cuda.is_available()」により,True が表示される.
python -m pip install -U --ignore-installed pip python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu118 python -c "import torch; print(torch.__version__, torch.cuda.is_available())"
Anaconda3を使いたい場合には, Anaconda プロンプト (Anaconda Prompt) を管理者として実行し, 次のコマンドを実行する. (PyTorch と NVIDIA CUDA との連携がうまくいかない可能性があるため,Anaconda3を使わないことも検討して欲しい).
conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 cudnn -c pytorch -c nvidia py -c "import torch; print(torch.__version__, torch.cuda.is_available())"
【サイト内の関連ページ】
【関連する外部ページ】
インストールの方法は複数ある. ここでは, NVIDIA CUDA ツールキットを使うことも考え, インストールしやすい方法として,ソースコードからビルドしてインストールする方法を案内している.
MMGen が mmcv-full のバージョン 1.3.0 以上,1.8.0 以下を必要とするので,mmcv-full バージョン 1.7.1 をインストールがインストールされる.
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -c "import torch; TORCH_VERSION = '.'.join(torch.__version__.split('.')[:2]); print(TORCH_VERSION)"
このとき,実際には 11.8 をインストールしているのに,「cu117」のように古いバージョンが表示されることがある.このような場合は,気にせずに続行する.
python -c "import torch; CUDA_VERSION = torch.__version__.split('+')[-1]; print(CUDA_VERSION)"
インストール手順は, https://mmcv.readthedocs.io/en/latest/get_started/installation.html に記載の手順による
python -m pip install -U --ignore-installed pip python -m pip uninstall -y openmim mmcv mmcv-full opencv-python opencv-python-headless python -m pip install -U openmim opencv-python cd %HOMEPATH% rmdir /s /q mmgeneration git clone https://github.com/open-mmlab/mmgeneration.git cd mmgeneration mim uninstall -y mmgeneration pip install -r requirements.txt mim install -e . mim list
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行する.
cd %HOMEPATH%\mmgeneration mkdir checkpoints cd checkpoints curl -O https://download.openmmlab.com/mmgen/stylegan2/official_weights/stylegan2-church-config-f-official_20210327_172657-1d42b7d1.pth dir /w cd ..
次の Python プログラムを実行する.Matplotlib を使うので,Jupyter QtConsole や Jupyter ノートブック (Jupyter Notebook) の利用が便利である.
https://mmgeneration.readthedocs.io/en/latest/get_started.html#verify-the-installationのプログラムを使用
下図では,Python プログラムの実行のため,jupyter qtconsole を使用している.
from mmgen.apis import init_model, sample_unconditional_model config_file = 'configs/styleganv2/stylegan2_c2_lsun-church_256_b4x8_800k.py' # you can download this checkpoint in advance and use a local file path. checkpoint_file = 'checkpoints/stylegan2-church-config-f-official_20210327_172657-1d42b7d1.pth' device = 'cuda:0' # init a generatvie model = init_model(config_file, checkpoint_file, device=device) # sample images fake_imgs = sample_unconditional_model(model, 4) import numpy as np import matplotlib.pyplot as plt plt.style.use('default') for i in fake_imgs: plt.imshow(np.stack([i[2], i[1], i[0]], axis=2)) plt.show()
エラーメッセージが出ないことを確認.