Stable Diffusion
動かしてみた
https://colab.research.google.com/drive/1MfdRXDDp87ESv0DxlK-AKV3K-MiWZ4Gr#scrollTo=ybBrSLbn1Mbk
https://gammasoft.jp/blog/simple-way-to-try-stable-diffusion/
モデルを差し替えるにはいくつかのやり方がある(https://self-development.info/%E3%80%90stable-diffusion%E3%80%91anything-v5の利用方法/)
Stable Diffusion web UI(AUTOMATIC1111版)
Diffusers
モデルにはいくつか形式がある(ref: https://economylife.net/safetensors-ckpt-difference/ )
Safetensors 形式: こっちは安全。huggingface が推奨。読み込みも早い
ckpt 形式: こちらは実態が pickel なので任意コード実行できる。危ない
https://wikiwiki.jp/sd_toshiaki/モデルについて が参考になるかも。
Stable Diffusion web UI
https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl#scrollTo=R-xAdMA5wxXd で web ui が動いた。
https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl#scrollTo=R-xAdMA5wxXd で作業
https://qiita.com/peka2/items/fdef492bcae84580edf4 は目を通しておきたい
https://www.reddit.com/r/StableDiffusion/comments/zt8b7q/can_you_download_from_civitai_onto_colab_without/ によれば
webui の設定方法 https://gigazine.net/news/20220928-automatic1111-stable-diffusion-webui-settings/#6
https://wikiwiki.jp/sd_toshiaki/ も見ておくといい。日本語向け。
https://blogcake.net/chilloutmix-re-generic/#index_id4 にマージ方法がある。
https://blogcake.net/xyzplot/ xyz の説明
https://twitter.com/studiomasakaki イラスト生成ノウハウに詳しい人
https://iosworld.blog.2nt.com/blog-entry-558.html nsfw 特化のプロンプト
https://blogcake.net/civitai/ civitai でモデルの探し方
https://original-game.com/image-ai-model-list/#m_heading-0 おすすめモデルについて
https://note.com/code_wizardry/n/n9c48006e27c9 実写プロンプト
Sampler
DPM2 a Karras
DPM++ 2S a Karras←これが一番よさそう
DPM++ 2M Karras
DPM++ SDE Karras←これもよさそう
gradio が安定しない。wss がたびたび削除される。
paperspace というのも結構良さそう。colab の代替。
https://ludela.gitbook.io/paperspace-gradientdenovelairkaruwo8dorudenikasu/paperspace-gradientno
https://note.com/code_wizardry/n/n9c48006e27c9 におすすめプロンプトがある
ポジティブプロンプト
code:plaintext
(8k, RAW photo, best quality, masterpiece:1.2), High detail RAW color photo, professional photograph, cowboyshot, (realistic, photo realistic:1.37), ((best quality)), 1 girl, cinematic light, (finerly detailed face:1.2), (masterpiece:1.5), (best quality:1.2), (smiling:1.2), (looking at viewer:1.2), bowtie, (detailed maid:1.2)
ネガティブプロンプと
code:plaintext
paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, (backlight:1.2), double navel, mutad arms, hused arms, neck lace, analog, analog effects, (sunglass:1.4), nipples, nsfw, bad architecture
code:data.json
{
"enable_hr": true,
"denoising_strength": 0.5,
"firstphase_width": 0,
"firstphase_height": 0,
"hr_scale": 2.0,
"hr_upscaler": "Latent (bicubic antialiased)",
"hr_second_pass_steps": 0,
"hr_resize_x": 0,
"hr_resize_y": 0,
"prompt": "(8k, RAW photo, best quality, masterpiece:1.2), High detail RAW color photo, professional photograph, (realistic, photo realistic:1.37), ((best quality)), 1 girl, cinematic light, (finerly detailed face:1.2), (masterpiece:1.5), (best quality:1.2), (smiling:1.2), (looking at viewer:1.2), japanese, nipples, huge boobs, (nude, full body shot:1.5), kawaii, beautiful beach, beautiful detailed eyes, standing",
"styles": null,
"seed": -1,
"subseed": -1,
"subseed_strength": 0,
"seed_resize_from_h": -1,
"seed_resize_from_w": -1,
"sampler_name": "DPM++ 2S a Karras",
"batch_size": 5,
"n_iter": 1,
"steps": 40,
"cfg_scale": 7.0,
"width": 512,
"height": 768,
"restore_faces": true,
"tiling": false,
"do_not_save_samples": false,
"do_not_save_grid": false,
"negative_prompt": "paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, (backlight:1.2), double navel, mutad arms, hused arms, neck lace, analog, analog effects, (sunglass:1.4), bad architecture",
"eta": null,
"s_churn": 0.0,
"s_tmax": null,
"s_tmin": 0.0,
"s_noise": 1.0,
"override_settings": null,
"override_settings_restore_afterwards": true,
"script_args": [],
"sampler_index": "DPM++ 2S a Karras",
"script_name": null,
"send_images": true,
"save_images": true,
"alwayson_scripts": {}
}
スクリプト
code:python
import json
import requests
import io
import base64
from PIL import Image, PngImagePlugin
url = "https://b5983629344213d1c0.gradio.live"
from pathlib import Path
payload = json.loads(Path("data.json").read_text())
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
print(response.text)
r = response.json()
for idx, i in enumerate(r'images'):
image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)0)))
image.save(f"output{idx}.png")
exit()
for i in r'images':
image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)0)))
png_payload = {
"image": "data:image/png;base64," + i
}
response2 = requests.post(url=f'{url}/sdapi/v1/png-info', json=png_payload)
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add_text("parameters", response2.json().get("info"))
image.save('output.png', pnginfo=pnginfo)
Stable Diffusion はテキストをエンコードする構成要素を使って画像を生成している。それが CLIP。CLIP を差し替えることで生成される画像を変更できる。
CLIP は Settings から変更できる。 https://e-penguiner.com/stable-diffusion-quicksettings-list/
CLIP の説明: https://atmarkit.itmedia.co.jp/ait/articles/2210/14/news035.html
Textual Inversion: 追加学習。短いテキストでプロンプトをかける。
https://blogcake.net/easynegative/#:~:text=Textual%20Inversionとは%EF%BC%9F,-画像引用元&text=Textual%20Inversionは%E3%80%81モデルに,ことで適用できます%E3%80%82
sd-scripts による追加学習のさせ方: https://github.com/kohya-ss/sd-scripts/blob/main/train_README-ja.md
diffusers というのがある。
controlnet はポーズなどを指摘できる便利なやつ。1.1をインストール https://kurokumasoft.com/2023/04/19/controlnet-new-features/
/work4ai/ControlNet 1.1
#StableDiffusion