Supershipの名畑です。8月28日発売の総特集 松苗あけみが楽しみすぎます。ぶ~け作品の数々は今でも私の心の重要な部分を占めています。
はじめに
6月23日にStable Diffusionの新モデルであるSDXL 0.9がリリースされました
この新モデルで生成した画像と過去のモデルで生成した画像にどのような差が出るのかを試してみたので共有いたします。
アカウント作成やAPI呼び出しなどの基本的なことは過去記事「Stable Diffusionでの画像生成をPythonとWeb APIで実装してみた記録」をぜひご覧ください。
参考:画像生成AI「Stable Diffusion」最高性能の新モデル「SDXL 0.9」一般的なPCで実行可能
対象engine_id
今回は
- Stable Diffusion XL v0.9(SDXL 0.9 / 2023年6月23日リリース)
- Stable Diffusion XL Beta v2.2.2(SDXL Beta / 2023年4月13日リリース)
- Stable Diffusion v2.1(SD 2.1 / 2022年12月7日リリース)
この3つを比較していきます。
SDXL 0.9が最新で、SDXL Betaがその一つ前、SD 2.1がさらに一つ前です。
コード
今回の比較のために用いたPythonのコードは下記です。engine_idを切り替えながら、いくつかのプロンプトで試しました。
画風が違うと比較が難しいためstyle_presetも指定するようにしました。全部で8つのプロンプトを試したのですが、前半3つがanime、次の1つがfantasy-art、後半4つがphotographicです
import base64
import os
import requests
import time
engine_id = "stable-diffusion-xl-1024-v0-9" # SDXL 0.9
# engine_id = "stable-diffusion-xl-beta-v2-2-2" # SDXL Beta
# engine_id = "stable-diffusion-512-v2-1" # SD 2.1
api_host = os.getenv('API_HOST', 'https://api.stability.ai')
api_key = os.getenv("STABILITY_API_KEY")
# API Keyの取得確認
if api_key is None:
raise Exception("Missing Stability API key.")
# API呼び出し
response = requests.post(
f"{api_host}/v1/generation/{engine_id}/text-to-image",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
},
json={
"Samples": 3,
"style_preset": "anime",
"text_prompts": [
{
"text": "Japanese moe heroine"
}
],
},
)
# レスポンス確認
if response.status_code != 200:
raise Exception("Non-200 response: " + str(response.text))
# レスポンス取得
data = response.json()
# 画像保存
# ファイル名にはタイムスタンプとengine_id、通番を含めています
# 通番は0〜samplesの値 - 1
for i, image in enumerate(data["artifacts"]):
with open(f"./{engine_id}_{int(time.time())}_{i}.png", "wb") as f:
f.write(base64.b64decode(image["base64"]))
結果
ここから結果です。
8つのプロンプトにつきまして、SD 2.1 → SDXL Beta → SDXL 0.9の順番で3枚ずつ生成画像を並べていきます。つまり旧 → 新です。
結論から述べてしまうと、新しいモデルほど
- 高品質
- 違和感が少ない
と感じました。
主観でしかないですが、新しいモデルほど「プロンプトを正確に汲み取っている」「自然な絵/写真に近づいている」という印象です。
日本の萌えヒロイン
「日本の萌えヒロイン(Japanese moe heroine)」をanime指定で生成してみます。
"style_preset": "anime",
"text_prompts": [
{
"text": "Japanese moe heroine"
}
],
SD 2.1
まずはSD 2.1の結果です。少し懐かしい感じの画像たちが生成されました。



SDXL Beta
続いてSDXL Betaの結果です。画風がより現代に近づいたかもしれませんが、武器や髪型や腕など、明らかに不自然ですね。



SDXL 0.9
最後にSDXL 0.9です。現代深夜アニメに彼女たちが登場しても違和感がなさそう。



日本の人気アニメに登場するスイーツ
次は「日本の人気アニメに登場するスイーツ(Sweets that appear in popular Japanese anime)」です。
"style_preset": "anime",
"text_prompts": [
{
"text": "Sweets that appear in popular Japanese anime"
}
],
SD 2.1
プロンプトに対して忠実かはともかく、個人的にはこれはこれで好き。



SDXL Beta
「スイーツ」というより「スイーツっぽい」ですね。概念としてはスイーツ。
3枚目がカオスで好き。



SDXL 0.9
日本のアニメにはなかなか登場しづらそうな種類のスイーツではありますが、クオリティ高いですね。
あと、SDXL 0.9は色合い等から受ける印象が現代風と感じます。



修学旅行中の男子高校生
続いて「修学旅行中の男子高校生(Male high school student on a school trip)」です。
"style_preset": "anime",
"text_prompts": [
{
"text": "Male high school student on a school trip"
}
],
SD 2.1
「果たして修学旅行とは?」と考えてしまう絵もありますね。やっぱり昔のモデルになればなるほど、全体的にはそれっぽいのですが、身につけているものだとかをピンポイントで見ると明らかにおかしかったりしますね。



SDXL Beta
修学旅行感は薄いですね。休日や放課後みたい。まあ、いまどきの男子高校生の休日も放課後も私からしたら未知の世界ですが。



SDXL 0.9
かなり修学旅行中っぽくなりましたね。ただ、通学中と言われればそれっぽいし、買い物中と言われてもそれっぽいので、そもそも私のプロンプトが抽象的過ぎただけですね。



ギターを演奏するお姫様
次は「ギターを演奏するお姫様(A princess playing guitar)」です。
fantasy-artを指定してみました。
"style_preset": "fantasy-art",
"text_prompts": [
{
"text": "A princess playing guitar"
}
],
SD 2.1
ギターが安定しませんね。



