Nodes/comfyui_face_parsing/MaskBatchComposite(FaceParsing)
ComfyUI Node

MaskBatchComposite(FaceParsing)

Collapse a batch of masks into one

By Ryuukeisyou·Created 3 years ago·Updated about a year ago· 193
MaskBatchComposite(FaceParsing)
  • mask
  • MASK
operation

Where MaskComposite combines two named masks (destination and source), this one takes a single batched MASK input - think of it as a stack of masks bundled into one tensor - and reduces the whole stack down to one mask, folding every element together with the operation you pick. Same family of boolean/arithmetic ops, different shape of input: one mask in, but it's secretly many.

Where this fits

A face-parsing model that segments into multiple classes at once naturally wants to hand you a batch: one mask per class, stacked. If you don't need them individually - you just want "all the regions I asked for, combined into one selection" - running them through a chain of separate MaskComposite nodes gets tedious fast, especially if the class count isn't fixed. MaskBatchComposite does that reduction in one node: feed it the whole batch, pick add/or for a union of everything in the stack, or multiply/and if you specifically want the overlap across every mask in the batch (rarer, but real - e.g., confirming a pixel is claimed by more than one class where your classes overlap).

It's worth being clear about the distinction from its sibling MaskListComposite, which does a very similar job but takes a Python list of masks rather than a stacked batch tensor. Which one you need depends on how the node upstream of it hands you its output - a batch (uniform tensor, same size across the stack) versus a list (which can tolerate masks of different sizes). If you're not sure which shape you've got, MaskBatchComposite is the one to reach for first when the upstream node's output is behaving like a normal batched ComfyUI tensor.

The inputs that matter

  • mask - the batched mask input. This is doing all the work; there's no second mask to name because the whole batch is the input.
  • operation - a dropdown of five: multiply, add, and, or, xor. Notably one shorter than MaskComposite's six-option list - no subtract here, which makes sense once you think about it: subtraction needs a clear "this one minus that one" direction, which doesn't translate cleanly to reducing an unordered stack. add/or (union) is what you'll reach for most; xor across more than two masks gets conceptually murky fast, so use it deliberately rather than by habit.

Output is a single MASK. From there it's the same story as everywhere else in this pack: feed it to MaskBorderDissolve if the edges need softening, or MaskInsertWithBBox if you need to place it back into full-image coordinates.

Installing it

Via ComfyUI Manager: search comfyui_face_parsing, install, restart. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/Ryuukeisyou/comfyui_face_parsing.git

Restart ComfyUI. The pack's model files - the face-parsing segmentation model and a YOLOv8 face detector - download on first run to models/face_parsing/ and models/ultralytics/bbox respectively, both from HuggingFace. If that connection is unreliable, the README lists the jonathandinu/face-parsing and Bingsu/adetailer files to grab manually.

Where it bites

The main trap is a shape mismatch you don't notice until the result looks wrong: if what you're feeding in isn't actually a properly batched, same-size stack of masks - say, it's a list that got coerced into a batch somewhere upstream, or the batch dimension has a stray single mask of a different resolution in it - the composite either errors or quietly produces something that doesn't match your intent. Since there's no subtract, don't go hunting for it if you need directional exclusion; drop down to MaskComposite for that instead, applied pairwise, or restructure so the mask you want to exclude is handled before it enters the batch at all.

Categoryface_parsing

Inputs (2)

NameTypeDefaultDescription
maskMASK
operationCOMBO5 options: multiply, add, and, or, xor

Outputs (1)

NameTypeDescription
MASKMASK