【Stable Diffusion】Hentai Diffusion 20の利用方法

【Stable Diffusion】Hentai Diffusion 20の利用方法 機械学習

「Hentai Diffusion 19と20の違いがわからない・・・」
「Hentai Diffusion 20はどこがどう変わったの?」

このような場合には、この記事の内容が参考になります。
この記事では、Hentai Diffusion 20を利用する方法を解説しています。

本記事の内容

  • Hentai Diffusion 20とは?
  • Hentai Diffusion 20の利用方法
  • Hentai Diffusion 20の動作検証

それでは、上記に沿って解説していきます。

Hentai Diffusion 20とは?

Hentai Diffusion 20が、2023年1月21日に公開されました。
2023年1月初旬にHentai Diffusion 19が公開されています。

Hentai Diffusionシリーズは、19から大きく路線変更しています。
技術的なこと以上に、運営形式の変更が大きかったようです。
詳細は、次の記事で説明しています。

今回も半月で新たなバージョンがリリースされています。
それだけ日々モデルがレベルアップしているということでしょう。

そのレベルアップを示すモノとして、Hentai Diffusion 20ではEmbedsが採用されています。
Textual Inversionと表現した方が、わかりやすいかもしれません。

Embedsにより、スタイルを大きく変更することが可能になります。
それ以外は、公式ページでも特に説明がありません。

このあたりは、実際に動作検証して確認するしかないでしょうね。

以上、Hentai Diffusion 20について説明しました。
次は、Hentai Diffusion 20の利用方法を説明します。

Hentai Diffusion 20の利用方法

モデルのダウンロードは、公式ページから可能です。
https://www.cognitionai.org/hdhowtogetstarted

「Download」ボタンをクリックすると、ファイルのダウンロードが始まります。

上記ファイルは、Hugging Faceのページでも公開されています。
https://huggingface.co/Deltaadams/HD-20/tree/main

「HD-20.ckpt」をダウンロードできたら、このファイルを必要な場所に設置します。
利用方法については、それぞれの環境で異なります。

  • Stable Diffusion web UI(AUTOMATIC1111版)
  • Diffusers

Stable Diffusion web UI(AUTOMATIC1111版)

OS環境を汚さないインストール方法を次の記事で説明しています。
OS依存のPythonを利用しない方法のため、安心してインストールできます。

「HD-20.ckpt」は、Stable Diffusion v1-5ベースです。
そのため、指定のディレクトリにファイルを設置するだけで済みます。
YAMLファイルは不要です。

設置して反映できたら、Hentai Diffusion 20が利用可能になります。

Diffusers

Diffusersの場合は、少し工夫が必要となります。
まずは、Stable Diffusionを動かせることが前提となります。

上記記事に従えば、自ずとDiffusersをインストールしています。

ここで工夫が必要となります。
ダウンロードしたcheckpointをDiffusersで読み込める形式に変換します。
変換方法は、次の記事で説明しています。

今回であれば、次のようなコマンドを用いました。
パスなどは、各自の環境に合わせてください。

python convert_diffusers20_original_sd.py ..\..\ckpt\HD-20.ckpt ..\..\model\HD-20   --v1 --reference_model runwayml/stable-diffusion-v1-5

変換までできたら、次のコードを実行します。

from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler
import torch

MODEL_ID = "./model/HD-20"
DEVICE = "cuda"
SEED = 1089107484

pipe = StableDiffusionPipeline.from_pretrained(MODEL_ID, custom_pipeline="lpw_stable_diffusion")
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to(DEVICE)

