Nodes/ComfyUI-MultiMaskOps/Mask List To Batch
ComfyUI Node

Mask List To Batch

The glue that welds a mask list back into one batch

By INuBq8·Created 2 months ago·Updated 2 months ago· 0
Mask List To Batch
  • masks
  • masks

Mask List To Batch is the return trip. You ran some per-subject processing on a pile of individual masks, and now a downstream node is demanding a single mask batch and won't take no for an answer. This node takes your list and welds it into one [N, H, W] tensor.

The whole MultiMaskOps pack is built around a distinction ComfyUI rarely forces you to think about. A batch is one tensor holding N masks - what a segmenter hands you when it finds N subjects in one image. A list is a Python list of separate mask tensors, and several nodes in this pack (Sort, Pick, Deduplicate, Expand) only work on lists so they can treat each mask independently. Mask Batch To List is the front door; this is the exit.

How it works

Mechanically it's boring, in the best way. Each mask gets normalized to [1, H, W] (a flat 2D mask gets a batch dimension added), anything that doesn't match the first mask's size gets resized to match it via nearest-neighbor interpolation, and the lot is torch.cat'd into a single [N, H, W] batch. That's the whole node.

The inputs and outputs that matter

There's exactly one of each, so this is a short list:

  • masks - the list you're combining. Feed it the list output of another MultiMaskOps node, like Mask Expand Without Overlap or Mask Sort By Position.
  • masks (output) - a single batch tensor, ready for nodes that want one. Wire it into MaskToImage, an inpaint setup, or anything expecting a normal mask batch.

Where people get burned: the resize-to-first step is nearest-neighbor, so if your list holds masks at different resolutions, edges can shift by a pixel when they're squashed to match. For most jobs nobody notices. If pixel-exact alignment matters - say you're compositing back over the original image - keep every mask at the same resolution and this step becomes a no-op.

Installation

Same story as the rest of the pack - no models, no extra Python packages:

cd ComfyUI/custom_nodes
git clone https://github.com/INuBq8/ComfyUI-MultiMaskOps

Restart ComfyUI and the nodes show up under MultiMaskOps. ComfyUI Manager should find it too (search "MultiMaskOps"), though the README hedges on that with a "(soon)", so the clone is the reliable path. The requirements.txt is empty; it leans on torch/scipy/torchvision, all of which ship with ComfyUI.

Troubleshooting

  • torch.cat on an empty list - joining zero masks blows up. Make sure the upstream node actually produced masks before you convert back.
  • Feeding it a batch by mistake - the input here is a list. If you wire in a single batch tensor, you're giving it one entry, not N. Chain this behind Mask Batch To List (or another list-output node), not directly behind your segmenter.

It's a two-minute utility, and it's fine that it is. You'll forget it exists until the exact moment a workflow won't run without it.

CategoryMultiMaskOps

Inputs (1)

NameTypeDefaultDescription
masksMASKA list of masks. Output is a single batch tensor [N, H, W]. Masks of differing sizes are resized to match the first.

Outputs (1)

NameTypeDescription
masksMASK