CV Class Scores Decode
Turning a raw score vector into 'top-1: golden retriever'
- scores
- labels_out
- scores_top
- class_ids
- top_label
What this is for
Every classification network ends the same way: a vector with one number per class. Useful - but only if you can turn index 207 into a word. CV DNN Pick Output gets you that vector out of a model's blob; CV Class Scores Decode does the last hundred metres: softmax (or not), sort, top-k, attach the class names.
It's a DATA node. It draws nothing. That's deliberate throughout this pack - the data nodes never render, so you choose what becomes a picture. Wire labels_out into Preview as Text, or use top_label as a STRING downstream.
How it works
The score vector arrives as (1, C) or (C,) and is flattened. Then the activation question: auto (the default) applies softmax only when the values lie outside [0, 1], because that's the signature of raw logits. If the model already ends in softmax or sigmoid, the values are probabilities and re-softmaxing them would flatten a confident prediction into mush. softmax and sigmoid force the operation; none never applies it. If your top-k proportions look weirdly uniform, this is the widget you got wrong.
After that it's a descending argsort and a slice - top-k, capped at the vector length so asking for 10 out of 5 classes returns 5 rather than erroring.
Inputs and outputs
Required: scores (the vector from DNN Pick Output) and top_k (default 5).
Optional:
activation-auto/softmax/sigmoid/none, as above. Advanced widget; the default is usually right.labels- class names, one per line, line N = class id N, pasted fromCV Load Labelsor anything else. Blank means classes are labelled by their numeric id, which is still readable output.
Four outputs:
labels_out-(K,)string array, best first. FeedPreview as Text.scores_top-(K,)float32 scores after the chosen activation, best first. This is the one you'd chart: run it throughCV Chart Seriesand you get labelled bars instead of a ranked list of numbers.class_ids-(K,)int32 ids, if you want to key off the index rather than the name.top_label- plain STRING of the top-1 name, for wiring into filenames, notes or prompts.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
# restart ComfyUI
Or ComfyUI CV in ComfyUI Manager (publisher bmad4ever). Needs Python ≥ 3.12 and a V3-node-API ComfyUI; opencv-contrib-python-headless~=5.0.0.93 comes with the pack. No model needed for this node - but the model that produced scores has to be an .onnx in ComfyUI/models/onnx, exported for cv2.dnn.
Common issues
- Every score comes back around the same value. You're softmaxing probabilities (or sigmoiding logits). Flip
activationtononeorautoand look again. - Labels don't line up.
labelsis line-indexed from zero, and the file has to match the model's class ordering - a different ImageNet-sorted list gives you confidently wrong names.CV Load Labelsreads the same text format the detectors use, so one label file can serve the whole graph. - The model doesn't load at all. This is the pack's honest weak spot, and its README says so: everything goes through
cv2.dnnon principle, the pinned OpenCV's DNN support is limited to older architectures, and a perfectly valid ONNX export can still be unloadable. CUDA is not available in these wheels either - the DNN backend/target selectors exist but are effectively inert on current builds. For anything ComfyUI already does natively, use the native node. - Contrib nodes vanished. Non-contrib OpenCV wheel clobbered the shared
site-packages/cv2;tools/repair_opencv_contrib.py --check/--apply.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| scores | NPARRAY | (1, C) or (C,) per-class scores/logits from the model (pick it out of 'DNN Forward All' with 'DNN Pick Output'). | |
| top_k | INT | 51–1000 | How many of the highest-scoring classes to emit. |
| activationopt | COMBO | auto | 'auto' applies softmax only when the values lie outside [0, 1] (i.e. raw logits). 'softmax'/'sigmoid' always apply, 'none' never (model already outputs probabilities). |
| labelsopt | STRING | Class names, one per line (line N = class id N), e.g. from 'CV Load Labels'. Blank = classes are labelled by their numeric id. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| labels_out | NPARRAY | (K,) string array of the top-k class labels, best first. Feed 'Preview as Text'. |
| scores_top | NPARRAY | (K,) float32 scores of the top-k classes (after the chosen activation), best first. |
| class_ids | NPARRAY | (K,) int32 class ids of the top-k classes. |
| top_label | STRING | The single best class label (top-1). |