ZML_批次到整数
How many images in that batch? This node counts for you
- 图像批次
- 图像数量
- 文本行数
A tiny counting node that turns an image batch into a number. You feed it an image batch and it reports how many images are in it; feed it a text string and it reports how many lines that text has. Both inputs are optional and both outputs fire independently. It's the kind of node you reach for when a workflow needs to know its own scale - "we got 12 images this run, so loop 12 times" - or when you want a batch's size wired into a filename, a loop bound, or a progress readout.
How it works
The mechanism is ComfyUI's tensor shapes plus newline counting. For the image batch, len(图像批次) returns the size of the batch dimension - a tensor of shape [12, H, W, 3] reports 12. For text, it counts lines with splitlines(), which handles \n, \r, and \r\n correctly. Two subtleties: if the text input is actually a list (some upstream nodes hand lists), it counts list items instead of lines; and an empty string counts as 0 lines. Both inputs are optional, so an unfed input just reports 0 - there's no error, no crash, nothing to configure.
That simplicity is the whole appeal: it's a passive sensor, not a processor. Put it between your batch-producing node and the rest of the graph and you always have the batch size as a plain integer to branch on.
The inputs
- 图像批次 - any image tensor (batch optional).
- 文本 - a string, or a list of strings.
Outputs: 图像数量 (INT) and 文本行数 (INT).
Installing
Standard pack:
cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image
restart, or ComfyUI Manager. No extra dependencies - it's pure torch and Python. Translation patch at https://github.com/zml-w/ZZZ_ZML_English_Patch for English labels.
Common issues
The counting is only as good as what you feed it. "Number of images" means the batch dimension - a single image (shape [1, H, W, 3]) reports 1, which is correct, but if your upstream node emits a batch of 1 even when you expected more, that's an upstream problem this node faithfully reports. Also, the image output is a plain count, not a loop: if you want to iterate that many times, you still need a loop node - this just supplies the bound. And remember unfed inputs report 0 silently, so a disconnected socket doesn't error; it just lies to you with a zero. For wiring batch sizes into conditions, loop bounds, or the pack's ZML_双整数V3(判断) aspect picker, this is the one.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| 图像批次opt | IMAGE | — | |
| 文本opt | STRING | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 图像数量 | INT | — |
| 文本行数 | INT | — |