Stable Diffusion XL 1.0 (SDXL 1.0) のインストール,画像生成(img2txt),画像変換(img2img),APIを利用して複数画像を一括生成(AUTOMATIC1111,Python,PyTorch を使用)(Windows 上)

要約】 AUTOMATIC1111は、PythonとPyTorchを使用したテキストから画像を生成するWebUIを提供。Windows上で動作し、GitHubからダウンロードできる。インストール後は http://127.0.0.1:7860 でアクセスし、学習済みモデルを選択して利用可能。また、SDXL(画像生成モデル)も提供されている。AUTOMATIC1111 の公式ページからのSDXLのダウンロード、インストール、img2txt と img2img の方法を説明している。いずれも,作成したい画像について英語のテキストで記述し,「Generate」をクリックして結果を確認できる。さらに一括画像生成のPythonプログラムも紹介している。複数の画像を1回の操作で生成することができ便利である。

画像生成 (txt2img),画像変換 (img2img)

複数の画像を一度に画像生成

目次

  1. 前準備
  2. AUTOMATIC1111 の stable-diffusion-webui のインストールと動作生成(Windows 上)
  3. Stable Diffusion XL 1.0 のインストール,画像生成 (txt2img),画像変換 (img2img)
  4. AUTOMATIC1111 の API を利用して,複数の画像を1回の操作で生成する Python プログラム

Stable Diffusion XL (SDXL)

Stable Diffusion XL (SDXL) は,Stability AIによって開発されたDiffusionベースの image-to-text の画像生成モデルである. SDXLはStable Diffusion with Larger UNet Backboneの略称である.

SDXLは,以前のStable Diffusionモデルと比較して,UNetバックボーンのサイズが3倍に増加している.この増加は,アテンションブロック数の増加とクロスアテンションコンテキストの拡大によるものである.また,SDXLはリファインメントモデルを導入している.このリファインメントモデルは,SDXLによって生成された画像の視覚的な精度を向上させるために使用される.

文献

D ustin Podell, Zion English, Kyle Lacey, Andreas Blattmann, Tim Dockhorn, Jonas Müller, Joe Penna, Robin Rombach: SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis. CoRR abs/2307.01952, 2023.

https://arxiv.org/pdf/2307.01952v1.pdf

サイト内の関連ページ

関連する外部ページ

前準備

Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022)または Visual Studio 2022 のインストール(Windows 上)

インストールの判断Build Tools for Visual Studio は,開発ツールセットである. Visual Studio は統合開発環境であり,いくつかの種類があり,Build Tools for Visual Studioの機能を含むか連携して使用するものである.インストールは以下の基準で判断してください:

不明な点がある場合は,Visual Studio 全体をインストール を行う方が良い.

Build Tools for Visual Studio 2022 のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    次のコマンドは,Build Tools for Visual Studio 2022と VC2015 再配布可能パッケージをインストールするものである.

    winget install --scope machine Microsoft.VisualStudio.2022.BuildTools 
    winget install --scope machine Microsoft.VCRedist.2015+.x64
    
  2. Build Tools for Visual Studio 2022 での C++ によるデスクトップ開発,CLI,ATL,MFC のインストール(Windows 上)
    1. Visual Studio Installer の起動

      起動方法: スタートメニューの「Visual Studio Installer」を選ぶ.

    2. Visual Studio Build Tools 2022 で「変更」を選ぶ.
    3. C++ によるデスクトップ開発」をクリック.そして,画面右側の「インストール」の詳細で「v143 ビルドツール用 C++/CLI サポート(最新)」,「ATL」,「MFC」をチェックする.その後,「変更」をクリック.