SDXL Beta
童話の挿絵等に出てきそうです。



SDXL 0.9
リアル要素が強めになりました。
絵の良し悪しは好みによるところも多分にあるとは思いますが、最新のモデルになるほどに、いわゆる現代的に上手な絵とされるものに近づいている感は受けます。



ノートパソコン上の可愛い妖精
「ノートパソコン上の可愛い妖精(A cute fairy on top of a white laptop)」です。妖精が実在しないという前提に立つのであれば、現実にはありえないものです。
また、ここからはphotographicを指定しています。
"style_preset": "photographic",
"text_prompts": [
{
"text": "A cute fairy on top of a white laptop"
}
],
SD 2.1
いわゆる可愛いではないかな……。



SDXL Beta
私のイメージする可愛いに近づきました。3枚目は心霊写真味がありますが。



SDXL 0.9
3枚目は腕の辺りの違和感強めですが、全体としてナチュラルな妖精になったと感じます。
本物の妖精を見たことないからナチュラルもなにもないっちゃないですが。



黒いボブヘアで可愛い28歳の日本人女性
私のQiita記事でよく使うプロンプト「黒いボブヘアで可愛い28歳の日本人女性(28-year-old Japanese pretty woman with black bobbed hair)」です。
"style_preset": "photographic",
"text_prompts": [
{
"text": "28-year-old Japanese pretty woman with black bobbed hair"
}
],
SD 2.1
これも主観ではありますが可愛いというよりは、違う形容詞をイメージする画像ですね。



SDXL Beta
メイクがナチュラルになりましたね。



SDXL 0.9
写真としてかなり質が向上したと感じます。前の写真が素人によるもので、これらの写真は玄人によるもの、みたいな。
サンプル数少ないのでたまたまかもしれませんが、髪型も統一感ありますね。



1980年代の香港の繁華街
人ではなく景色を生成してみましょう。「1980年代の香港の繁華街(Hong Kong downtown in the 1980s)」です。ちなみに私は香港には行ったことはありますが2010年代です。
"style_preset": "photographic",
"text_prompts": [
{
"text": "Hong Kong downtown in the 1980s"
}
],
SD 2.1
なんとも言いづらい。1980年代にテレビでよく見たジオラマはこんなだった気がする。



SDXL Beta
どうでしょうか。もうちょっと雑多な方が現実に近いですかね。



SDXL 0.9
1980年代より少し前の1970年代の写真っぽさありますね。



2020年の新宿歌舞伎町
これで最後です。「2020年の新宿歌舞伎町(Shinjuku Kabukicho in 2020)」です。
"style_preset": "photographic",
"text_prompts": [
{
"text": "Shinjuku Kabukicho in 2020"
}
],
SD 2.1
かなり雰囲気出ていると思いますが、やっぱり描画される文字はどうしても原理的にそれっぽいに留まりますね。



SDXL Beta
これも主観でしかないですが新宿らしさは増した気がします。



SDXL 0.9
なんかちょっとくすんだ感じになってしまったでしょうか。他の写真が全体的にキラキラし過ぎているのかもしれませんが。



おまけ engine_id一覧
指定可能なengine_idのリストはenginesのlist APIで取得可能です。現時点でのリストを貼っておきます
[
{
"description": "Real-ESRGAN_x2plus upscaler model",
"id": "esrgan-v1-x2plus",
"name": "Real-ESRGAN x2",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion XL v0.9",
"id": "stable-diffusion-xl-1024-v0-9",
"name": "Stable Diffusion XL v0.9",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion v1.4",
"id": "stable-diffusion-v1",
"name": "Stable Diffusion v1.4",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion v1.5",
"id": "stable-diffusion-v1-5",
"name": "Stable Diffusion v1.5",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion v2.0",
"id": "stable-diffusion-512-v2-0",
"name": "Stable Diffusion v2.0",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion 768 v2.0",
"id": "stable-diffusion-768-v2-0",
"name": "Stable Diffusion v2.0-768",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion Depth v2.0",
"id": "stable-diffusion-depth-v2-0",
"name": "Stable Diffusion v2.0-depth",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion v2.1",
"id": "stable-diffusion-512-v2-1",
"name": "Stable Diffusion v2.1",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion 768 v2.1",
"id": "stable-diffusion-768-v2-1",
"name": "Stable Diffusion v2.1-768",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Diffusion XL Beta v2.2.2",
"id": "stable-diffusion-xl-beta-v2-2-2",
"name": "Stable Diffusion v2.2.2-XL Beta",
"type": "PICTURE"
},
{
"description": "Stable Diffusion x4 Latent Upscaler",
"id": "stable-diffusion-x4-latent-upscaler",
"name": "Stable Diffusion x4 Latent Upscaler",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Inpainting v1.0",
"id": "stable-inpainting-v1-0",
"name": "Stable Inpainting v1.0",
"type": "PICTURE"
},
{
"description": "Stability-AI Stable Inpainting v2.0",
"id": "stable-inpainting-512-v2-0",
"name": "Stable Inpainting v2.0",
"type": "PICTURE"
}
]
最後に
7月中旬にはSDXL 1.0がリリースされる予定らしいですし、この進化スピードで行くと年内でどこまで到達しているのか読めないですね。
宣伝
SupershipのQiita Organizationを合わせてご覧いただけますと嬉しいです。他のメンバーの記事も多数あります。
Supershipではプロダクト開発やサービス開発に関わる方を絶賛募集しております。
興味がある方はSupership株式会社 採用サイトよりご確認ください。