Nodes/DOGMA Nodes/DOGMA V50 SAM Input Gate
ComfyUI Node

DOGMA V50 SAM Input Gate

Stop running SAM on categories that don't exist — the 64-pixel bypass

By axior·Created 4 months ago·Updated 3 days ago· 1
DOGMA V50 SAM Input Gate
  • image
  • image
  • info
category

Plans in this pipeline are always six groups wide, because a fixed-width plan keeps the graph static - no dynamic node creation, no list-length surprises. Which means most of your runs have dead slots in them: categories the VLM never saw in the frame, sitting in the plan as none with a placeholder segmentation prompt.

Left alone, each dead slot costs a full SAM pass over a 4K image. This node makes each dead slot cost almost nothing.

What it does

It reads category. If it's empty, none, or unused, it returns a 64×64 black image instead of your frame. Anything else, and it returns the first frame of the image at full resolution, RGB.

That's the entire node, and the cleverness is that SAM's cost scales with the input it's given. A promptable segmenter asked to find nonexistent_placeholder_object_xyz in a 64×64 black square has nothing to find and nothing to chew through. The gate turns an expensive no-op into a cheap one, without the graph needing a conditional or the plan needing to be shorter.

It never returns nothing, which matters more than it sounds: a segmenter handed a zero-size tensor throws, a segmenter handed a 64px black square returns an empty mask, and the downstream crop node already knows how to treat an empty mask as a no-op - that's a designed path in this pack, and this node is how you reach it.

Why it matters at scale: the KB's masking doc describes promptable segmentation (SAM 3 with text, or GroundingDINO boxes feeding SAM) as the standard way to turn a named region into a mask, and notes the practical cost - Triton dependencies, real VRAM, and a per-pass price that only pays off when there's something to find. Multiply one wasted SAM pass by four dead categories by every tile in a 5K restoration and the bypass stops being a micro-optimisation.

Inputs and outputs

  • image - your master or tile.
  • category - a STRING, forced input, from the plan node. none / "" / unused trigger the bypass; anything else passes the frame through.

Outputs image (the gated frame) and info. The info string tells you which branch fired - inactive -> 64px SAM bypass or active 'cars' -> full 5K image to tiled SAM3 - which is a genuinely useful row to read when you're checking that the plan's categories landed where you expected. If a category you know is in the photo reports inactive, your plan canonicalisation failed upstream, not here.

Install

ComfyUI Manager → search DOGMA Nodes, or:

cd ComfyUI/custom_nodes && git clone https://github.com/axior/ComfyUI-DOGMA-Nodes

Restart ComfyUI. The node itself is dependency-free - the pack's requirements.txt is one line, # No external dependencies. - but the SAM node it feeds is a separate install with its own weights and, depending on which SAM you use, its own Triton requirement. The pack's README doesn't document this node; it registers from dogma_semantic_v5641.py.

Where it bites

The gate only understands three magic strings. none, unused, and empty. Anything else - 0, null, N/A, nonexistent - passes the full frame through, and you're back to paying for a pointless SAM pass. If your plan node writes a different sentinel, you get silent waste rather than an error. Watch the info output when you first wire a new plan node up.

It's a cost gate, not a correctness gate. The output is a black 64×64 image, so anything downstream that assumes "same size as the master" will break on a dead slot. In this pipeline the crop nodes explicitly handle no-op metas, so that's fine - in someone else's graph, it's a size mismatch waiting to happen.

Nothing is logged to the console. The only evidence of what happened is the info string; if you're wondering why a category never produced a crop, that string is where the answer is.

Don't use it as an on/off switch for a category you want. Returning a black frame does not cancel the group - it makes the segmenter return an empty mask, and the pipeline continues. If you want the group gone, take it out of the plan.

CategoryDOGMA/v50

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
categorySTRING

Outputs (2)

NameTypeDescription
imageIMAGE
infoSTRING