Visual Studio のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    1. コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
    2. インストールコマンドの実行
      winget install Microsoft.VisualStudio.2022.Community --scope machine --override "--add Microsoft.VisualStudio.Workload.NativeDesktop Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core Microsoft.VisualStudio.Component.VC.CLI.Support Microsoft.VisualStudio.Component.CoreEditor Microsoft.VisualStudio.Component.NuGet Microsoft.VisualStudio.Component.Roslyn.Compiler Microsoft.VisualStudio.Component.TextTemplating Microsoft.VisualStudio.Component.Windows.SDK.Latest Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.VC.ATL Microsoft.VisualStudio.Component.VC.ATLMFC"
      winget install Microsoft.VisualStudio.2022.Community --scope machine Microsoft.VCRedist.2015+.x64
      

      インストールされるコンポーネントの説明:

      • NativeDesktop:C++によるデスクトップアプリケーション開発のためのワークロード一式
      • NativeDesktop.Core:C++デスクトップ開発に必要な基本コンポーネント群
      • VC.CLI.Support:マネージドコードとネイティブコードの統合開発を可能にするC++/CLIサポート
      • CoreEditor:コード編集,デバッグ,検索などの基本機能を提供するVisual Studioのコアエディタ
      • NuGet:.NETライブラリの依存関係を管理するパッケージ管理システム
      • Windows.SDK.Latest:Windows 向けアプリケーション開発用SDK(Software Development Kit)
      • VC.Tools.x86.x64:32ビット及び64ビット向けC++コンパイラとビルドツール
      • VC.ATL:Windowsコンポーネント開発用のActive Template Library
      • VC.ATLMFC:デスクトップアプリケーション開発用のMicrosoft Foundation Class Library

      システム要件と注意事項:

      • 管理者権限でのインストールが必須
      • 必要ディスク容量:10GB以上
      • 推奨メモリ:8GB以上のRAM
      • インストール過程でシステムの再起動が要求される可能性がある
      • 安定したインターネット接続環境が必要

      追加のコンポーネントが必要な場合は,Visual Studio Installerを使用して個別にインストールすることが可能である.

    3. インストール完了の確認
      winget list Microsoft.VisualStudio.2022.Community
      

      トラブルシューティング:

      インストール失敗時は,以下のログファイルを確認:

      %TEMP%\dd_setup_<timestamp>.log
      %TEMP%\dd_bootstrapper_<timestamp>.log
  2. Visual Studio での C++ によるデスクトップ開発,CLI のインストール(Windows 上)
    1. Visual Studio Installer の起動

      起動方法: スタートメニューの「Visual Studio Installer」を選ぶ.

    2. Visual Studio Community 2022 で「変更」を選ぶ.
    3. C++ によるデスクトップ開発」をチェック.そして,画面右側の「インストール」の詳細で「v143 ビルドツール用 C++/CLI サポート(最新)」をチェックする.その後,「インストール」をクリック.

Python 3.10,Git のインストール(Windows 上)

Pythonは,プログラミング言語の1つ. Gitは,分散型のバージョン管理システム.

手順

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    次のコマンドは,Python ランチャーとPython 3.10とGitをインストールし,Gitパスを通すものである.

    次のコマンドでインストールされるGitは 「git for Windows」と呼ばれるものであり, Git,MinGW などから構成されている.

    winget install --scope machine Python.Launcher
    winget install --scope machine Python.Python.3.10
    winget install --scope machine Git.Git
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\Git\cmd\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    

関連する外部ページ

サイト内の関連ページ

関連項目Python, Git バージョン管理システム, Git の利用

Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN 8.9.7 のインストール(Windows 上)

サイト内の関連ページNVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバNVIDIA CUDA ツールキットNVIDIA cuDNN のインストールを行う.

関連する外部ページ

