最終更新:ID:DqSiI5hXpw 2023年04月21日(金) 14:14:23履歴
学習は別のでやる流れだけど生成には便利に使えるはず。
Remote UI(1111を含む)の利用が禁止になりました。
以後、ブラウザで操作するタイプのソフトウェアは使わないでください。
今後の更新はありません。
最終版のセル(参考)
segがエラーで動かんなあ。prettytableは入れたつもりなんだけど。
Remote UI(1111を含む)の利用が禁止になりました。
以後、ブラウザで操作するタイプのソフトウェアは使わないでください。
今後の更新はありません。
最終版のセル(参考)
#@title ↓再生ボタンを押してね #@markdown 実行は自己責任で。 #@markdown gradioログイン情報(パスワード空白時は自動生成) user = "user"#@param {type:"string"} password = ""#@param {type:"string"} #@markdown 環境調査(2回目以降は飛ばしてもいい) use_envcheck = True #@param {type:"boolean"} if use_envcheck: # Ubuntu !uname -m && cat /etc/*release res = !cat /etc/*release | grep 'VERSION_ID' | grep -o '[0-9.]*' if not res[0].startswith('20.04'): raise RuntimeError("Ubuntuのバージョンが変わった " + res[0]) # Python res = !python -V | grep -o '[0-9.]*' if not res[0].startswith('3.9.'): raise RuntimeError("Pythonのバージョンが変わった " + res[0]) # GPU/CUDA !nvidia-smi res = !nvcc -V | grep 'Cuda compilation tools, release' | grep -o '[0-9.]*' if not res[0].startswith('11.8'): raise RuntimeError("CUDAのバージョンが変わった " + res[0]) # RAMの容量取得(GiB) res = !free -m | grep 'Mem:' | awk '{print $2}' if not res: raise ValueError("RAMが取得できない") ram = round(float(res[0]) / 1024, 3) if ram < 12: raise ValueError("RAMが思ったより少ない" + ram) print(f"RAM : {ram}") # VRAMの容量取得(GiB) res = !nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits if not res: raise ValueError("VRAMが取得できない(GPUに繋がってないかも)") vram = round(float(res[0]) / 1024, 3) if vram < 14: raise ValueError("VRAMが思ったより少ない " + vram) print(f"VRAM: {vram}") del res ### セットアップ %cd /content #@markdown # Pythonインストール #@markdown miniconda 3.10.9 use_conda = False #@param {type:"boolean"} #@markdown apt-get 3.10.10 こっちは最近調子悪いみたい use_apt = False #@param {type:"boolean"} if use_conda and use_apt: raise ValueError("どっちやねん") if use_conda: !wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh !bash Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local if use_apt: !sudo apt autoremove !sudo apt-get -y update !sudo apt-get -y install python3.10 !sudo cp `which python3.10` /usr/local/bin/python # Pythonのバージョン確認 !python -V # pipを最新に !wget https://bootstrap.pypa.io/get-pip.py -O - | sudo python #@markdown xformersインストール(当面torch1のみ) use_xformers = False #@param {type:"boolean"} #@markdown torch2インストール(use_conda必須) use_torch2 = False #@param {type:"boolean"} if use_torch2: !pip install --upgrade torch torchvision --extra-index-url https://download.pytorch.org/whl/cu118 # torch1をアップデート(Python 3.10の時だけ) elif use_conda or use_apt: !pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 if use_xformers: !pip install -U --pre triton !pip install xformers==0.0.16rc425 # これが無いと動かないので !pip install fastapi==0.90.1 ### パスワード関連 # デフォルトパスワード生成 import secrets import string def get_password(length: int) -> str: # secretsはrandomとかと違って暗号学的に安全な乱数を生成できる。 pass_chars = string.ascii_letters + string.digits password = ''.join(secrets.choice(pass_chars) for i in range(length)) return password if not password: password = get_password(64) del secrets del string del get_password ### WEBUIのセットアップ %cd /content/ !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git %cd stable-diffusion-webui/models/Stable-diffusion #@markdown モデルのURL(複数いるならFilerでダウンロードしましょう) ckpt_url = 'https://huggingface.co/aka7774/fp16_safetensors/resolve/main/7th_anime_v3_A-fp16-1833-2982-0018.safetensors'#@param {type:"string"} # ダウンロードにトークンの要らないモデルなのでコメントアウト ##@markdown トークンはここで貰ってきて https://huggingface.co/settings/tokens #user_token = ''#@param {type:"string"} #user_header = f"\"Authorization: Bearer {user_token}\"" #!wget -c --header={user_header} "{ckpt_url}" -P /content/stable-diffusion-webui/models/Stable-diffusion/ #del user_header if ckpt_url: !wget -c "{ckpt_url}" -P /content/stable-diffusion-webui/models/Stable-diffusion/ # @markdown aria2cで落としたいモデルのURL(なければ空白) aria_url = ''#@param {type:"string"} if aria_url: !apt install -y -qq aria2 !aria2c --summary-interval=10 -x 3 --allow-overwrite=true -Z {aria_url} import os #@markdown # Extensions %cd /content/stable-diffusion-webui/extensions/ #@markdown --enable-insecure-extension-access use_eiea = False #@param {type:"boolean"} #@markdown ImagesとFilerはColabで便利なので入れましょう use_filer = True #@param {type:"boolean"} if use_filer: #!git clone https://github.com/aka7774/sd_images_browser.git !git clone https://github.com/AlUlkesh/stable-diffusion-webui-images-browser.git !git clone https://github.com/aka7774/sd_filer.git #@markdown 型抜き系(Katanuki rembg PBRemTools) use_katanuki = False #@param {type:"boolean"} if use_katanuki: !git clone https://github.com/mattyamonaca/PBRemTools.git !git clone https://github.com/aka7774/sd_katanuki.git !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-rembg.git #@markdown 学習関連(dreambooth, Hypernetwork-MonkeyPatch) use_train = False #@param {type:"boolean"} if use_train: !git clone https://github.com/d8ahazard/sd_dreambooth_extension.git !git clone https://github.com/aria1th/Hypernetwork-MonkeyPatch-Extension.git #@markdown マージ関連(supermerger, MBW)とモデル変換(toolkit) use_merge = False #@param {type:"boolean"} if use_merge: !git clone https://github.com/hako-mikan/sd-webui-supermerger.git !git clone https://github.com/bbc-mc/sdweb-merge-block-weighted-gui.git !git clone https://github.com/aka7774/sd_merge_numa.git !git clone https://github.com/arenatemp/stable-diffusion-webui-model-toolkit.git #@markdown LoRA関連(additional-networks, locon, two-shot) use_lora = False #@param {type:"boolean"} if use_lora: !git clone https://github.com/kohya-ss/sd-webui-additional-networks.git !git clone https://github.com/KohakuBlueleaf/a1111-sd-webui-locon.git !git clone https://github.com/opparco/stable-diffusion-webui-two-shot.git #@markdown ControlNet(fp16モデルつき) use_controlnet = False #@param {type:"boolean"} if use_controlnet: !pip install prettytable !git clone https://github.com/Mikubill/sd-webui-controlnet.git %cd sd-webui-controlnet !git clone https://huggingface.co/webui/ControlNet-modules-safetensors.git for fi in os.listdir("ControlNet-modules-safetensors"): os.rename(f"ControlNet-modules-safetensors/{fi}", f"models/{fi}") %cd .. !git clone https://github.com/gogodr/sd-webui-stopmotion.git #@markdown aka: fake_xyplot, curly_rand, copyguard use_aka = False #@param {type:"boolean"} if use_aka: !git clone https://github.com/aka7774/sd_fake_xyplot.git !git clone https://github.com/aka7774/sd_curly_rand.git !git clone https://github.com/aka7774/sd_copyguard.git #@markdown aka: Gimai(ゲームの会話シーン制作) use_gimai = False #@param {type:"boolean"} if use_gimai: !sudo apt install ffmpeg !ffmpeg -version !git clone https://github.com/aka7774/sd_gimai.git %cd sd_gimai !git clone https://huggingface.co/spaces/skytnt/moe-tts.git %cd .. # 一度起動して必要なものをインストールする %cd /content/stable-diffusion-webui/ !COMMANDLINE_ARGS="--exit" REQS_FILE="requirements.txt" python launch.py #@markdown ## Google Driveのマウント(任意) use_drive = False #@param {type:"boolean"} if use_drive: from google.colab import drive drive.mount('/content/drive') # filerのデフォルトバックアップ先を設定 !mkdir -m 0777 /content/stable-diffusion-webui/extensions/sd_filer/config !echo '{"backup_dir":"/content/drive/MyDrive/sd"}' > /content/stable-diffusion-webui/extensions/sd_filer/config/config.json # WEBUIの起動 !COMMANDLINE_ARGS="{'--xformers' if use_xformers else ''} {'--opt-sdp-no-mem-attention' if use_torch2 else ''} --opt-channelslast {'--enable-insecure-extension-access' if use_eiea else ''} --share --gradio-auth {user}:{password}" REQS_FILE="requirements.txt" python launch.py
- 本体の動作確認できてないんだけど、気になったExtensionを追加した。
- PBRemTools AlUlkesh/stable-diffusion-webui-images-browser sd-webui-stopmotion
- torch2に対応しました。めちゃ速くなるので楽しい。
- xformersを入れなくできるようにした(torch2では不要だし)
- 環境調査をスキップできるようにした
- Extensionsを更新(LyCoris動かす用など)
- --enable-insecure-extension-accessを入れられるようにした
- Pythonのバージョン指定を次の3つに変更しました
- Python 3.9.16 Colabデフォルト 時短になるのでおすすめ
- Python 3.10.9 use_conda 最新版を入れるので将来おかしくなる可能性あり 今3.9だと困る場合にどうぞ
- Python 3.10.10 use_apt 従来通り。今はうまく動いていない?
- Python 3.9.16選択時にはデフォルトのtorchを使うようにしました 時短
- 環境チェックを厳格にしてRuntimeErrorを返すようにしました
- ControlNet(fp16)に対応しました
- 学習はkohya_train_network_simpleで出来るのでExtensionを外しました
- fastapiのバージョンを0.90.1に固定しました
- Pythonが3.10.10になってました(悪影響は無いはず)
segがエラーで動かんなあ。prettytableは入れたつもりなんだけど。
ModuleNotFoundError: No module named 'lib2to3'
- Python 3.10にきちんと対応(xformersがすんなり入るよ、やったね)
- モジュールのバージョンをあげました
- 流行りのExtensionsに入れ替え(面倒なので今後はやらんかも)
- モデルのURLをVAE内蔵の7th3Aにしました(ダウンロードが早く済むはず)
- condaかpipか選べるようにした。エラー出た時の予備になるかも?
- 階層マージ遊びが出来るExtensionをインストールできるようにした(たぶん4GBのモデルならいける)
- モデルのURLを3つまで入れられるようにした(もっと入れたければ改造して)
- SD2.0系は未対応(需要あれば対応する)
- Googleアカウントを用意する(普段使いとは分けるのがおすすめ)
- 次のページを読んで基礎を理解する
- 「1+1」のかわりに
以下の黄色い枠内の内容をコピペして上のリンク先のnotebook内容をコピーして実行 - 実行結果に「Running on public URL: https://xxxxx.gradio.live」と出てくるのでそこに飛んで、usernameとpasswordを入力する
- usernameはデフォルト実行ならuser。passwordは自動生成されているので「Launching Web UI with arguments:」の行を参照
このページへのコメント
無料版のSD禁止令どうしようか…
今までの無料の利用頻度(一日2時間程度)なら有料プランでも約50時間で25日は使えるし、課金したらいいんじゃない?
月1000円ちょっとで今まで通り遊べるなら十分安い趣味だと思うけど
クレカなければVISAデビットでも作ればいいし
VAEの追加ってどうしたらええんや?
Filerでダウンロードしたり、
aria_urlでもいけると思うけど、
1モデルを使いこむのが主なら、
ベストは事前にマージしたモデルを🤗にあげといて、
それをckpt_urlで入れちゃうことかな
なるほどーサンガツや!
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Preparing metadata (setup.py) ... error
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
これ出るようになって起動出来なくなったね
gdrive通してなくても出るし書いてある通りパッケージの問題?
他の人のノートブックは普通に動くんで原因分かるまでそれ使うといいすね
エラー試行錯誤とか色々グチャグチャになってもいいならwikiノートブックのPython関係のとこ消して他のノートブックから拝借したコード継ぎ接ぎとかすれば一応動きます
Python関連の更新があったらしいです
minicondaを入れると動きました
具体的には
# バージョンあがってないかな
!uname -m && cat /etc/*release | head -n 2
!python -V
---ここから---
!wget ://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
!bash Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
---ここまで---
h t t p sを入力禁止にされたのでwegtの後に入れてください
動きますね。
とりあえずそちらのコード加えてこれは一時解決かな
Driveに保存してるモデルを使いたいですので「モデルのURL」のところに /content/drive/MyDrive/Counterfeit-V2.5.safetensors と入れましたがダメでした。どうすればDriveのファイルが使えますか?
エラーメッセージ:
Can't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations. The program will exit.
起動時に--ckptで指定するか、
!cp /content/drive/MyDrive/Counterfeit-V2.5.safetensors /content/stable-diffusion-webui/models/Stable-diffusion/
でいけるんでないかな
ありがとうございました
エラーについてのissue
github.com/AUTOMATIC1111/stable-diffusion-webui/issues/7714
issue先にも書いてあるけど、
webui起動前のセルに以下を挿入して実行すればいける
!cd /content/stable-diffusion-webui
!source ./venv/bin/activate
!pip install fastapi==0.90.1
!deactivate
あざっす!解決しました