Checkpoint 详解 - Stable Diffusion 的核心模型
什么是 Checkpoint?
在使用 Stable Diffusion 的过程中,Checkpoint 是我们最先接触、也是影响最大的一类模型文件。它决定了 AI 绘画的基础能力、风格倾向、细节表现,是整个生成流程的大脑,是理解 Stable Diffusion 绘画效果的关键。
所谓的 Checkpoint(大模型底模),本质上是一个封装好的扩散模型(Diffusion Model)。它不是单纯的数据库,而是一套复杂的数学运算系统。
简单来说,它的工作就是:听懂人话 → 制造混乱 → 从混乱中寻找秩序 → 翻译成图,Checkpoint 就是一个大脑,不同的 Checkpoint,就像是不同的“绘画灵魂”,呈现出完全不一样的风格和特性。
Checkpoint 内部包含 UNet、VAE、文本编码器等关键模块,是图像生成能力的核心来源。
- UNet 扩散模型决定画面如何从噪声中逐步被“擦”出来
- VAE 编解码器负责图像的压缩和还原
- CLIP 文本编辑器负责理解提示词
graph TB
A[Checkpoint 模型文件] --> B[UNet 扩散模型]
A --> C[VAE 编解码器]
A --> D[CLIP 文本编码器]
B --> E[图像去噪能力]
C --> F[图像压缩/还原]
D --> G[理解提示词]
style A fill:#ff6b6b
style B fill:#4ecdc4
style C fill:#45b7d1
style D fill:#f7b731
CLIP 文本编码器
CLIP(Contrastive Language–Image Pretraining)是 OpenAI 提出的一个模型,Stable Diffusion 中只用了 CLIP 的文本编辑器,作用是将用户输入的正向提示词和负面提示词由文本转成向量(Embeddings ),向量中包含了文本的语义信息,能让模型更好“理解” prompt 的语义和概念,作为扩散模型 U-Net 的条件输入。
在 Stable Diffusion 中,你输入的文本 Prompt 会被 CLIP Text Encoder 变成一个 768 或 1024 维的 embedding,U-Net 根据这个 embedding 指导图像生成,最终得到与你 prompt 语义匹配的图。
graph LR
%% --- 样式定义 ---
%% 1. 文本输入:暖橙色,代表人类语言
classDef inputNode fill:#fff3e0,stroke:#ff9800,stroke-width:2px,color:#e65100,rx:5,ry:5;
%% 2. 模型处理:深蓝色,代表计算核心
classDef modelNode fill:#e8eaf6,stroke:#3949ab,stroke-width:2px,color:#1a237e,rx:10,ry:10,font-weight:bold;
%% 3. 向量数据:紫粉色,六边形,代表抽象特征
classDef vectorNode fill:#fce4ec,stroke:#d81b60,stroke-width:2px,color:#880e4f,shape:hexagon;
%% 4. 图像输出:青绿色,代表最终视觉结果
classDef outputNode fill:#e0f2f1,stroke:#00695c,stroke-width:2px,color:#004d40,rx:5,ry:5;
%% --- 节点定义 ---
T[文本输入<br/>"a beautiful sunset"]:::inputNode
CLIP[CLIP Encoder<br/>文本编码器]:::modelNode
V{{向量表示 Embedding<br/>0.23, -0.45, 0.67...}}:::vectorNode
UNet[Diffusion UNet<br/>引导生成]:::modelNode
I[生成图像<br/>Generated Image]:::outputNode
%% --- 连接流程 ---
T -- Tokenize --> CLIP
CLIP == 编码转换 ==> V
V -- 条件引导 (Conditioning) --> UNet
UNet == 逐步去噪 ==> I
%% --- 连线样式 ---
%% 让数据流动的线也有颜色区分
linkStyle 0 stroke:#ff9800,stroke-width:2px;
linkStyle 1 stroke:#3949ab,stroke-width:3px;
linkStyle 2 stroke:#d81b60,stroke-width:2px,stroke-dasharray: 5 5;
linkStyle 3 stroke:#00695c,stroke-width:3px;
UNet 扩散模型
UNet 是整个扩散模型的“图像生成引擎”,是负责“从噪声变成图像”的主力,也是最消耗显卡算力的步骤。它的工作分为两部分:
- 理解提示词带来的条件信息
- 在每一个 Sampling Step 中预测噪声,逐步把潜空间从随机噪声变成结构清晰的画面
几乎所有画面构图、光影、细节、风格,都由 UNet 负责。
graph TB
%% --- 定义样式类 ---
%% 1. 图像状态类:使用冷色调渐变,暗示从混乱到清晰的过程
classDef stateStart fill:#4a148c,stroke:#7c43bd,stroke-width:2px,color:#fff,rx:10,ry:10;
classDef stateMid fill:#1565c0,stroke:#42a5f5,stroke-width:2px,color:#fff,rx:10,ry:10;
classDef stateEnd fill:#00897b,stroke:#26a69a,stroke-width:2px,color:#fff,rx:10,ry:10;
classDef stateEllipse fill:#b0bec5,stroke:none,color:#fff,rx:5,ry:5;
%% 2. 操作动作类:使用暖色调,代表计算处理
classDef operation fill:#f57c00,stroke:#ff9800,stroke-width:2px,color:#fff,rx:5,ry:5,font-weight:bold;
%% 3. 条件输入类:使用独特的亮色,强调外部引导
classDef condition fill:#e91e63,stroke:#f48fb1,stroke-width:3px,color:#fff,rx:15,ry:15,stroke-dasharray: 5 5;
%% --- 定义节点 ---
%% 使用 Font Awesome 图标 (如果支持环境允许) 或 emoji 增强视觉
A[纯噪声<br/>**Step 0**]:::stateStart
B[预测噪声方向]:::operation
C[去除部分噪声<br/>**Step 1**]:::stateMid
D[再次预测]:::operation
E[继续去噪<br/>**Step 2**]:::stateMid
F[...]:::stateEllipse
G[清晰图像<br/>**Step 20-50**]:::stateEnd
H[提示词条件]:::condition
%% --- 定义连接 ---
%% 主流程使用粗线
A ==> B
B ==> C
C ==> D
D ==> E
E ==> F
F ==> G
%% 条件输入使用虚线,强调其辅助作用
H -.-> B
H -.-> D
%% --- 图表标题 (可选) ---
%% title 扩散模型去噪过程示意
UNet 就像一个雕刻家,在几步到几十步的 Step 中根据用户输入的提示词信息,一点点把用户想要的人或物从噪声里“挖”出来。
VAE 变分自编码器
虽然 UNet 完成了工作,但此刻的图像依然是那张 64x64 的“压缩包”(潜空间图像),人类肉眼是无法看懂的。VAE (变分自编码器) 的作用就是把“照片冲洗”出来。
VAE (Variational Autoencoder)又叫变分自编码器,主要负责图像的编码和解码。Stable Diffusion 并不是直接处理 512×512 的 RGB 图,而是通过 Encoder 将图像压缩到潜空间(512×512 → 64×64),再通过Decoder 将潜空间还原为图像(64×64 → 512×512) 。这一压一解,就是 VAE 的职能。
注意:如果是文生图,则不涉及编码过程。
通过 VAE 的压缩,把图像压缩到一个较小的潜空间(latent space),在这个空间中做扩散,可以显著节省显存和计算资源,速度提升几十倍,这就是 Latent Diffusion Models(LDM) 技术。最重要的,开启了模型本地部署的可行性。
graph LR
%% --- 样式定义 ---
%% 1. 像素空间:宽大的矩形,代表高维数据
classDef pixelSpace fill:#e1f5fe,stroke:#0288d1,stroke-width:2px,color:#01579b,rx:5,ry:5;
%% 2. 处理器(VAE):机械感的橙色,代表计算网络
classDef processor fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#e65100,rx:10,ry:10;
%% 3. 潜空间:核心的小圆/菱形,代表高度压缩的精华
classDef latentSpace fill:#f3e5f5,stroke:#9c27b0,stroke-width:3px,color:#4a148c,shape:circle;
%% --- 节点定义 ---
subgraph Pixel_Input [输入端:像素空间]
direction TB
ImgIn[输入图像<br/>Image]:::pixelSpace
end
NodeEnc[VAE Encoder<br/>压缩编码]:::processor
NodeLat((Latent<br/>潜空间表现)):::latentSpace
NodeDec[VAE Decoder<br/>还原解码]:::processor
subgraph Pixel_Output [输出端:像素空间]
direction TB
ImgOut[最终可视图<br/>Image]:::pixelSpace
end
%% --- 连接与标注 ---
ImgIn == 压缩 ==> NodeEnc
NodeEnc -- 降维特征 --> NodeLat
NodeLat -- 扩充特征 --> NodeDec
NodeDec == 还原 ==> ImgOut
%% --- 增加隐式背景连接让排版更直(可选) ---
%% linkStyle default stroke-width:2px,fill:none,stroke:#546e7a;
VAE 最后负责把像素“画出来”,所以它会直接影响:
- 肤色是否糊
- 灰高光与暗部的对比
- 衣服材质纹理是否清晰
- 漫画边缘是否锐利
- 色彩饱和度
如果 VAE 好,最终画面色彩会更柔和,细节更舒适;如果 VAE 较弱,可能会出现糊、脏、暗等问题。
整体流程
graph TB
%% --- 样式配置 ---
%% 1. 文本流:暖色,代表人类指令
classDef textStyle fill:#fff8e1,stroke:#ffb300,stroke-width:2px,color:#6f4c00,rx:5,ry:5;
%% 2. 潜空间流:紫色,代表抽象和随机
classDef latentStyle fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px,color:#4a148c,shape:hexagon;
%% 3. 模型计算:深蓝,代表处理核心
classDef modelStyle fill:#e8eaf6,stroke:#3949ab,stroke-width:2px,color:#1a237e,rx:10,ry:10,font-weight:bold;
%% 4. 逻辑判断:红色菱形
classDef logicStyle fill:#ffebee,stroke:#ef5350,stroke-width:2px,color:#b71c1c,shape:diamond;
%% 5. 最终产物:青绿色
classDef resultStyle fill:#e0f2f1,stroke:#00897b,stroke-width:3px,color:#004d40,rx:5,ry:5;
%% --- 区域 1: 提示词处理 ---
subgraph Conditioning [准备阶段: 提示词编码]
direction TB
A[文本提示词<br/>'a cat']:::textStyle
B[CLIP 编码器]:::modelStyle
C{{文本向量<br/>Embedding}}:::textStyle
end
%% --- 区域 2: 扩散去噪循环 ---
subgraph Diffusion [核心阶段: 潜空间去噪]
direction TB
D[随机噪声<br/>Gaussian Noise]:::latentStyle
E[UNet 神经网络<br/>预测噪声]:::modelStyle
F[去除噪声步骤]:::latentStyle
H{步数<br/>完成?}:::logicStyle
I((潜空间<br/>纯净图像)):::latentStyle
end
%% --- 区域 3: 像素还原 ---
subgraph Decoding [收尾阶段: 像素解码]
direction TB
J[VAE 解码器]:::modelStyle
K[最终图像<br/>Pixel Image]:::resultStyle
end
%% --- 连接关系 ---
A ==> B
B ==> C
%% 文本向量介入 UNet
C -. 引导 .-> E
D ==> E
E --> F
F --> H
H -- No (继续去噪) --> E
H -- Yes (完成) --> I
I ==> J
J ==> K
%% --- 连线着色 ---
%% 文本流 (橙色)
linkStyle 0,1 stroke:#ffb300,stroke-width:3px;
%% 引导线 (虚线)
linkStyle 2 stroke:#ffb300,stroke-width:2px,stroke-dasharray: 5 5;
%% 潜空间流 (紫色)
linkStyle 3,4,5 stroke:#8e24aa,stroke-width:3px;
%% 循环线 (红色)
linkStyle 6 stroke:#ef5350,stroke-width:2px;
%% 成功输出流 (绿色)
linkStyle 7,8,9 stroke:#00897b,stroke-width:3px;
第 1 篇,共 6 篇
相关推荐
Stable Diffusion 模型下载指南
详细介绍 Stable Diffusion 模型的下载渠道、文件格式说明以及安装方法
Checkpoint 模型详解与选择指南
深入解析 Stable Diffusion 的 Checkpoint 模型,帮助你选择适合自己创作需求的模型
Stable Diffusion 的版本演进
深入解析 Stable Diffusion 的版本演进,了解各个版本的特性和差异。