Closed
Description
Search before asking
- I have searched the Supervision issues and found no similar bug report.
Bug
I have a dataset (downloaded from roboflow) in COCO format. I tried to load using
dataset = sv.DetectionDataset.from_coco("dataset", "dataset/_annotations.coco.json")
but this throws an error:
/home/ks/projekty/bugs/venv/bin/python /home/ks/projekty/bugs/supervision_bug/test.py
Traceback (most recent call last):
File "/home/ks/projekty/bugs/supervision_bug/test.py", line 3, in <module>
dataset = sv.DetectionDataset.from_coco("dataset", "dataset/_annotations.coco.json")
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/core.py", line 399, in from_coco
classes, images, annotations = load_coco_annotations(
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/formats/coco.py", line 168, in load_coco_annotations
annotation = map_detections_class_id(
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/supervision/dataset/utils.py", line 86, in map_detections_class_id
detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2372, in __call__
return self._call_as_normal(*args, **kwargs)
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2365, in _call_as_normal
return self._vectorize_call(func=func, args=vargs)
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2450, in _vectorize_call
ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
File "/home/ks/projekty/bugs/venv/lib/python3.10/site-packages/numpy/lib/function_base.py", line 2406, in _get_ufunc_and_otypes
raise ValueError('cannot call `vectorize` on size 0 inputs '
ValueError: cannot call `vectorize` on size 0 inputs unless `otypes` is set
Process finished with exit code 1
has
I investigated what's going wrong and it turns out, that one of the images had no annotations.
This problem not occurs when datasets is in YOLO format and use from_yolo
method.
I check out that changing lines from 86 to 88 in supervision.dataset.utils
from
detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
detections_copy.class_id
)
to
detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
detections_copy.class_id, otypes='int'
)
will help with this issue.
Environment
- OS
- python 3.10.12
- supervision from commit
abbde887dc380b0abd8065c21ebe10cf20efb2a2
- other packages:
contourpy 1.1.0
cycler 0.11.0
fonttools 4.40.0
kiwisolver 1.4.4
matplotlib 3.7.2
numpy 1.25.1
opencv-python 4.8.0.74
packaging 23.1
Pillow 10.0.0
pip 22.3.1
pyparsing 3.0.9
python-dateutil 2.8.2
PyYAML 6.0
setuptools 65.5.1
six 1.16.0
supervision 0.11.1
wheel 0.38.4
Minimal Reproducible Example
I made an example with a toy dataset to reproduce bug. Just run test.py
. There are no annotations for image 1.jpg
Additional
No response
Are you willing to submit a PR?
- Yes I'd like to help by submitting a PR!
Metadata
Metadata
Assignees
Type
Projects
Status
Done