PyTorch のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. PyTorch のページを確認

    PyTorch の公式ページ: https://pytorch.org/index.html

  3. 次のようなコマンドを実行(実行するコマンドは,PyTorch のページの表示されるコマンドを使う).

    次のコマンドを実行することにより, PyTorch 2.3 (NVIDIA CUDA 11.8 用)がインストールされる. 但し,Anaconda3を使いたい場合には別手順になる.

    事前に NVIDIA CUDA のバージョンを確認しておくこと(ここでは,NVIDIA CUDA ツールキット 11.8 が前もってインストール済みであるとする).

    PyTorch で,GPU が動作している場合には,「torch.cuda.is_available()」により,True が表示される.

    python -m pip install -U --ignore-installed pip
    python -m pip uninstall -y torch torchvision torchaudio torchtext xformers
    python -m pip install -U torch torchvision torchaudio numpy --index-url https://download.pytorch.org/whl/cu118
    
    python -c "import torch; print(torch.__version__, torch.cuda.is_available())" 
    

    Anaconda3を使いたい場合には, Anaconda プロンプト (Anaconda Prompt)管理者として実行し, 次のコマンドを実行する. (PyTorch と NVIDIA CUDA との連携がうまくいかない可能性があるため,Anaconda3を使わないことも検討して欲しい).

    conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 cudnn -c pytorch -c nvidia
    py -c "import torch; print(torch.__version__, torch.cuda.is_available())" 
    

    サイト内の関連ページ

    関連する外部ページ

AUTOMATIC1111 の stable-diffusion-webui のインストールと動作確認(Windows 上)

AUTOMATIC1111 の stable-diffusion-webui の GitHUb のページ: https://github.com/AUTOMATIC1111/stable-diffusion-webui

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. Stable Diffusion web UI(AUTOMATIC1111版) のダウンロード
    cd /d c:%HOMEPATH%
    rmdir /s /q stable-diffusion-webui
    git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
    
  3. 動作確認のため,コマンドプロンプトで,「webui.bat --update-all-extensions」 を実行

    「--update-all-extensions」を付けて実行することで,拡張機能(extension) の更新を行っている.

    このとき, WebUI のバージョンが表示されるので確認.

    エラーメッセージが出ていないことを確認.

    cd /d c:%HOMEPATH%
    cd stable-diffusion-webui
    webui.bat --update-all-extensions
    

    このとき,次のような「Couldn't launch python exit code: 9009 stderr: Python Launch unsuccessful. Exiting 」という表示が出た場合は, Python のインストールを行ってから,上の操作をやり直す.

  4. このときの表示に従い,Web ブラウザで,http://127.0.0.1:7860 にアクセス
  5. 画面が開く.

    右上のメニューでは,学習済みモデルを選ぶことができる. 2023年6月時点では,インストール直後に,V1-5-pruned-emaonly,safetensorsを選ぶことができる.

  6. 英語の文章を入れて,「Generate」をクリック.結果を確認.

    解像度は1920 x 1024 にしている.

    プロンプトとして次を入れている.

    (master piece:1,1) (best quality:1,1), cinematic lighting, 4k, 8k, Standing on a sandy beach by the sea, the vast ocean reflects sunlight. A forest trees, while in the distance, mountains with snow-capped peaks appear. The clear blue sky and warm sunlight create a perfect setting.  Today is meant for playing on the beach, inspired by the beautiful scenery.
    

    画像をクリックすると拡大表示できる.

Stable Diffusion XL 1.0 のインストール,画像生成 (txt2img),画像変換 (img2img)

xformers を Automatic 1111 のvenv下にインストール

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

    次のコマンドを実行

    cd /d c:%HOMEPATH%
    cd stable-diffusion-webui
    cd venv
    cd scripts
    .\python -m pip install -U xformers
    

Stable Diffusion XL 1.0 のインストール,画像生成 (txt2img),画像変換 (img2img)

  1. AUTOMATIC1111 の Wiki のページを開く.

    https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#stable-diffusion-20

  2. SD-XL の下の「sd_xl_base_1.0_0.9vae」をクリック
  3. download」をクリック
  4. ダウンロードが始まる

    ダウンロードしたファイルはあとで使用する.

  5. 再び,AUTOMATIC1111 の Wiki のページを開く.

    https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#stable-diffusion-20

  6. 今度は,SD-XL の下の「sd_xl_refiner_1.0_0.9vae」をクリック
  7. download」をクリック
  8. ダウンロードが始まる

    ダウンロードしたファイルはあとで使用する.

  9. いまダウンロードした2つのファイルを %HOMEPATH%stable-diffusion-webui\models\Stable-diffusion の下にコピー
  10. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)

