Nodes/ComfyUI-YOLO/Ultralytics Flatten Masks
ComfyUI Node

Ultralytics Flatten Masks

Stick every detection into one mask

By kadirnar·Created 2 years ago·Updated 7 months ago· 121
Ultralytics Flatten Masks
  • masks
  • MASK

UltralyticsInference's MASK output gives you one mask per detection - a batch of N rectangle masks, one per box. Most downstream ComfyUI nodes want a single mask for the whole image. This node is the glue: it takes that (N, H, W) batch and maxes across the object dimension, producing one (1, H, W) mask that's the union of every detection. A 4D (B, N, H, W) batch (video frames) gets collapsed per frame instead.

In plain terms: detected a person and a car? Flatten them and you get a mask covering both. That's the whole mechanism - a torch.max over the detection axis, which is a logical OR. Nothing fancy, nothing hidden.

Why you'd reach for it: a mask is the input most of ComfyUI's conditional tooling wants. Take the flattened mask, feed it into an inpaint node or a detailer, and you're doing region-targeted work on "everything the detector found" without needing to know which detection was which. It's the natural bridge from this pack's detection output into the wider ecosystem of mask-driven nodes - the same territory where Impact Pack's FaceDetailer and the ADetailer-style detect-then-fix workflows live, except you control the mask yourself.

One caveat worth knowing: these are box masks - rectangles from the detections, not true segmentation silhouettes. For "detect the person and inpaint the box" it's exactly right; if you want a mask that follows the outline of the object, you need a segmentation model and the MASKS output instead. And when nothing was detected, the upstream returns a single empty mask rather than a batch - flattening still behaves.

Install is the shared pack story: ComfyUI Manager (search "ComfyUI-YOLO"), or clone into custom_nodes, restart, with ultralytics>=8.2.27 handled by Manager. One input, one output - this is the pack's smallest honest node, and it exists because detection-to-mask was the gap.

CategoryUltralytics/PostProcess

Inputs (1)

NameTypeDefaultDescription
masksMASK

Outputs (1)

NameTypeDescription
MASKMASK