stable diffusion 是一款AI繪圖軟體,你可以免費把stable diffusion算出來的圖免費拿來商用,但是像我的電腦因為顯卡太舊而無法快速運行,而浪費很多時間,你只要準備一個google帳號即可(注意!要是一個小號,因為會消耗掉12GB的空間)。創建google帳號很簡單,不用電話號碼。
到git hub的文章,下面也有程式碼。【
連結】,點選第一個連結,點選複製到雲端硬碟,
點選圖片中的按鈕,點選更變執行階段,將選項變成GPU,執行腳本時記得要同意存取雲端硬碟,不然無法成功。再點擊三角形運行,完成後,到git hub點選第二個連結,點選複製到雲端硬碟,這次直接運行,滑到最下面,等一下後你會看到,有很多連結,點選第二個,就可以進到stable diffusion的操控介面了,網路上有很多有關stable diffusion的教學,如果有時間我再額外介紹。
第二次運行時,要到檔案開啟筆記本,選擇run,再運行即可。
第三個連結是安裝模型用的,這裡用我改寫的程式碼會比較方便,後面沒有#的程式碼都不要改。
懶得到git hub的朋友可以使用精簡後的(只是刪掉註解,不影響程式)程式碼,但是不是點選複製到雲端硬碟,而是按檔案新增筆記本,在貼上程式碼。
install安裝用,更新也可以用這個:
%cd /content
from google.colab import drive
drive.mount('/content/drive')
%env PYTHONDONTWRITEBYTECODE=1
!apt-get -y install -qq aria2
!git clone -b v2.1 https://github.com/camenduru/stable-diffusion-webui /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui checkout -f v2.1
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui pull origin v2.1
!git clone https://huggingface.co/embed/negative /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/embeddings/negative
!git clone https://huggingface.co/embed/lora /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/Lora/positive
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/ESRGAN -o 4x-UltraSharp.pth
!wget https://raw.githubusercontent.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/scripts/run_n_times.py
!git clone https://github.com/deforum-art/deforum-for-automatic1111-webui /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui
!rm -rf /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser
!git clone https://github.com/camenduru/stable-diffusion-webui-images-browser /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser
!git clone https://github.com/camenduru/stable-diffusion-webui-huggingface /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface
!rm -rf /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-civitai-browser
!git clone https://github.com/camenduru/sd-civitai-browser /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-civitai-browser
!git clone https://github.com/kohya-ss/sd-webui-additional-networks /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-additional-networks
!git clone https://github.com/Mikubill/sd-webui-controlnet /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet
!git clone https://github.com/camenduru/openpose-editor /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/openpose-editor
!git clone https://github.com/jexom/sd-webui-depth-lib /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-depth-lib
!git clone https://github.com/hnmr293/posex /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/posex
!git clone https://github.com/camenduru/sd-webui-tunnels /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-tunnels
!git clone https://github.com/etherealxx/batchlinks-webui /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/batchlinks-webui
!git clone https://github.com/camenduru/stable-diffusion-webui-catppuccin /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-catppuccin
!git clone https://github.com/KohakuBlueleaf/a1111-sd-webui-locon /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/a1111-sd-webui-locon
!git clone https://github.com/camenduru/sd_webui_stealth_pnginfo /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd_webui_stealth_pnginfo
%cd /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-civitai-browser reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-civitai-browser pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-additional-networks reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-additional-networks pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/openpose-editor reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/openpose-editor pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-depth-lib reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-depth-lib pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/posex reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/posex pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-tunnels reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-tunnels pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/batchlinks-webui reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/batchlinks-webui pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-catppuccin reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/stable-diffusion-webui-catppuccin pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/a1111-sd-webui-locon reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/a1111-sd-webui-locon pull
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd_webui_stealth_pnginfo reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd_webui_stealth_pnginfo pull
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/hand_pose_model.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/openpose -o hand_pose_model.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/body_pose_model.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/openpose -o body_pose_model.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/dpt_hybrid-midas-501f0c75.pt -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/midas -o dpt_hybrid-midas-501f0c75.pt
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_large_512_fp32.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/mlsd -o mlsd_large_512_fp32.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_tiny_512_fp32.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/mlsd -o mlsd_tiny_512_fp32.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/network-bsds500.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/hed -o network-bsds500.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/upernet_global_small.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/uniformer -o upernet_global_small.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_canny-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_canny-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_depth-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_depth-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_hed-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_hed-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_mlsd-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_mlsd-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_normal-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_normal-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_openpose-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_openpose-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_scribble-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_scribble-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/control_seg-fp16.safetensors -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o control_seg-fp16.safetensors
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/t2iadapter_style_sd14v1.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o t2iadapter_style_sd14v1.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/t2iadapter_sketch_sd14v1.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o t2iadapter_sketch_sd14v1.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/t2iadapter_keypose_sd14v1.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o t2iadapter_keypose_sd14v1.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet/resolve/main/t2iadapter_color_sd14v1.pth -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-controlnet/models -o t2iadapter_color_sd14v1.pth
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/sd15/resolve/main/v1-5-pruned-emaonly.ckpt -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/Stable-diffusion -o v1-5-pruned-emaonly.ckpt
!sed -i -e 's/ start()/ #start()/g' /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/launch.py
!sed -i -e 's/checkout {commithash}/checkout --force {commithash}/g' /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/launch.py
%cd /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
!python launch.py --skip-torch-cuda-test
print("Installed")
run運行用:
%cd /content
from google.colab import drive
drive.mount('/content/drive')
%env PYTHONDONTWRITEBYTECODE=1
import os
from google.colab.output import eval_js
os.environ['colab_url'] = eval_js("google.colab.kernel.proxyPort(7860, {'cache': false})")
!apt -y update -qq
!wget http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb
!wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb
!wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb
!wget https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb
!apt install -qq libunwind8-dev
!dpkg -i *.deb
%env LD_PRELOAD=libtcmalloc.so
!rm *.deb
!apt -y install -qq aria2
!apt -y install -qq unionfs-fuse
!pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 torchtext==0.14.1 torchdata==0.5.1 --extra-index-url https://download.pytorch.org/whl/cu116 -U
!pip install -q xformers==0.0.16 triton==2.0.0 -U
!mkdir /content/fused
!mkdir /content/models
!unionfs-fuse /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/Stable-diffusion=RW:/content/models=RW /content/fused
%cd /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui
!git reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-tunnels reset --hard
!git -C /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/sd-webui-tunnels pull
!sed -i -e 's/checkout {commithash}/checkout --force {commithash}/g' /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/launch.py
!sed -i -e 's/fastapi==0.90.1/fastapi==0.89.1/g' /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/requirements_versions.txt
!mkdir /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui/models
if not os.path.exists(f"/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/CLIP"):
os.mkdir(f"/content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/CLIP")
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://openaipublic.azureedge.net/clip/models/b8cca3fd41ae0c99ba7e8951adf17d267cdb84cd88be6f7c2e0eca1737a03836/ViT-L-14.pt -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/CLIP -o ViT-L-14.pt
!python launch.py --listen --xformers --enable-insecure-extension-access --theme dark --gradio-queue --clip-models-path /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/CLIP --ckpt-dir /content/fused --multiple
add model:安裝模型用
from google.colab import drive
drive.mount('/content/drive')
!apt-get -y install -qq aria2
model_url = "https://" #模型的網址
model_name = "..." #模型的名稱,最好是方便辨識的名稱
model_url = f"\"{model_url}\""
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M {model_url} -d /content/drive/MyDrive/stable-diffusion-webui-colab/stable-diffusion-webui/models/Stable-diffusion -o {model_name}