金子邦彦研究室人工知能Windows で動く人工知能関係 Pythonアプリケーション,オープンソースソフトウエア)ImaginAIry のインストールと動作確認(画像合成,画像編集,Prompt Based Masking,Image to Image)(Stable Diffusion,InstructPix2Pix,Stable Diffusion 2 Depth,Python を使用)(Windows 上)

ImaginAIry のインストールと動作確認(画像合成,画像編集,Prompt Based Masking,Image to Image)(Stable Diffusion,InstructPix2Pix,Stable Diffusion 2 Depth,Python を使用)(Windows 上)

ImaginAIry は,Python から stable diffusion 画像の生成を扱う機能を持ったソフトウエア.

目次

  1. 前準備
  2. ImaginAIry のインストール(Python,pip を使用)(Windows 上)
  3. 動作確認のため動かしてみる(Windows 上)

    サイト内の関連ページ

    Ubuntu について: 別ページ »で説明

    関連する外部ページ

    ImaginAIry の GitHub のページ: https://github.com/brycedrennan/imaginAIry

前準備

Git のインストール(Windows 上)

Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.

サイト内の関連ページ

Windows での Git のインストール: 別ページ »で説明している.

関連する外部ページ

Git の公式ページ: https://git-scm.com/

Python のインストール(Windows 上)

サイト内の関連ページ

関連する外部ページ

Python の公式ページ: https://www.python.org/

Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN 8.6 のインストール(Windows 上)

サイト内の関連ページ

NVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバNVIDIA CUDA ツールキットNVIDIA cuDNN のインストールを行う.

関連する外部ページ

PyTorch のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. PyTorch のページを確認

    PyTorch のページ: https://pytorch.org/index.html

  3. 次のようなコマンドを実行(実行するコマンドは,PyTorch のページの表示されるコマンドを使う).

    次のコマンドは, 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())" 
    

    [image]

    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())" 
    

    サイト内の関連ページ

    関連する外部ページ

ImaginAIry のインストール(Python,pip を使用)(Windows 上)

  1. Windows で,コマンドプロンプト管理者として実行

    コマンドプロンプトを管理者として実行: 別ページ »で説明

  2. インストール

    python -m pip install -U imaginairy
    

    [image]
  3. 関連ファイルをダウンロード

    cd %HOMEPATH%
    rmdir /s /q imaginAIry
    git clone --recursive https://github.com/brycedrennan/imaginAIry
    

    [image]

動作確認のため動かしてみる(Windows 上)

https://github.com/brycedrennan/imaginAIry の手順に従う.

テキストからの画像生成(Stable Diffusion を使用)

Windows で,コマンドプロンプト管理者として実行

次を実行することにより,画像ファイルが生成される.画像ファイル名が表示されるので確認.

imagine "海沿いを走る"

[image]

[image]
imagine "a scenic landscape"

[image]

[image]

テキストからの画像生成,Stable Diffusion のバージョンを 2.1 に指定

Windows で,コマンドプロンプト管理者として実行

次を実行することにより,画像ファイルが生成される.画像ファイル名が表示されるので確認.

imagine --model SD-2.1 "海沿いを走る"

[image]

[image]
imagine --model SD-2.1 "a scenic landscape"

[image]

[image]

画像編集(InstructPix2Pix を使用)

InstructPix2Pix を使用している

InstructPix2Pix の GitHub のページ: https://github.com/timothybrooks/instruct-pix2pix

Windows で,コマンドプロンプト管理者として実行

cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit scenic_landscape_winter.jpg "make a sky sunset"

[image]

元画像

[image]

画像編集の結果

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit 000032_337692011_PLMS40_PS7.5_a_photo_of_a_dog.jpg "make a dog white"

[image]

元画像

[image]

画像編集の結果

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit 000056_293284644_PLMS40_PS7.5_photo_of_a_bowl_of_fruit.jpg "make fruits vegetables"

[image]

元画像

[image]

画像編集の結果

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit spock.jpg "make a man long hair" --prompt-strength 20

[image]

元画像

[image]

画像編集の結果

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit spock.jpg "add glasses"

[image]

元画像

[image]

画像編集の結果

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
aimg edit spock.jpg "make color tropical"

[image]

元画像

[image]

画像編集の結果

[image]

Prompt Based Masking(clipseg を使用)

clipseg を使用している.

clipseg の GitHub のページ: https://github.com/timojl/clipseg

Windows で,コマンドプロンプト管理者として実行

cd %HOMEPATH%
cd imaginAIry
cd assets
imagine ^
    --init-image girl_with_a_pearl_earring.jpg ^
    --mask-prompt "face AND NOT (bandana OR hair OR blue fabric){*6}" ^
    --mask-mode keep ^
    --init-image-strength .2 ^
    --fix-faces ^
   "a young girl" "an old lady" "white dressed" "fireman"

[image]

元画像

[image]

Prompt Based Masking の結果

[image]

[image]

[image]

[image]
cd %HOMEPATH%
cd imaginAIry
cd assets
imagine ^
    --init-image 000056_293284644_PLMS40_PS7.5_photo_of_a_bowl_of_fruit.jpg ^
     --mask-prompt "fruit OR fruit stem{*6}" ^
    --mask-mode replace ^
    --mask-modify-original ^
    --init-image-strength .1 ^
    "ball" "animal doll" "soup" "rice" "candy" "pencil" 

[image]

元画像

[image]

Prompt Based Masking の結果

[image]

[image]

[image]

[image]

[image]

[image]

Image-to-Image(Stable Diffusion 2 Depth を使用)

Stable Diffusion 2 Depth を使用している.

Windows で,コマンドプロンプト管理者として実行

cd %HOMEPATH%
cd imaginAIry
cd assets
imagine --model SD-2.0-depth --init-image mona-lisa.jpg --init-image-strength 0.05  "professional headshot photo of a woman" -r 4 -w 1024 -h 1024 --steps 50

[image]

[image]

[image]

[image]

[image]

[image]