私的AI研究会 > AI_Program3

生成 AI プログラミング3

image_040_m.jpg

 これまで検証してきた結果をもとに、Python で生成 AI プログラムを書く

▲ 目 次
※ 最終更新:2025/07/15 

diffusersではじめめる Stable Diffusion (応用編2)

 画像から画像を生成する instruct-pix2pixcontrolnet instruct-pix2pix

 参考サイト:instruct-pix2pixで画像を指示した通り変更したり

概要

動作環境

Step 40:「instruct-pix2pix」で画像を変換する

  1. プログラムを実行する  SD1.5モデル  (実行時間:約 3秒 RTX 4070 Ti 12GB)
     python sd_040.py
     生成画像(左) image_040.png 元になる画像(右) sd_040_test.png
    (sd_test) > python sd_040.py
    
    Stable Diffusion with diffusers(040)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_040.png
     --cpu                      :   False
     --log                      :   3
     --model_path               :   timbrooks/instruct-pix2pix
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   雪の中の場面にする
     --seed                     :   0
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --image_scale              :   1.5
    
    prompt: Make it a scene in the snow
    width: 512, height: 512
    seed: 0
    Loading pipeline components...: 100%|████████████| 7/7 [00:02<00:00,  2.97it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.75it/s]
    result_file: results/image_040.png
    
    Finished.
  2. 画像ファイル「image_040.png」が生成される

  3. プログラムを実行する  SDXLモデル  (実行時間:約 8秒 RTX 4070 Ti 12GB)
     python sd_040.py --model_path 'diffusers/sdxl-instructpix2pix-768' --width 768 --height 768 --result_image 'results/image_040a.png'
     生成画像 image_040a.png 元になる画像は同じ sd_040_test.png
    (sd_test) PS > python sd_040.py --model_path 'diffusers/sdxl-instructpix2pix-768' --width 768 --height 768 --result_image 'results/image_040a.png'
    
    Stable Diffusion with diffusers(040)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_040a.png
     --cpu                      :   False
     --log                      :   3
     --model_path               :   diffusers/sdxl-instructpix2pix-768
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   雪の中の場面にする
     --seed                     :   0
     --width                    :   768
     --height                   :   768
     --step                     :   20
     --scale                    :   7.0
     --image_scale              :   1.5
    
    prompt: Make it a scene in the snow
    width: 768, height: 768
    seed: 0
    Loading pipeline components...: 100%|████████████| 7/7 [00:04<00:00,  1.67it/s]
    100%|██████████████████████████████████████████| 20/20 [00:03<00:00,  5.27it/s]
    result_file: results/image_040a.png
    
    Finished.
  4. 画像ファイル「image_040a.png」が生成される