prompt = "best quality, {{{nsfw}}}, {{{masterpiece}}}, 1girl, monika \(doki doki literature club\, (breasts:0.984), (brown hair:0.989), (cleavage:0.586), (collarbone:0.746), (eyebrows visible through hair:0.732), (green eyes:0.944), (long hair:0.982), (ponytail:0.741), winter clothes, winter coat, portrait, from side"
negative_prompt = "(((deformed))), blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, (extra_limb), (ugly), (poorly drawn hands), fused fingers, messy drawing, broken legs censor, censored, censor_bar, multiple breasts, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), black-white, bad anatomy, liquid body, liquidtongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, low res, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missingbreasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fusedears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquidanimal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers, one hand with more than 5 fingers, one hand with less than5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, colorful tongue, blacktongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game, 3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawnfeet, fused feet, missing feet, extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves, fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly, bad face, fused face, poorly drawn face, cloned face, big face, long face, badeyes, fused eyes poorly drawn eyes, extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples, poorly drawnnipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs, missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand, more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs, extra calf,fused calf, extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth, fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too longtongue, black tongue, big mouth, cracked mouth, bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, badpantie, yellow teeth, thick lips, bad camel toe, colorful camel toe, bad asshole, poorly drawn asshole, fused asshole, missing asshole, bad anus, bad pussy, bad crotch, badcrotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch, fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorlydrawn crotch seam, bad thigh gap, missing thigh gap, fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone, liquid collarbone, strong girl, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles, split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored, safety panties, safety knickers, beard, furry, pony, pubic hair, mosaic, futa, testis, (((deformed))), blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, (extra_limb), (ugly), (poorly drawn hands), fused fingers, messy drawing, broken legs censor, censored, censor_bar, multiple breasts, (mutated hands and fingers:1.5), (long body :1.3), (mutation, poorly drawn :1.2), black-white, bad anatomy, liquid body, liquidtongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, low res, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missingbreasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fusedears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquidanimal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers, one hand with more than 5 fingers, one hand with less than5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, colorful tongue, blacktongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game, 3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawnfeet, fused feet, missing feet, extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves, fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly, bad face, fused face, poorly drawn face, cloned face, big face, long face, badeyes, fused eyes poorly drawn eyes, extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples, poorly drawnnipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs, missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand, more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs, extra calf,fused calf, extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth, fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too longtongue, black tongue, big mouth, cracked mouth, bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, badpantie, yellow teeth, thick lips, bad camel toe, colorful camel toe, bad asshole, poorly drawn asshole, fused asshole, missing asshole, bad anus, bad pussy, bad crotch, badcrotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch, fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorlydrawn crotch seam, bad thigh gap, missing thigh gap, fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone, liquid collarbone, strong girl, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles, split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored, safety panties, safety knickers, beard, furry, pony, pubic hair, mosaic, futa, testis"

# seed固定
generator = torch.Generator(device=DEVICE).manual_seed(SEED)

image = pipe(
    prompt,
    num_inference_steps=140,
    guidance_scale=7.5,
    width=512,
    height=768,
    negative_prompt=negative_prompt,
    generator=generator,
    max_embeddings_multiples=6
).images[0]

image.save("test.png")

実行した結果、次のような画像が生成されます。

Hentai Diffusion 19で利用したコードを流用しています。
違いは、モデルのパスだけです。

ステップ数140は、公式ページのプロンプトを参考にしています。
実際は、40程度でも十分でしょう。

コード上では、seedの固定と長いプロンプトに対応する処理が含まれています。
それらの方法については、次の記事で説明しています。

以上、Hentai Diffusion 20の利用方法を説明しました。
次は、Hentai Diffusion 20の動作検証を説明します。

Hentai Diffusion 20の動作検証

左からHentai Diffusion18,19,20で生成した画像になります。

なるべく似ている画像を選んでいます。
みなさんに見てほしいのは、色の彩度です。

18は、淡いぼやけた感じになっています。
19は、そのぼやけた感じがなくなってクリアになった感じです。
20は、18と19の中間のような印象を受けます。

色の専門家ではないので、正確なところはわかりません。
ただ、バージョン毎に試行錯誤していることがわかります。
そこに、より良いモノを追求する姿勢を感じます。

他にも変化はあるでしょうが、Hentai Diffusion 20ではEmbedsが新たに取り入れられています。
これを検証してみましょう。

まず、Embedsのファイルをダウンロードします。
https://huggingface.co/Deltaadams/ignoremepls/tree/main

ptファイルをすべてダウンロードしましょう。
そして、Stable Diffusion web UI(AUTOMATIC1111版)の指定ディレクトリにそれらを設置します。

web UIの起動時コンソールに次のように表示されれば、読み込みOK。

ベースとなるプロンプトは、以下を利用。

best quality, {{{masterpiece}}}, 1girl, perfect body, leaf hair, black turtleneck, autumn background, a short white skirt, standing

スタイルを適用させるには、プロンプト末尾に「, A1」、「, A2」、「, A3」、「, A4」を追加します。
そうやって作成した画像(同じSEEDで比較可能)が、以下。

左から、Embedsなし、A1、A2、A3、A4を適用して作成した画像になります。
イマイチ、A1とA2の世界観がわかりません。

まあ、上手く適用はできているようです。
個人的には、A4がいいですね。

以上、Hentai Diffusion 20の動作検証を説明しました。

タイトルとURLをコピーしました