Stable Diffusion

Stable Diffusion是一个开源的文本生成图像模型。由CompVis、StabilityAI和Runway合作开发。

简介

时间轴

常见图像生成模型

名称 描述
Diffusion models
GAN
(Generative adversarial networks)
VAE
(Variational auto encoders)
Flow-based models


相似对比

名称 描述 网站
Stable Diffusion
Midjourney
DALL-E

安装

在线使用

平台 描述
Hugging Face 无需注册,直接使用。

官网:https://huggingface.co/spaces/stabilityai/stable-diffusion

Replicate 无需注册,直接使用,支持付费API。

官网:https://replicate.com/stability-ai/stable-diffusion

DreamStudio Stability AI 提供的网站。

官网:http://beta.dreamstudio.ai

Google Colab Colab是Google提供的一个免费和付费的Jupyter Notebook环境。
使用步骤:
1.登录Colab,https://colab.research.google.com/
2.安装Stable Diffusion环境,在 https://github.com/camenduru/stable-diffusion-webui-colab 选择一个环境脚本,点击打开并在Colab运行安装。
3.Colab中安装完成后会有WebUI链接,点击访问即可。

Google Colab:https://colab.research.google.com/
stable-diffusion-webui-colab:https://github.com/camenduru/stable-diffusion-webui-colab

腾讯云GPU服务器 购买活动服务器,60元15天。
使用步骤:
1.系统选择:Docker基础镜像。
2.拉取Docker镜像:sudo docker pull gpulab.tencentcloudcr.com/ai/stable-diffusion:1.0.8
3.运行容器:sudo docker run -itd --gpus=all --network=host --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --name=stable-diffusion gpulab.tencentcloudcr.com/ai/stable-diffusion:1.0.8 | xargs sudo docker logs --follow
4.点击Public URL:https://xxxxxxxx.gradio.live/ 可以打开Stable Diffusion WebUI。点击http://外网IP:8888/?token=xxxxxx打开JupyterNotebook

官网:https://cloud.tencent.com/act/pro/gpu-study

了解更多 >> Stability 博客:Stable Diffusion 公开发布


Windows上部署

快速开始

Prompt 提示词

语法

名称 描述 示例
prompt 提示词,需要在画面出现内容。
Negative prompt 反向提示词,不需要在画面出现内容。
Seed

常见提示词

类型 提示词
设备 Device 佳能:Canon,尼康:Nikon,iPhone,
镜头 Lenses
风格
画质 杰作:masterpiece,最佳品质:best quality

常用网站

网站名称 描述 网址
Civitai 模型分享网站,点击图片右下角的感叹号,会显示提示词。 https://civitai.com/
Promptbase 有 DALL·E, GPT, Midjourney, Stable Diffusion, ChatGPT提示词 https://promptbase.com/
Prompthero https://prompthero.com/
无界AI https://wujieai.com/
Lexica https://lexica.art/


Model 模型

Stable Diffusion模型是由一大堆的图像和图像的本注释训练而成。

模型类型

名称 描述
Checkpoint 又称大模型、底模型,真正 Stable Diffusion模型,直接使用即可生成图片。模型很大,一般2 – 7 GB。
格式:ckpt,safetensors
位置:stable-diffusion-webui/models/Stable-diffusion/
使用:点击webUI左上角Stable Diffusion checkpoint单选框选择模型,默认Stable diffusion训练模型。
LoRA

下载安装

安装模型,只需要下载模型放入对应文件夹,再在网页点击模型刷新按钮。如Checkpoint模型放入stable-diffusion-webui/models/Stable-diffusion文件夹中。可以网页浏览下载模型,也可以使用命令下载,如在Linux中下载chilloutmix 模型:

# 进入模型对应文件夹,使用wget下载。
cd stable-diffusion-webui/models/Stable-diffusion
wget -O chilloutmix_NiPrunedFp32.safetensors https://civitai.com/api/download/models/9475
名称 描述 网址
Civitai 模型多,浏览下载方便。 https://civitai.com/
Hugging Face 模型多 https://huggingface.co/

训练模型

LoRA训练

1.训练环境搭建,一般使用kohya-ss/sd-scripts脚本训练,地址:https://github.com/kohya-ss/sd-scripts 。基于kohya-ss/sd-scripts制作的更易用的图形界面有:

以下示例在Ubuntu下安装bmaltais/kohya_ss:

# 安装anaconda
sudo apt update
wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh
bash Anaconda3-2023.03-1-Linux-x86_64.sh
export PATH=/home/yourusername/anaconda3/bin:$PATH

# 重启终端,创建虚拟环境
conda create -n kohya_ss python=3.10
conda init bash  
conda activate kohya_ss  # 进入虚拟环境

sudo apt install python3-tk
conda install -c conda-forge accelerate
# 下载项目,安装,启动
git clone https://github.com/bmaltais/kohya_ss.git
cd kohya_ss
./setup.sh  # 安装
accelerate config
./gui.sh --share   # 启动

2.图像处理

3.打标签

4.训练

5.模型测试


了解更多 >> GitHub:kohya-ss/sd-scripts GitHub:bmaltais/kohya_ss kohya-ss/sd-scripts:训练


Controlnet

资源

官网

网站

视频


文章