Step 41:「instruct-pix2pix」image_guidance_scale パラメータによる変化をみる

  1. プログラムを実行する  SD1.5モデル  (実行時間:約 12秒 RTX 4070 Ti 12GB)
     python sd_041.py
    (sd_test) PS > python sd_041.py
    
    Stable Diffusion with diffusers(041)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_041.png
     --cpu                      :   False
     --log                      :   3
     --model_path               :   timbrooks/instruct-pix2pix
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   雪の中の場面にする
     --seed                     :   0
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --image_scale              :   1.5
    
    prompt: Make it a scene in the snow
    width: 512, height: 512
    seed: 0
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  4.87it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 18.16it/s]
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  5.65it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 18.43it/s]
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  5.70it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 18.44it/s]
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  5.35it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.70it/s]
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  5.65it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 18.42it/s]
    Loading pipeline components...: 100%|████████████| 7/7 [00:01<00:00,  5.66it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 18.43it/s]
    result_file: results/image_041.png
    
    Finished.
  2. 画像ファイル「image_041.png」が生成される

  3. プログラムを実行する  SDXLモデル  (実行時間:約 42秒 RTX 4070 Ti 12GB)
     python sd_041.py --model_path 'diffusers/sdxl-instructpix2pix-768' --width 768 --height 768 --result_image 'results/image_041a.png'
    (sd_test) PS > python sd_041.py --model_path 'diffusers/sdxl-instructpix2pix-768' --width 768 --height 768 --result_image 'results/image_041a.png'
    
    Stable Diffusion with diffusers(041)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_041a.png
     --cpu                      :   False
     --log                      :   3
     --model_path               :   diffusers/sdxl-instructpix2pix-768
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   雪の中の場面にする
     --seed                     :   0
     --width                    :   768
     --height                   :   768
     --step                     :   20
     --scale                    :   7.0
     --image_scale              :   1.5
    
    prompt: Make it a scene in the snow
    width: 768, height: 768
    seed: 0
    Loading pipeline components...: 100%|█████████████| 7/7 [00:03<00:00,  1.76it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.36it/s]
    Loading pipeline components...: 100%|█████████████| 7/7 [00:04<00:00,  1.70it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.45it/s]
    Loading pipeline components...: 100%|█████████████| 7/7 [00:04<00:00,  1.73it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.44it/s]
    Loading pipeline components...: 100%|█████████████| 7/7 [00:04<00:00,  1.66it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.45it/s]
    Loading pipeline components...: 100%|█████████████| 7/7 [00:03<00:00,  1.80it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.44it/s]
    Loading pipeline components...: 100%|█████████████| 7/7 [00:03<00:00,  1.78it/s]
    100%|███████████████████████████████████████████| 20/20 [00:03<00:00,  5.45it/s]
    result_file: results/image_041a.png
    
    Finished.
  4. 画像ファイル「image_041a.png」が生成される

Step 42:「controlnet instruct-pix2pix」で画像を変換する

  1. プログラムを実行する(実行時間:約 2秒 RTX 4070 Ti 12GB)
     python sd_042.py
     生成画像(左) image_042.png 元になる画像(右) sd_040_test.png
    (sd_test) PS D:\anaconda_win\workspace_3\sd_test> python sd_042.py
    
    Stable Diffusion with diffusers(042)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_042.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11e_sd15_ip2p_fp16.safetensors
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   浜辺の場面にする
     --seed                     :   12345678
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --cc_scale                 :   1.0
    
    prompt: Set the scene on the beach
    width: 512, height: 512
    seed: 12345678
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 17.47it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 10.55it/s]
    result_file: results/image_042.png
    
    Finished.
  2. 画像ファイル「image_042.png」が生成される

  3. プロンプトを変えて生成する
    ・「python sd_042.py --prompt 'プロンプト'」
     python sd_042.py --prompt '雪の中の場面にする'
    ・ベースモデル「beautifulRealistic_brav5.safetensors(リアル系)」
    浜辺の場面にする雪の中の場面にする炎の中の場面にする森の中の場面にする山中の場面にする砂漠の場面にする
    image_042_m.jpg image_042_0_m.jpg image_042_1_m.jpg image_042_2_m.jpg image_042_3_m.jpg image_042_4_m.jpg
    着物姿に着替えるイラスト画像にするアニメ画像にする微笑んだ顔のアニメ画像泣き顔のアニメ画像にする嬉しそうな顔のアニメ画像
    image_042_5_m.jpg image_042_6_m.jpg image_042_7_m.jpg image_042_8_m.jpg image_042_9_m.jpg image_042_10_m.jpg
    ・ベースモデル「animePastelDream_softBakedVae.safetensors(イラスト系)」
    浜辺の場面にする雪の中の場面にする炎の中の場面にする森の中の場面にする山中の場面にする砂漠の場面にする
    image_042_ani_m.jpg image_042_ani_0_m.jpg image_042_ani_1_m.jpg image_042_ani_2_m.jpg image_042_ani_3_m.jpg image_042_ani_4_m.jpg
    着物姿に着替えるイラスト画像にするアニメ画像にする微笑んだ顔のアニメ画像泣き顔のアニメ画像にする嬉しそうな顔のアニメ画像
    image_042_ani_5_m.jpg image_042_ani_6_m.jpg image_042_ani_7_m.jpg image_042_ani_8_m.jpg image_042_ani_9_m.jpg image_042_ani_10_m.jpg

