Nodes/ComfyUI CV/CV DNN Pick Output
ComfyUI Node

CV DNN Pick Output

Getting the right tensor out of a multi-output ONNX model

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
CV DNN Pick Output
  • outputs
  • output
  • index
◄modeby index►
◄index0►
◄output_names—►
◄name►

Why you'd reach for this

CV DNN Forward returns one array. CV DNN Forward All returns every unconnected output of the net, in a list. That's great for a YOLO seg model, which emits a detection head and a prototype map, and less great if you then have to remember which list position is which.

That's this node: one output in, one output out, chosen by index, by layer name, or - the part that actually saves you - by shape. It's plumbing, and it lives in the plumbing layer of a graph, where the whole point is that nothing downstream has to care that the model had four outputs.

How it works

Seven modes:

  • by index - uses the index widget, 0-based, in the order Forward All reports.
  • first / last - the ends of the list.
  • by name - matches the name widget against the output_names string you wire in from Forward All. Exact match first, then a substring match, so "proto" will find "proto_0". If nothing matches it raises and lists the names it did see.
  • 3-D detection head - first tensor with 3 dimensions, i.e. the (1, N, C) head.
  • 4-D prototype map - first 4-D tensor that is not a (..., 1, 4) box tensor.
  • 4-D map (highest resolution) - the 4-D output with the largest H*W.

That last one exists because of a real behaviour worth knowing: getUnconnectedOutLayersNames() is not in a stable order. The pack's own comment records measuring RAFT list ['12007', '12006'] on the default engine and the reverse on the classic engine - so by index or last on a multi-scale model can silently hand you a different tensor depending on which engine you picked. If a model returns the same field at two resolutions, use this mode or pick by name.

Both outputs are useful: output is the array, index is the position it came from, which is how you find out where a name- or shape-based pick actually landed.

Inputs and outputs that matter

  • outputs - the list from CV DNN Forward All. An empty list raises immediately with a message telling you to check the blob, which is a nicer failure than three nodes of silence.
  • mode + index - the common case. Set mode to by index and count, or avoid counting entirely with a shape mode.
  • output_names + name - the robust case. Wire the output_names STRING out of Forward All and name the layer you want; order stops mattering.
  • output → straight into the matching decoder (CV YOLO Detect Decode, CV YOLO Seg Masks, CV Class Scores Decode), or into Inspect CV Data when you have no idea what the model just did.

Chain one picker per output you need. Two pickers, two decoders, same Forward All - that's the whole pattern.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"

Python ≥ 3.12 and a recent ComfyUI (V3 API), or install "ComfyUI CV" through ComfyUI Manager. The model files live under ComfyUI/models/onnx and are not bundled - model_sources.txt in the repo root has the URLs and licenses.

Common issues

  • "found no matching output among N outputs" - the error prints every output shape it saw. Read that; it's the fastest diagnosis in the whole pack. Usually it's the wrong engine, so the net exposed one output instead of four.
  • by name fails - output_names isn't wired. The node can't guess the names off the arrays themselves.
  • Detections decode into nonsense - you picked the prototype map with the detection head's decoder, or vice versa. Check the picked index output against the shape you expect: a head is (1, N, C), a proto map is (1, C, H, W).
  • Wrong resolution map after switching engines - the layer ordering moved, as described above. Name-pick or use the highest-resolution heuristic.
  • Contrib wheels. This pack needs the contrib OpenCV build; installing a plain opencv-python over it silently empties the contrib submodules. tools/repair_opencv_contrib.py --check / --apply fixes that.
Categoryimage/CV/dnn

Inputs (5)

NameTypeDefaultDescription
outputsNPARRAYThe 'outputs' list from 'CV DNN Forward All'.
modeCOMBOby indexHow to pick: 'by index' uses the index widget; 'by name' matches the name widget against the connected output_names; the shape heuristics pick the first output with that number of dimensions, except '4-D map (highest resolution)', which picks the 4-D output with the largest H*W (the full-res flow of a multi-scale model, whatever order the engine lists the layers in); 'first'/'last' pick the ends.
indexINT00–63Position to pick when mode = 'by index' (0-based, matching the output_names order).
output_namesoptSTRINGThe 'output_names' STRING from 'CV DNN Forward All' (needed for mode = 'by name').
nameoptSTRINGLayer name to pick when mode = 'by name'. Exact match first, then substring match.

Outputs (2)

NameTypeDescription
outputNPARRAYThe picked output array.
indexINTThe position the array was picked from (useful when a name or shape heuristic did the picking).