Nodes/comfyui_cv/CV Embedding Match
ComfyUI Node

CV Embedding Match

Matches every vector in one embedding set against every vector in another, with the two metrics cv2.FaceRecognizerSF.match implements: cosine similarity and the L2 distance between L2-normalized vectors. Written as plain array maths on purpose - it needs no model file and therefore works on ANY embeddings, not just SFace: the 'CV Deep Features' backbone vectors, DNN class scores, your own descriptors. Typical use: 'query' = the faces in the scene, 'gallery' = the known people; then 'best_index' says who each query face is and 'is_match' says whether to believe it. Empty inputs give empty outputs, never an error.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Embedding Match
  • query
  • gallery
  • scores
  • best_index
  • best_score
  • is_match
  • any_match
metriccosine similarity (higher = same)
threshold0.363
Categoryimage/CV/dnn

Inputs (4)

NameTypeDefaultDescription
queryNPARRAY(A, D) embeddings to identify - e.g. the faces found in the scene. A single (D,) vector is accepted as one row.
galleryNPARRAY(B, D) known reference embeddings, same dimension D. Each query row is compared against all of them.
metricCOMBOcosine similarity (higher = same)The two metrics cv2.FaceRecognizerSF.match implements. Cosine is a SIMILARITY (bigger is more alike, best match = maximum); normalized L2 is a DISTANCE (smaller is more alike, best match = minimum). This only chooses HOW scores are computed and compared - where the accept/reject line sits is entirely the 'threshold' input.
thresholdFLOAT0.363-1–100Decision threshold for 'is_match', always used: with cosine a match needs score >= threshold, with normalized L2 it needs score <= threshold. The right value depends on YOUR embeddings; as a reference, SFace's official face-identity operating points are 0.363 (cosine) and 1.128 (normalized L2), which is where the default comes from. Remember to change it when you switch metric.

Outputs (5)

NameTypeDescription
scoresNPARRAY(A, B) float32 score matrix, query rows x gallery columns - preview it with 'Preview CV Array' (heatmap) to see the whole comparison at once.
best_indexNPARRAY(A,) int32 index of the best gallery entry for each query row (-1 when the gallery is empty).
best_scoreNPARRAY(A,) float32 score of that best entry.
is_matchNPARRAY(A,) uint8 0/255 - whether the best score passes the threshold. Use it as labels for 'CV Draw Points' or to filter the query boxes.
any_matchBOOLEANTrue when at least one query row matched - branch on it with 'Basic data handling: IfElse'.