Step 43:「controlnet instruct-pix2pix」controlnet_conditioning_scale パラメータによる変化をみる

  1. プログラムを実行する(実行時間:約 6秒 RTX 4070 Ti 12GB)
     python sd_043.py
    (sd_test) PS D:\anaconda_win\workspace_3\sd_test> python sd_043.py
    
    Stable Diffusion with diffusers(043)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_043.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11e_sd15_ip2p_fp16.safetensors
     --image_path               :   images/sd_040_test.png
     --max_size                 :   0
     --prompt                   :   浜辺の場面にする
     --seed                     :   12345678
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --cc_scale                 :   1.0
    
    prompt: Set the scene on the beach
    width: 512, height: 512
    seed: 12345678
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 30.96it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 14.83it/s]
    Fetching 11 files: 100%|█████████████████████| 11/11 [00:00<00:00, 7498.35it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 33.70it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 17.03it/s]
    Fetching 11 files: 100%|████████████████████| 11/11 [00:00<00:00, 11016.56it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 33.90it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.16it/s]
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 21.80it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.25it/s]
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 33.68it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.56it/s]
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 34.80it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 16.98it/s]
    result_file: results/image_043.png
    
    Finished.
  2. 画像ファイル「image_043.png」が生成される

  3. モジュール・ソースコード
    ▼「sd_043.py」

Step 44:「controlnet inpaint」で画像の一部を変換する

sd_038_test_m.jpg
sd_038_test_mask_m.jpg
  1. プログラムを実行する(実行時間:約 1秒 RTX 4070 Ti 12GB)
     python sd_044.py
     マスク画像(左) sd_038_test_mask.png 元画像(右) sd_038_test.png
    (sd_test) PS > python sd_044.py
    
    Stable Diffusion with diffusers(044)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_044.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11p_sd15_inpaint_fp16.safetensors
     --image_path               :   images/sd_038_test.png
     --ctrl_image_path          :   images/sd_038_test_mask.png
     --max_size                 :   0
     --prompt                   :   微笑んでいる女性
     --seed                     :   12345678
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --cc_scale                 :   1.0
     --strength                 :   0.6
    
    prompt: Woman smiling
    width: 512, height: 512
    seed: 12345678
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 16.91it/s]
    100%|██████████████████████████████████████████| 12/12 [00:01<00:00, 10.44it/s]
    result_file: results/image_044.png
    
    Finished.
  2. 画像ファイル「image_044.png」が生成される

  3. プロンプトを変えて生成する
    ・「python sd_044.py --prompt 'プロンプト'」
     python sd_044.py --prompt '見つめている女性'
    ・元画像
    ・ベースモデル「beautifulRealistic_brav5.safetensors(リアル系)」
    微笑んでいる女性泣いている女性怒っている女性照れている女性見つめている女性笑っている女性
    image_044_m.jpg image_044_61_m.jpg image_044_62_m.jpg image_044_63_m.jpg image_044_64_m.jpg image_044_65_m.jpg
    目を瞑っている女性ウィンクしている女性苛立っている女性怖がっている女性驚いている女性疲れている女性
    image_044_66_m.jpg image_044_67_m.jpg image_044_68_m.jpg image_044_69_m.jpg image_044_70_m.jpg image_044_71_m.jpg
    ・ベースモデル「animePastelDream_softBakedVae.safetensors(イラスト系)」
    微笑んでいる女性泣いている女性怒っている女性照れている女性見つめている女性笑っている女性
    image_044_0_m.jpg image_044_1_m.jpg image_044_2_m.jpg image_044_3_m.jpg image_044_4_m.jpg image_044_5_m.jpg
    image_044_20_m.jpg image_044_21_m.jpg image_044_22_m.jpg image_044_23_m.jpg image_044_24_m.jpg image_044_25_m.jpg
    image_044_40_m.jpg image_044_41_m.jpg image_044_42_m.jpg image_044_43_m.jpg image_044_44_m.jpg image_044_45_m.jpg
    目を瞑っている女性ウィンクしている女性苛立っている女性怖がっている女性驚いている女性疲れている女性
    image_044_6_m.jpg image_044_7_m.jpg image_044_8_m.jpg image_044_9_m.jpg image_044_10_m.jpg image_044_11_m.jpg
    image_044_26_m.jpg image_044_27_m.jpg image_044_28_m.jpg image_044_29_m.jpg image_044_30_m.jpg image_044_31_m.jpg
    image_044_46_m.jpg image_044_47_m.jpg image_044_48_m.jpg image_044_49_m.jpg image_044_50_m.jpg image_044_51_m.jpg