画像生成

  1. コマンドプロンプトで,webui-user.bat を実行
    cd /d c:%HOMEPATH%
    cd stable-diffusion-webui
    webui-user.bat
    

    少ないビデオメモリで動かすために,公式ページでは「--lowvram」,「--medvram 」が案内されている.

    webui-user.bat --lowvram

    webui-user.bat --medvram

  2. このときの表示に従い,Web ブラウザで,http://127.0.0.1:7860 にアクセス
  3. メニューで使用するモデルを確認,設定できる.

    ここでは,sd_xl_base_1.0_0.9vae_safetensorsを選択

  4. 文章を入れて,「Generate」をクリック.結果を確認.

    解像度は1920 x 1024 にしている.

    プロンプトとして次を入れている.

    (master piece:1,1) (best quality:1,1), cinematic lighting, 4k, 8k, Standing on a sandy beach by the sea, the vast ocean reflects sunlight. A forest trees, while in the distance, mountains with snow-capped peaks appear. The clear blue sky and warm sunlight create a perfect setting.  Today is meant for playing on the beach, inspired by the beautiful scenery.
    

    「Generate」をクリック.

  5. 結果が表示される
  6. 画像のクリックにより拡大表示できる.
  7. 「Save」により保存できる

img2img による画像改善

画像合成で得られた画像をimg2img を用いて画像改善する

  1. 画像生成のあと「Send to img2img」をクリック
  2. モデルをsd_xl_refiner_1.0_0.9vae_safetensorsに変更することを忘れない.
  3. 「Generate」をクリックすることにより img2img が開始する.結果を確認.

    得られた画像

  4. 南国のようにしたいと考えて,プロンプトを「Do not make changes to the image as possible except changing the image to tropical island, flowers and fruits.」として,「Generate」をクリック.

    得られた画像

  5. 京都のようにしたいと考えて,プロンプトを「Do not make changes to the image as possible except relocating the image to Kyoto.」として,「Generate」をクリック.

    得られた画像

  6. 南極のようにしたいと考えて,プロンプトを「Do not make changes to the image as possible except relocating the image to Antarctica.」として,「Generate」をクリック.

    得られた画像

AUTOMATIC1111 の API を利用して,複数の画像を1回の操作で生成する Python プログラム

関連する外部ページ

AUTOMATIC1111 の API の公式ページ: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API

