私的AI研究会 > CycleGAN

画像スタイル変換:CycleGAN

 AI技術「GAN(敵対的生成ネットワーク)」を試してみる(その2)。「CycleGAN」で画像のスタイル変換をおこなう。

※ 最終更新:2023/12/17 

動作環境の準備と設定

事前準備

Python3.8 仮想環境「py38_gan」を使用する

「CycleGan」の導入

  1. オフィシャルサイト から pytorch-CycleGAN-and-pix2pix一式をダウンロード
    (py38_gan) PS > cd /anaconda_win/work/
    (py38_gan) PS > git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git
    ▼「git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git」ログ

  2. 学習済みモデルのダウンロード

    Linux 環境の場合
    bash ./scripts/download_cyclegan_model.sh style_ukiyoe
    bash ./scripts/download_cyclegan_model.sh style_monet
    bash ./scripts/download_cyclegan_model.sh style_cezanne
    bash ./scripts/download_cyclegan_model.sh style_vangogh
    Windows 環境の場合
    ・上記の『事前準備』でダウンロードしたファイルを解凍し「work/」フォルダ以降を上書き配置する

    学習済みモデルの場所 → 「checkpoints/style_XXXXXXX_pretrained/latest_net_G.pth」
  1. 「CycleGan」実行に必要な不足しているパッケージをインストール
    (py38_gan) PS > pip install dominate visdom
    ▼「pip install dominate visdom」ログ

CycleGan の実行

準備

  1. 「py38_gan」 仮想環境下で実行する(異なる環境の場合、下記コマンドでアクティベートする)
    conda activate py38_gan

  2. カレントディレクトリを移動する
    (py38_gan) PS > cd /anaconda_win/work/pytorch-CycleGAN-and-pix2pix/

  3. 入力画像「datasets/images/」


  4. 出力(結果)画像「results/style_XXXXXXXX_pretrained/test_latest/images/」(コマンド実行後に作成される)
    「results/style_XXXXXXXX_pretrained/test_latest/index.html」ファイルにより Webブラウザ上で入出力画像の一覧を見ることができる

浮世絵風

モネ風

セザンヌ風

ゴッホ風

発生したエラーと対処法法

AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

 

更新履歴

参考資料

 

Last-modified: 2023-12-17 (日) 04:12:52