Step 45:「controlnet inpaint」strength パラメータによる変化をみる

  1. プログラムを実行する(実行時間:約 5秒 RTX 4070 Ti 12GB)
     python sd_045.py
    (sd_test) PS > python sd_045.py
    
    Stable Diffusion with diffusers(045)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_045.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11p_sd15_inpaint_fp16.safetensors
     --image_path               :   images/sd_038_test.png
     --ctrl_image_path          :   images/sd_038_test_mask.png
     --max_size                 :   0
     --prompt                   :   微笑んでいる女性
     --seed                     :   12345678
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --cc_scale                 :   1.0
     --strength                 :   0.6
    
    prompt: Woman smiling
    width: 512, height: 512
    seed: 12345678
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 32.00it/s]
    100%|█████████████████████████████████████████████| 2/2 [00:00<00:00,  9.69it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 33.38it/s]
    100%|█████████████████████████████████████████████| 4/4 [00:00<00:00, 15.51it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 33.10it/s]
    100%|█████████████████████████████████████████████| 6/6 [00:00<00:00, 16.51it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 22.99it/s]
    100%|█████████████████████████████████████████████| 8/8 [00:00<00:00, 15.07it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 33.78it/s]
    100%|███████████████████████████████████████████| 10/10 [00:00<00:00, 15.35it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 33.54it/s]
    100%|███████████████████████████████████████████| 12/12 [00:00<00:00, 16.26it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 21.80it/s]
    100%|███████████████████████████████████████████| 14/14 [00:00<00:00, 15.63it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 34.68it/s]
    100%|███████████████████████████████████████████| 16/16 [00:00<00:00, 16.55it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 34.62it/s]
    100%|███████████████████████████████████████████| 18/18 [00:01<00:00, 16.38it/s]
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 33.47it/s]
    100%|███████████████████████████████████████████| 20/20 [00:01<00:00, 15.80it/s]
    result_file: results/image_045.png
    
    Finished.
  2. 画像ファイル「image_045.png」が生成される

Step 46:「outpaint」画像の外側を書き加える

  1. プログラムを実行する(実行時間:約 1秒 RTX 4070 Ti 12GB)
     python sd_046.py
    (sd_test) PS > python sd_046.py
    
    Stable Diffusion with diffusers(046)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_046.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11p_sd15_inpaint_fp16.safetensors
     --image_path               :   images/sd_046_test.png
     --max_size                 :   0
     --prompt                   :   庭に立って微笑んでいる女性
     --seed                     :   12345678
     --width                    :   512
     --height                   :   512
     --step                     :   20
     --scale                    :   7.0
     --cc_scale                 :   1.0
    
    prompt: Woman standing in a garden smiling
    width: 512, height: 512
    seed: 12345678
    Fetching 11 files: 100%|████████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|█████████████| 6/6 [00:00<00:00, 22.32it/s]
    100%|███████████████████████████████████████████| 20/20 [00:01<00:00, 11.69it/s]
    result_file: results/image_046.png
  2. 画像ファイル「image_046.png」が生成される

