eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

stable-diffusion

Stable Diffusion web UI(AUTOMATIC1111) Google Colab に自分の好みの設定でインストールして毎回同じ設定で起動する方法

更新日:

「Google Colab」の制限

インスタンスが起動してから12時間経過するとPython実行環境が初期化され環境の再構築が必要になります。また何も操作しないと90分でリセットされます。Google ドライブに設定内容を保存し起動時に読み込むことも可能ですがドライブ接続時にショートメールで認証の確認が来るので私は行っていません。そのためインストール時に設定を作ったりダウンロードすることで対応することを考えます。

インストール時に設定する方法

今まで投稿してきた内容をまとめます

!nvidia-smi!nvidia-smi

!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui /content/stable-diffusion-webui
%cd /content/stable-diffusion-webui

!git clone  https://github.com/yfszzx/stable-diffusion-webui-images-browser extensions/images-browser

!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients extensions/aesthetic-gradients
patterns = "aivazovsky.pt,cloudcore.pt,fantasy.pt,flower_plant.pt,gloomcore.pt,glowwave.pt,laion_7plus.pt,sac_8plus.pt," #@param {type:"string"}
patterna = patterns.split(",")
for pattern in patterna:
    !wget https://github.com/vicgalle/stable-diffusion-aesthetic-gradients/raw/main/aesthetic_embeddings/{pattern} -O  /content/stable-diffusion-webui/extensions/aesthetic-gradients/aesthetic_embeddings/{pattern}

!echo {\"localization\": \"ja_JP\"\,\"filter_nsfw\" : true} >config.json

model_url = "https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt" #@param {type:"string"}
model_filename = "sd-v1-4.ckpt" #@param {type:"string"}
user_token = "" #@param {type:"string"}
user_header = f"\"Authorization: Bearer {user_token}\""
!wget --header={user_header} {model_url} -O models/{model_filename}

model_url2 = "https://huggingface.co/hakurei/waifu-diffusion-v1-3/resolve/main/wd-v1-3-float16.ckpt" #@param {type:"string"}
model_filename2 ="wd-v1-3-float16.ckpt" #@param {type:"string"}
!wget {model_url2} -O models/{model_filename2}

model_url3 = "https://huggingface.co/naclbit/trinart_stable_diffusion_v2/resolve/main/trinart2_step115000.ckpt" #@param {type:"string"}
model_filename3 ="trinart_characters_it4_v1.ckpt" #@param {type:"string"}
!wget {model_url3} -O models/{model_filename3}

vars = f"--exit"
no_gpu = False # @param {type:"boolean"}
if no_gpu:
 vars += f" --skip-torch-cuda-test --precision full --no-half "
!COMMANDLINE_ARGS="""{vars}""" REQS_FILE="requirements.txt" python launch.py

%cd /content/stable-diffusion-webui
!git pull

vars = f"--share --gradio-debug"
vars += f" --deepdanbooru --gradio-img2img-tool color-sketch --enable-insecure-extension-access --gradio-auth me:qwerty"
no_gpu = False # @param {type:"boolean"}
if no_gpu:
  vars += f" --skip-torch-cuda-test --precision full --no-half "
!COMMANDLINE_ARGS="""{vars}""" REQS_FILE="requirements.txt" python launch.py

ui-config.jsonの変更

!sed -i -e 's/\"txt2img\/Height\/value\": 512\,/\"txt2img\/Height\/value\": 1024\,/g' ui-config.json

ui-config.jsonの新規作成

!echo {\"img2img\/Width\/value\"\: 384\,\"img2img\/Height\/value\"\: 320} >ui-config.json

参考 Google ドライブに接続する方法

import os
from google.colab import drive
drive.mount('/content/drive')

参考 Google ドライブにフォルダを作成する方法

%mkdir drive/MyDrive/stable_diffusion/
%cd drive/MyDrive/stable_diffusion/

参考 起動中処理を強制終了させる方法

os.kill(os.getpid(), 9)

-stable-diffusion

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.