Stable Diffusion
動かしてみた
Stable Diffusion web UI(AUTOMATIC1111版)
Diffusers
Safetensors 形式: こっちは安全。huggingface が推奨。読み込みも早い
ckpt 形式: こちらは実態が pickel なので任意コード実行できる。危ない
Sampler
DPM2 a Karras
DPM++ 2S a Karras←これが一番よさそう
DPM++ 2M Karras
DPM++ SDE Karras←これもよさそう
gradio が安定しない。wss がたびたび削除される。
paperspace というのも結構良さそう。colab の代替。
ポジティブプロンプト
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
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()
image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)0))) image.save(f"output{idx}.png")
exit()
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 を差し替えることで生成される画像を変更できる。
Textual Inversion: 追加学習。短いテキストでプロンプトをかける。
diffusers というのがある。