Step 47:「controlnet scribble」手描きの線画から画像を生成

  1. プログラムを実行する(実行時間:約 1秒 RTX 4070 Ti 12GB)
     python sd_047.py
     線画イラスト(左) sd_047.png 生成画像(右) image_047.png
    (sd_test) PS > python sd_047.py
    
    Stable Diffusion with diffusers(047)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_047.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/v1-5-pruned-emaonly.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11p_sd15_scribble_fp16.safetensors
     --image_path               :   images/sd_047.png
     --max_size                 :   0
     --prompt                   :   テーブル上の白いコーヒーカップ
     --seed                     :   12345678
     --step                     :   20
    
    prompt: White coffee cup on the table
    seed: 12345678
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:01<00:00,  5.70it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 10.11it/s]
    result_file: results/image_047.png
    
    Finished.
  2. 画像ファイル「image_047.png」が生成される

  3. プロンプトを変えて生成する
    ・「python sd_047.py ['プロンプト']」
     python sd_047.py --prompt '木製のテーブルの上に置かれた白いコーヒーカップ'
    ・ベースモデル「v1-5-pruned-emaonly.safetensors
    線画イラストテーブル上の白いコーヒーカップ木製のテーブルの上に置かれた白いコーヒーカップビーチに置かれたオレンジ色のコーヒーカップ
    sd_047_m.jpg image_047_m.jpg image_047_1_m.jpg image_047_2_m.jpg
    sd_047_1_m.jpg image_047_3_m.jpg image_047_4_m.jpg image_047_5_m.jpg
    sd_047_2_m.jpg image_047_6_m.jpg image_047_7_m.jpg image_047_8_m.jpg

Step 48:「controlnet openpose」画像から同じ姿勢の画像を生成

  1. 追加のパッケージをインストールする
    (sd_test) PS > pip install controlnet_aux
  2. プログラムを実行する(実行時間:約 2秒 RTX 4070 Ti 12GB)
     python sd_048.py
     推定された姿勢(左) sd_048_test1_pose.png 元画像(右) sd_048_test1.png
    (sd_test) PS > python sd_048.py
    
    Stable Diffusion with diffusers(048)  Ver 0.01: Starting application...
    
     --result_image             :   results/image_048.png
     --cpu                      :   False
     --log                      :   3
     --model_dir                :   /StabilityMatrix/Data/Models/StableDiffusion
     --model_path               :   SD1.5/beautifulRealistic_brav5.safetensors
     --ctrl_model_dir           :   /StabilityMatrix/Data/Models/ControlNet
     --ctrl_model_path          :   control_v11p_sd15_openpose_fp16.safetensors
     --image_path               :   images/sd_048_test1.png
     --max_size                 :   0
     --prompt                   :   ダンスを踊る女性
     --seed                     :   -1
     --step                     :   20
    
    prompt: Dancing Woman
    seed: 2142389556
    Fetching 11 files: 100%|███████████████████████████████| 11/11 [00:00<?, ?it/s]
    Loading pipeline components...: 100%|████████████| 6/6 [00:00<00:00, 15.00it/s]
    100%|██████████████████████████████████████████| 20/20 [00:01<00:00, 10.27it/s]
    result_file: results/image_048_2142389556.png
    
    Finished.
  3. 画像ファイル「image_048_2142389556.png」が生成される(ファイル名の末尾はシード値)

  4. シード値を指定して生成する
    ・「python sd_047.py --seed 'シード値(-1 = ランダム生成)'」
    (sd_test) PS > python sd_048.py --seed 1595966935
    ・ベースモデル「beautifulRealistic_brav5.safetensors(リアル系)」/「animePastelDream_softBakedVae.safetensors(イラスト系)」
    元画像推定姿勢生成画像①生成画像②生成画像③
    sd_048_test1_m.jpg sd_048_test1_pose_m.jpg image_048_r1_1595966935_m.jpg image_048_r1_2819990836_m.jpg image_048_r1_3393410450_m.jpg
    image_048_a1_160690119_m.jpg image_048_a1_371943037_m.jpg image_048_a1_1334114839_m.jpg
    sd_048_test2_m.jpg sd_048_test2_pose_m.jpg image_048_r2_932110098_m.jpg image_048_r2_1734112287_m.jpg image_048_r2_2491593200_m.jpg
    image_048_a2_205787808_m.jpg image_048_a2_851990563_m.jpg image_048_a2_2340211196_m.jpg
    sd_048_test3_m.jpg sd_048_test3_pose_m.jpg image_048_r3_453170158_m.jpg image_048_r3_1384310311_m.jpg image_048_r3_3938690490_m.jpg
    image_048_a3_0_m.jpg image_048_a3_693363384_m.jpg image_048_a3_861209932_m.jpg
 

忘備録

 

更新履歴

参考資料