CV Predict Classifier
Load a cv2.ml model and classify in one step
- features
- predictions
- count
- success
The read side of the pack's small classic-ML corner. You trained a classifier earlier with CV Train Classifier and saved it with CV Save Classifier; this node loads it back and predicts on new feature rows.
What it's for
ComfyUI's model story is neural networks, and it has no clean concept of "a small trained SVM that lives in a file and classifies 36 numbers." OpenCV's cv2.ml module does, and this pack exposes it: HOG descriptors from CV HOG Features, frozen deep features from CV Deep Features, or BRISQUE's 36 natural-scene-statistics features from CV Quality BRISQUE Features all come out as rows, and this node labels them.
The genuinely good use case is a look classifier or defect classifier trained on your images. A pre-trained quality model has its own opinion about what good looks like; a few hundred labelled feature rows and this node give you your own. That's the reason CV Stack Feature Classes exists - build a labelled training matrix, train, save, and this node runs it at generation time.
How it works, and why it's built this way
Loading and predicting both happen inside one execute(). That isn't incidental. A loaded cv2.ml model is a stateful Python object, and ComfyUI caches node outputs - if the model travelled along a wire as graph state, a cached handle would get mutated by a later run and you'd get answers that depend on execution order. Keeping the model inside the call makes the node a pure function of its inputs, which is what the cache assumes. Same reasoning as CV Train Classifier and every class-API node in this pack.
You point model at a file from ComfyUI/models/cvml: the gzipped .yml.gz files CV Save Classifier writes, or a plain .yml/.yaml you drop in yourself. Or connect model_yaml with the model as YAML text - for example straight off CV Train Classifier - and it takes precedence over the file, letting you train and predict in one graph without touching disk.
Inputs and outputs
features is an (N, D) matrix, one row per sample; any shape flattens to rows. model is the file dropdown, model_yaml the text override. D is not negotiable: the feature length has to match what the model was trained on, which in practice means the same CV HOG Features settings applied to the same-size images. That's the number one cause of "it worked yesterday".
Outputs are predictions - an (N,) int32 array of labels, which for models built by CV Train Classifier are class indices 0..K-1 in the order you fed CV Stack Feature Classes - count, and success. success=false for a missing or corrupt file, a YAML that isn't a model, a feature-length mismatch, or empty features; you get empty predictions, never an exception. Wire it into an if/else node and branch, rather than letting empty arrays flow into the drawing nodes.
Installing
Pack-wide install. ComfyUI Manager → search "ComfyUI CV", or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
# restart ComfyUI
Python ≥ 3.12, recent ComfyUI on the V3 node API, opencv-contrib-python-headless~=5.0.0.93 plus numpy and torch. Models live in ComfyUI/models/cvml, which the pack registers with ComfyUI's folder paths the first time it loads.
Gotchas
The dropdown is built at page load. Save a classifier and it won't appear in the list until you reload the ComfyUI page - same mechanic as every model dropdown. Your file is fine; the list is stale.
Feature-length mismatch is silent in the logs and loud in your results. Check what the training features were before you trust a prediction: CV Array Shape on the feature array gives you D in one node.
Labels are indices, not names. The model predicts 0..K-1 in the class order you built the training matrix with. Keep that order in a note node, or the mapping between "class 3" and "blurry" lives only in your head.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| features | NPARRAY | (N, D) rows to classify (any shape flattens to one row per sample) - same D as at training time. | |
| model | COMBO | Saved classifier from ComfyUI/models/cvml (written by 'CV Save Classifier'). Reload the page to list files saved during the same session. | |
| model_yamlopt | STRING | Optional: a model as YAML text (e.g. straight from 'CV Train Classifier'). When connected and non-empty it overrides the model file above. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| predictions | NPARRAY | (N,) int32 predicted label per feature row (class indices 0..K-1 for models from 'CV Train Classifier'). Empty when success=false. |
| count | INT | How many rows were classified. |
| success | BOOLEAN | False when the model could not be loaded or the features do not fit it - gate with if/else. |