工作流概述
工作流信息
- 工作流类型: 批量处理
- 难度等级: 高级
- 预计执行时间: 取决于batch_size
- 推荐模型: Stable Diffusion 1.5
- ComfyUI版本要求: >= 1.0
功能特点
- 批量生成图像
- 自动化处理
- 提高效率
- 节省时间
- 统一质量
适用场景
- 大量图像生成
- 批量风格转换
- 批量图像处理
- 自动化工作流
- 数据集生成
工作流结构
批量处理工作流示意图
下图展示了批量处理工作流的完整流程:
这个图展示了: - EmptyLatentImage: 创建空白潜在空间(batch_size控制数量) - KSampler: 批量采样生成 - VAEDecode: 批量解码为图像 - SaveImage: 保存N张图像 - batch_size设置: 1-2(低显存)、4-8(中显存)、8-16(高显存)
节点流程图(Mermaid)
graph TD
A[CheckpointLoaderSimple] -->|MODEL| B[KSampler]
A -->|CLIP| C[CLIPTextEncode]
A -->|CLIP| D[CLIPTextEncode]
A -->|VAE| E[VAEDecode]
C -->|CONDITIONING| B
D -->|CONDITIONING| B
F[EmptyLatentImage] -->|LATENT| B
B -->|LATENT| E
E -->|IMAGE| G[SaveImage]
H[TextMultiline] -->|TEXT| I[CLIPTextEncode]
style A fill:#e1f5ff
style B fill:#fff4e1
style C fill:#ffe1f5
style D fill:#ffe1f5
style E fill:#e1ffe1
style F fill:#e1ffe1
style G fill:#ffe1e1
style H fill:#e1ffe1
style I fill:#ffe1f5
批量生成流程
graph LR
A[输入提示词列表] --> B[循环处理] --> C[生成图像] --> D[保存图像]
B -->|重复| E[下一个提示词] --> B
C -->|批量| F[多个图像]
style A fill:#e1ffe1
style B fill:#fff4e1
style C fill:#fff4e1
style D fill:#ffe1e1
style E fill:#e1ffe1
style F fill:#ffe1e1
核心节点说明
- 作用: 创建空白潜在空间
- 关键参数: batch_size(批处理大小)
- CheckpointLoaderSimple: 加载模型
- CLIPTextEncode: 编码提示词
- KSampler: 执行采样
- VAEDecode: 解码潜在空间
- SaveImage: 保存图像
使用步骤
步骤1: 准备工作
- 准备提示词列表
- 确定batch_size
- 准备模型文件
步骤2: 加载工作流
- 打开ComfyUI
- 点击"Load"按钮
- 选择工作流JSON文件
步骤3: 配置参数
ckpt_name: v1-5-pruned-emaonly.ckpt
text: beautiful landscape, mountains, sunset, 4k, detailed
text: ugly, blurry, low quality
width: 512
height: 512
batch_size: 4 # 一次生成4张
seed: 123456789
steps: 20
cfg: 8
sampler_name: euler
scheduler: normal
denoise: 1.0
filename_prefix: batch_
步骤4: 执行工作流
- 点击"Queue Prompt"按钮
- 等待批量生成完成
- 查看生成的图像
工作流JSON
基础批量生成
{
"3": {
"inputs": {
"seed": 123456789,
"steps": 20,
"cfg": 8,
"sampler_name": "euler",
"scheduler": "normal",
"denoise": 1.0,
"model": ["4", 0],
"positive": ["6", 0],
"negative": ["7", 0],
"latent_image": ["5", 0]
},
"class_type": "KSampler"
},
"4": {
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly.ckpt"
},
"class_type": "CheckpointLoaderSimple"
},
"5": {
"inputs": {
"width": 512,
"height": 512,
"batch_size": 4
},
"class_type": "EmptyLatentImage"
},
"6": {
"inputs": {
"text": "beautiful landscape, mountains, sunset, 4k, detailed",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode"
},
"7": {
"inputs": {
"text": "ugly, blurry, low quality",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode"
},
"8": {
"inputs": {
"samples": ["3", 0],
"vae": ["4", 2]
},
"class_type": "VAEDecode"
},
"9": {
"inputs": {
"filename_prefix": "batch_",
"images": ["8", 0]
},
"class_type": "SaveImage"
}
}
多提示词批量生成
{
"3": {
"inputs": {
"seed": 123456789,
"steps": 20,
"cfg": 8,
"sampler_name": "euler",
"scheduler": "normal",
"denoise": 1.0,
"model": ["4", 0],
"positive": ["6", 0],
"negative": ["7", 0],
"latent_image": ["5", 0]
},
"class_type": "KSampler"
},
"4": {
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly.ckpt"
},
"class_type": "CheckpointLoaderSimple"
},
"5": {
"inputs": {
"width": 512,
"height": 512,
"batch_size": 1
},
"class_type": "EmptyLatentImage"
},
"6": {
"inputs": {
"text": "beautiful landscape, mountains, sunset",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode"
},
"7": {
"inputs": {
"text": "ugly, blurry, low quality",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode"
},
"8": {
"inputs": {
"samples": ["3", 0],
"vae": ["4", 2]
},
"class_type": "VAEDecode"
},
"9": {
"inputs": {
"filename_prefix": "batch_",
"images": ["8", 0]
},
"class_type": "SaveImage"
}
}
批量处理策略
策略1: 单次批量
graph LR
A[设置batch_size=4] --> B[一次生成4张] --> C[保存4张图像]
style A fill:#e1ffe1
style B fill:#fff4e1
style C fill:#ffe1e1
策略2: 多次批量
graph LR
A[设置batch_size=2] --> B[第一次生成2张] --> C[第二次生成2张] --> D[第三次生成2张] --> E[共6张]
style A fill:#e1ffe1
style B fill:#fff4e1
style C fill:#fff4e1
style D fill:#fff4e1
style E fill:#ffe1e1
策略3: 提示词循环
graph LR
A[提示词1] --> B[生成] --> C[保存]
D[提示词2] --> E[生成] --> F[保存]
G[提示词3] --> H[生成] --> I[保存]
style A fill:#e1ffe1
style B fill:#fff4e1
style C fill:#ffe1e1
style D fill:#e1ffe1
style E fill:#fff4e1
style F fill:#ffe1e1
style G fill:#e1ffe1
style H fill:#fff4e1
style I fill:#ffe1e1
参数配置指南
关键参数说明
- 1-2: 低显存,慢速
- 2-4: 标准配置,平衡
- 4-8: 高显存,快速
- 8+: 需要大显存
- 固定seed: 生成相似图像
- 随机seed: 每次生成不同图像
- seed范围: 使用不同seed生成不同图像
- batch_size vs 显存: batch_size越大需要越多显存
- steps vs 速度: steps越多质量越好但越慢
- sampler vs 速度: 不同采样器速度不同
示例结果
示例1: 批量风景
- batch_size: 4
- 提示词: beautiful landscape, mountains, sunset
- seed: 随机
- 结果: 4张不同风景图像
示例2: 批量肖像
- batch_size: 2
- 提示词: portrait of beautiful woman, detailed
- seed: 随机
- 结果: 2张不同肖像图像
示例3: 多提示词
- 提示词1: landscape, mountains
- 提示词2: portrait, woman
- 提示词3: anime style, girl
- 结果: 3张不同风格图像
自动化技巧
技巧1: 脚本自动化
# 使用脚本自动执行工作流
for i in {1..10}; do
python batch_generate.py --prompt "prompt_$i" --seed $RANDOM
done
技巧2: 提示词文件
# prompts.txt
beautiful landscape, mountains, sunset
portrait of beautiful woman, detailed
anime style, girl, vibrant colors
abstract art, geometric shapes
技巧3: 参数变化
graph LR
A[基础参数] --> B[变化1<br/>seed变化] --> C[变化2<br/>cfg变化] --> D[变化3<br/>steps变化] --> E[生成多种结果]
style A fill:#e1ffe1
style B fill:#fff4e1
style C fill:#fff4e1
style D fill:#fff4e1
style E fill:#ffe1e1
优化建议
性能优化
- 合理batch_size: 根据显存设置batch_size
- 减少steps: 提高速度
- 使用快速采样器: euler或lcm
- 降低分辨率: 使用较小分辨率
质量优化
- 增加steps: 提高质量
- 使用高质量采样器: dpmpp_2m
- 改进提示词: 使用更好的提示词
- 使用LoRA: 添加LoRA增强
效率优化
- 自动化脚本: 使用脚本自动化
- 批量处理: 使用批量处理
- 并行处理: 利用多GPU
- 任务队列: 使用任务队列
常见问题
Q1: batch_size设置多少合适?
A: 根据显存大小,通常2-4,大显存可以8+。
Q2: 如何批量生成不同提示词?
A: 修改提示词后多次执行,或使用脚本自动化。
Q3: 批量生成显存不足怎么办?
A: 减小batch_size,降低分辨率,使用低显存模式。
Q4: 如何自动化批量处理?
A: 使用脚本或插件自动化执行工作流。
Q5: 批量生成速度慢怎么办?
A: 减少steps,使用快速采样器,增加batch_size。
变体工作流
变体1: 大批量
- batch_size: 8
- steps: 15
- 用途: 快速大量生成
变体2: 高质量批量
- batch_size: 2
- steps: 30
- 用途: 高质量批量生成
变体3: 多样化批量
- 使用不同提示词
- 使用不同seed
- 用途: 生成多样化图像
相关工作流
扩展阅读
更新日志
- 2026-01-26: 初始版本创建