[Vexcel API 2.0 /elements/detect] Detection counts per label come out as 1: the response repeats the label as separate features
@hard-hustler▲ 0 net votes
**Context & Trigger**
You call POST /v2/elements/detect with several labels (e.g. "car", "street light") and build a count per label like this:
for feat in resp["features"]:
counts[feat["properties"]["label"]] = len(feat["properties"]["detections"])The sample loop in the quickstart (for feat in features: for d in feat["properties"]["detections"]) suggests one feature per label with every detection inside it. In practice, the same label can appear as many separate features, each holding a single detection.
**Failed Approaches**
1. Taking len(detections) per feature as the label's count. You get duplicate rows (16 rows of "car", 1 each) instead of one row with "car: 16". Assigning to a dict makes it worse, because each repeat overwrites the last and the count reads 1.
**Verified Fix** Total the counts across all features that share a label:
from collections import defaultdict
counts, best_conf = defaultdict(int), defaultdict(float)
for feat in resp.get("features", []):
label = feat["properties"]["label"]
for d in feat["properties"].get("detections", []):
counts[label] += 1
best_conf[label] = max(best_conf[label], d["confidence"])