複数の画像を1回の操作で生成する Python プログラム

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. webui とサーバを起動

    前準備として「webui.bat --api --allow-code」で起動.(--allow-code はプロンプト中にコードを含めることを可能にするもの.今回はこの機能は使っていない)

    cd /d c:%HOMEPATH%
    cd stable-diffusion-webui
    webui.bat --api --allow-code
    
  3. エディタを起動
    cd /d c:%HOMEPATH%
    cd stable-diffusion-webui
    notepad txt2img.py
    
  4. エディタで,次のプログラムを保存

    このプログラムは, AUTOMATIC1111 の API の公式ページ: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API で公開されていたものを変更して使用している.

    import json
    import requests
    import io
    import base64
    from PIL import Image, PngImagePlugin
    import os
    import tkinter as tk
    
    def get_file_extension(filename):
        # ファイル名と拡張子を取得
        _, extension = os.path.splitext(filename)
        # 拡張子の先頭のピリオドを取り除く
        return extension[1:]
    
    def remove_file_extension(filename):
        # ファイル名と拡張子を取得
        filename_without_extension, _ = os.path.splitext(filename)
        return filename_without_extension
    
    def get_response(url, payload):
        response = requests.post(url=url, json=payload)
        return response.json()
    
    def save_image(image_data, fname):
        image = Image.open(io.BytesIO(base64.b64decode(image_data.split(",", 1)[0])))
        png_payload = {
            "image": "data:image/png;base64," + image_data
        }
        response2 = requests.post(url=f'{url}/sdapi/v1/png-info', json=png_payload)
        pnginfo = PngImagePlugin.PngInfo()
        pnginfo.add_text("parameters", response2.json().get("info"))
        print(fname)
        image.save(fname, pnginfo=pnginfo)
    
    def generate_images():
        global url_entry
        url = url_entry.get()
        output_filename = output_filename_entry.get()
        number_of_files = int(number_of_files_entry.get()) 
        model = model_entry.get()
        prompt = prompt_entry.get("1.0", tk.END)
        width = int(width_entry.get())
        height = int(height_entry.get())
        steps = int(steps_entry.get())
        cfg_scale = int(cfg_scale_entry.get())
        negative_prompt = negative_prompt_entry.get("1.0", tk.END)
    
        payload = {
            "sd_model_checkpoint": model,
        }
        response = get_response(f'{url}/sdapi/v1/options', payload)
    
        strings = [f"{i:02}" for i in range(number_of_files)]
        for i in strings:       
            payload = {
                "prompt": prompt,
                "width": width,
                "height": height,
                "steps": steps,
                "cfg_scale": cfg_scale,
                "negative_prompt": negative_prompt,
            }
            response = get_response(f'{url}/sdapi/v1/txt2img', payload)
            for j in response['images']:
                save_image(j, remove_file_extension(output_filename) + i + '.' +  get_file_extension(output_filename))
    
    url_entry = None;
    output_filename_entry = None;
    number_of_files_entry = None;
    model_entry = None;
    prompt_entry = None;
    width_entry = None;
    height_entry = None;
    steps_entry = None;
    cfg_scale_entry = None;
    negative_prompt_entry = None;
    
    def main():
        global url_entry, output_filename_entry, number_of_files_entry, model_entry, prompt_entry, width_entry, height_entry, steps_entry, cfg_scale_entry, negative_prompt_entry
    
        # Tkinter GUI setup
        root = tk.Tk()
        root.title("Image Generation Configurator")
    
        tk.Label(root, text="URL:").grid(row=0, column=0, padx=5, pady=5)
        url_entry = tk.Entry(root, width=50)
        url_entry.grid(row=0, column=1, columnspan=3, padx=5, pady=5)
        url_entry.insert(tk.END, "http://127.0.0.1:7860")
    
        tk.Label(root, text="Output Filename:").grid(row=1, column=0, padx=5, pady=5)
        output_filename_entry = tk.Entry(root, width=50)
        output_filename_entry.grid(row=1, column=1, columnspan=3, padx=5, pady=5)
        output_filename_entry.insert(tk.END, "output.png")
    
        tk.Label(root, text="Number of Files:").grid(row=2, column=0, padx=5, pady=5)
        number_of_files_entry = tk.Entry(root, width=50)
        number_of_files_entry.grid(row=2, column=1, columnspan=3, padx=5, pady=5)
        number_of_files_entry.insert(tk.END, "20")
    
        tk.Label(root, text="model:").grid(row=3, column=0, padx=5, pady=5)
        model_entry = tk.Entry(root, width=50)
        model_entry.grid(row=3, column=1, columnspan=3, padx=5, pady=5)
        model_entry.insert(tk.END, "sd_xl_base_1.0_0.9vae.safetensors [e6bb9ea85b]")
    
        tk.Label(root, text="Prompt:").grid(row=4, column=0, padx=5, pady=5)
        prompt_entry = tk.Text(root, width=50, height=6)
        prompt_entry.grid(row=4, column=1, columnspan=3, padx=5, pady=5)
        prompt_entry.insert(tk.END, "person, (master piece:1,1) (best quality:1,1), 4k, 8k")
    
        tk.Label(root, text="Width:").grid(row=5, column=0, padx=5, pady=5)
        width_entry = tk.Entry(root, width=50)
        width_entry.grid(row=5, column=1, columnspan=3, padx=5, pady=5)
        width_entry.insert(tk.END, "1024")
    
        tk.Label(root, text="Height:").grid(row=6, column=0, padx=5, pady=5)
        height_entry = tk.Entry(root, width=50)
        height_entry.grid(row=6, column=1, columnspan=3, padx=5, pady=5)
        height_entry.insert(tk.END, "1024")
    
        tk.Label(root, text="Steps:").grid(row=7, column=0, padx=5, pady=5)
        steps_entry = tk.Entry(root, width=50)
        steps_entry.grid(row=7, column=1, columnspan=3, padx=5, pady=5)
        steps_entry.insert(tk.END, "20")
        
        tk.Label(root, text="Cfg Scale:").grid(row=8, column=0, padx=5, pady=5)
        cfg_scale_entry = tk.Entry(root, width=50)
        cfg_scale_entry.grid(row=8, column=1, columnspan=3, padx=5, pady=5)
        cfg_scale_entry.insert(tk.END, "7")
    
        tk.Label(root, text="Negative Prompt:").grid(row=9, column=0, padx=5, pady=5)
        negative_prompt_entry = tk.Text(root, width=50, height=10)
        negative_prompt_entry.grid(row=9, column=1, columnspan=3, padx=5, pady=5)
        negative_prompt_entry.insert(tk.END, "(((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, 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")
    
        generate_button = tk.Button(root, text="Generate Images", command=generate_images)
        generate_button.grid(row=10, column=0, columnspan=4, padx=5, pady=10)
        
        root.mainloop()
    
    if __name__ == "__main__":
        main()
    
  5. Python プログラムの実行

    Python プログラムの実行

    Python 開発環境(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, Spyder, PyCharm, PyScripterなど)も便利である.

    Python のまとめ: 別ページ »にまとめ

    プログラムを txt2img.pyのようなファイル名で保存したので, 「python txt2img.py」のようなコマンドで行う.

    python txt2img.py
    
  6. 設定画面が出るので設定する.設定が終わったら「Generate Images」をクリック.

    モデルの既定値(デフォルト値)は,sd_xl_base_1.0_0.9vae.safetensors [e6bb9ea85b]」にしている.

    Output Filename で「output.png」と設定すると,生成される画像ファイル名はoutput00.png, output01.png ... のようなファイル名になる.

    その他の設定

    • URL: 接続先のURL とポート番号
    • Number of Files: 生成する画像枚数
    • model: 使用するモデル
    • Prompt: : プロンプト
    • width, Height: 画像のサイズ
    • Negative Prompt": negative プロンプト

      下のプログラムでは,https://huggingface.co/Deltaadams/HentaiDiffusion/resolve/main/Universal%20Negative%20Prompt%20Text.txtで公開されているものから「3D」についての記載を取り除いたものを既定値(デフォルト値)としている.

    • Steps: ステップ数
    • Cfg Scale: cfg_scale
  7. 実行の結果,画像ファイルが output00.png, output01.png, ... のようにできるので確認

    複数の画像を1回の操作で生成している.

    下は,prompt に 「"Johannes Vermeer, fine art, master work, oil painting, (master piece:1,1) (best quality:1,1), 4k, 8k"」を設定して実行したときの結果

StyleSelectorXL extension のインストール

  1. Extensions」をクリック
  2. Install from URL」をクリック
  3. 次のURLを設定する.「Install」をクリック
    https://github.com/ahgsql/StyleSelectorXL
    
  4. Installed」をクリック. 「Apply and restart UI」をクリック.
  5. txt2img で SDXL Styles が設定できるようになる.