TadaoYamaokaの開発日記

個人開発しているスマホアプリや将棋AIの開発ネタを中心に書いていきます。

stable-diffusion-webuiをWSL2で動かす その2

昨日導入方法を書いたstable-diffusion-webuiにGFPGANとRealESRGANを導入する。

GFPGANは、顔を改善するモデルで、RealESRGANは解像度2倍にするモデルである。
それぞれ適用した場合の比較画像は、公式のページにサンプルがある。
GitHub - hlky/stable-diffusion-webui: Stable Diffusion web UI

ライブラリインストール

GFPGANとRealESRGANに必要になるライブラリをインストールする。
バージョン不整合を防ぐために、以前のpipでインストールしたライブラリも再度同時にインストールする。

pip install diffusers transformers scipy ftfy invisible-watermark gradio pynvml omegaconf pytorch_lightning realesrgan basicsr

モデルダウンロード

GFPGAN
cd ~/stable-diffusion
mkdir -p src/gfpgan/experiments/pretrained_models
cd src/gfpgan/experiments/pretrained_models
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth
RealESRGAN
cd ~/stable-diffusion
mkdir -p src/realesrgan/experiments/pretrained_models
cd src/realesrgan/experiments/pretrained_models
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth

起動確認

cd ~/stable-diffusion
python webui.py

初回はモデルのダウンロードに少し時間がかかる。

/home/kei/anaconda3/envs/stable-diffusion/lib/python3.9/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.
  warnings.warn(
/home/kei/anaconda3/envs/stable-diffusion/lib/python3.9/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=None`.
  warnings.warn(msg)
Downloading: "https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth" to /home/kei/anaconda3/envs/stable-diffusion/lib/python3.9/site-packages/facexlib/weights/detection_Resnet50_Final.pth

100%|████████████████████████████████████████████████████████████████████| 104M/104M [00:12<00:00, 8.72MB/s]
Downloading: "https://github.com/xinntao/facexlib/releases/download/v0.2.2/parsing_parsenet.pth" to /home/kei/anaconda3/envs/stable-diffusion/lib/python3.9/site-packages/facexlib/weights/parsing_parsenet.pth

100%|██████████████████████████████████████████████████████████████████| 81.4M/81.4M [00:07<00:00, 11.4MB/s]
Loaded GFPGAN
Loaded RealESRGAN with model RealESRGAN_x4plus
Loading model from models/ldm/stable-diffusion-v1/model.ckpt
Global Step: 470000
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
/home/kei/anaconda3/envs/stable-diffusion/lib/python3.9/site-packages/gradio/deprecation.py:43: UserWarning: You have unused kwarg parameters in Button, please remove them: {'full_width': True}
  warnings.warn(
Running on local URL:  http://localhost:7860/

To create a public link, set `share=True` in `launch()`.

ブラウザでhttp://localhost:7860/にアクセスする。

Advancedタブから、「Fix faces using GFPGAN」及び「Upscale images using RealESRGAN」が選べるようになっている。

まとめ

stable-diffusion-webuiにGFPGANとRealESRGANを導入する方法について記載した。
生成画像が良くないと適用しても印象は変わらないので、元画像で良い画像がでるようにするにはプロンプトで頑張らないといけなそうである。