supervision
supervision copied to clipboard
[Bug]: CSVSink truncates and mangles array-valued data (embeddings, OBB corners); JSONSink does not
Search before asking
- [x] I have searched the issues and discussions and found no similar bug report.
Bug
What's the bug? CSVSink passes NumPy arrays in detections.data to csv.writer, which calls str() on them. Large arrays are written as numpy's summarised repr, so the values are lost, and smaller ones are written in a form that cannot be parsed.
Expected behavior: A parseable, lossless cell, with the same values JSONSink writes for the same input.
Actual behavior:
- a 1536-d float32 embedding: '[0.8506242 0.63696164 0.5111365 ... 0.08969319 0.6120899 0.91254586' (6 of 1536 values recoverable; json.loads fails)
- OBB corners (shape (4, 2)): '[[ 0.5 0.25]\n [10. 0. ]\n ...' with embedded newlines
- a small int array: '[1 2 3]' (json.loads fails) JSONSink writes proper (nested) lists for the same data.
Error/Traceback (if any):
# No exception from CSVSink; json.loads on the cell raises ValueError (e.g. "Expecting value").
Environment
- Supervision: 0.31.0.dev0 (develop @ 69cb843)
- Python: 3.11
- OS: macOS 15 (arm64)
Minimal Reproducible Example
import csv, json, os, tempfile
import numpy as np
import supervision as sv
emb = np.random.default_rng(0).random((1, 1536), dtype=np.float32)
corners = np.array([[[0.5, 0.25], [10.0, 0.0], [10.0, 5.0], [0.0, 5.0]]])
det = sv.Detections(xyxy=np.array([[0.0, 0.0, 10.0, 5.0]]), data={"embedding": emb, "xyxyxyxy": corners})
with tempfile.TemporaryDirectory() as d:
p = os.path.join(d, "o.csv")
with sv.CSVSink(p) as s:
s.append(det)
row = next(csv.DictReader(open(p, newline="")))
for k in ("embedding", "xyxyxyxy"):
print(k, repr(row[k][:60]))
try:
json.loads(row[k]); print(" parseable")
except ValueError as e:
print(" json.loads failed:", e)
Are you willing to submit a PR?
- [x] Yes I'd like to help by submitting a PR!