Nodes/comfyui_bmab/BMAB Detect And Mask
ComfyUI Node

BMAB Detect And Mask

Turning an object detector into a usable mask

By portu-sim·Created 2 years ago·Updated 8 months ago· 124
BMAB Detect And Mask
  • image
  • mask
model
dilation4

This is the detection half of BMAB's detect-crop-refine machinery - the node that answers "where is the thing I care about in this image," and hands you back a mask you can feed anywhere a mask is expected, most naturally into BMAB Detail Anything.

What it is and why you'd reach for it

You give it an image and a detection model, and it finds whatever that model was trained to find, returning a MASK covering the detected region(s). This is the same pattern as GroundingDINO-plus-SAM pipelines elsewhere in the ComfyUI ecosystem: a text-prompted or class-based detector finds the object, and the mask it produces feeds a downstream refinement or compositing step rather than being the end product itself. In BMAB's case, the obvious next stop is BMAB Detail Anything, but nothing stops you from wiring this mask into a stock ComfyUI inpainting node either.

Where this earns its place over manually painting a mask: batch processing (running the same detection across many images without touching each one by hand), or any workflow where you don't know in advance exactly where the target region will land.

How it works

Per the README, BMAB's object detection runs on Hugging Face's transformers library, which has shipped a Grounding DINO implementation since v4.40.0 - no separate model install needed for that specific detector, it comes along with the dependency BMAB already requires. The dilation setting grows the raw detected mask outward slightly before it's returned, which matters for whatever consumes it downstream: a mask that hugs the detected box too tightly tends to leave a visible seam once something gets resampled or pasted into it.

Inputs and outputs

  • image (required) - the image to run detection on.
  • model (required, dropdown) - the detection model to use. This dropdown is populated from whatever detection models you have installed; if it's empty, you haven't added one yet.
  • dilation (default 4, range 4–128) - how much to grow the detected region before returning it as a mask.

Output: a single mask.

Installing it

Through ComfyUI Manager: search comfyui_bmab, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/portu-sim/comfyui_bmab.git
cd comfyui_bmab
pip install -r requirements.txt

The README is explicit that Grounding DINO detection rides on transformers>=4.40.0 and needs no separate install - it should already be satisfied by BMAB's own requirements.txt. This node doesn't need comfyui_controlnet_aux or ComfyUI_IPAdapter_plus.

Common issues

  • transformers version mismatches breaking detection outright. This is a real, reported problem, not a hypothetical one - people have hit an error along the lines of GroundingDinoProcessor.post_process_grounded_object_detection() got an unexpected keyword argument 'box_threshold' when running BMAB's detection nodes, which is a signature mismatch between the transformers version installed and what BMAB's code expects. If detection nodes throw an error mentioning box_threshold or a similar unexpected-keyword-argument complaint, the fix is matching your transformers version to what's pinned in comfyui_bmab/requirements.txt rather than assuming the latest release is safe - a newer transformers can silently change a method's signature out from under a pack that was written against an older one.
  • Empty model dropdown. Means no detection model is installed where BMAB expects to find one - check your setup against the README's model-file guidance before assuming the node itself is broken.
  • Detected mask too tight, causing a visible seam downstream. Bump dilation up before troubleshooting further downstream - a slightly larger mask blends more forgivingly into whatever refinement or paste operation follows.
CategoryBMAB/imaging

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
modelCOMBO0 options:
dilationINT44–128

Outputs (1)

NameTypeDescription
maskMASK