Nodes/ComfyUI-QING/批处理丨图像收集
ComfyUI Node

批处理丨图像收集

Accumulate images run after run into one growing batch

By sheengoa·Created about a year ago·Updated 20 days ago· 16
批处理丨图像收集
  • item_image
  • images
  • count
resetfalse
max_items999

The awkward thing about a "for each" loop in ComfyUI is that each iteration produces one image, and you usually want them all back as a batch at the end. QING_BatchCollect is the collecting side of that loop: it remembers every image you feed it across executions, stacks them, and outputs the growing batch plus a count. Feed it the output of QING_BatchForEach and you've got a working loop-accumulator.

What it does

Inputs: item_image (an IMAGE - it can itself be a batch, in which case every frame in it gets collected individually), reset (boolean, default false - clear the history cache before collecting), and max_items (int, default 999). Outputs: images (the accumulated batch) and count (how many frames are in it).

Mechanically it's a class-level list that appends each incoming frame and torch.cats the whole thing on every execution. The node sets IS_CHANGED to return NaN, which is the standard "always re-run me" trick from the node-plumbing doc - it can't be cached, because its state changes every call. That's also what makes the accumulating work at all: the node fires every execution regardless of whether its inputs "changed."

The loop it's built for

Pair it with QING_BatchForEach: extract frame N, process it, collect it here; bump the index, repeat. When is_last fires, count tells you exactly how many frames you gathered, and the collected images batch feeds a grid node, a QING_SaveImage, or a final pass. This is the "iterate and gather" pattern made out of two plain nodes instead of a bespoke loop extension.

Installing it

Ships in ComfyUI-QING:

cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py

Restart ComfyUI after. Pure torch, nothing extra to install beyond the pack's standard requirements. Manager users: search "ComfyUI-QING." And the README's GAOSHI-QING clone-URL typo is wrong - the repo is GAO-SHIQING/ComfyUI-QING.

Things to know

Two genuine traps, and one of them will bite you. The cache is shared across every workflow that uses this node - it's a class-level list, not per-graph or per-run. If two of your workflows both use QING_BatchCollect, they can leak images into each other. The reset input exists precisely for this: set it true on the first iteration of any loop (or permanently in a one-shot setup) so stale frames are cleared before you start. Second trap: exceeding max_items raises an error rather than truncating - the default of 999 is generous but it's not infinite, and a runaway loop will eventually fail loudly. Which is arguably the feature: better an error than a silently wrong batch.

CategoryQING/数据工具

Inputs (3)

NameTypeDefaultDescription
item_imageIMAGE输入单张图像(可为批次,将逐张收集)
resetBOOLEANfalse是否清空历史缓存后再收集
max_itemsINT9991–10000最多收集数量

Outputs (2)

NameTypeDescription
imagesIMAGE
countINT