批量处理工作流

批量处理工作流用于批量生成和处理图像,提高工作效率,适合需要生成大量图像的场景。

工作流概述

工作流信息

功能特点

适用场景

工作流结构

批量处理工作流示意图

下图展示了批量处理工作流的完整流程:

这个图展示了: - 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

核心节点说明

使用步骤

步骤1: 准备工作

  1. 准备提示词列表
  2. 确定batch_size
  3. 准备模型文件

步骤2: 加载工作流

  1. 打开ComfyUI
  2. 点击"Load"按钮
  3. 选择工作流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: 执行工作流

  1. 点击"Queue Prompt"按钮
  2. 等待批量生成完成
  3. 查看生成的图像

工作流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: 批量肖像

示例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

优化建议

性能优化

质量优化

效率优化

常见问题

Q1: batch_size设置多少合适?

A: 根据显存大小,通常2-4,大显存可以8+。

Q2: 如何批量生成不同提示词?

A: 修改提示词后多次执行,或使用脚本自动化。

Q3: 批量生成显存不足怎么办?

A: 减小batch_size,降低分辨率,使用低显存模式。

Q4: 如何自动化批量处理?

A: 使用脚本或插件自动化执行工作流。

Q5: 批量生成速度慢怎么办?

A: 减少steps,使用快速采样器,增加batch_size。

变体工作流

变体1: 大批量

变体2: 高质量批量

变体3: 多样化批量

相关工作流

扩展阅读

更新日志