Skip to content

Commit 1b9c65b

Browse files
authored
🛠️ Merge pull request #192 from hardikdava/fix/coco_empty_fix
🛠️ Fixing empty detection coco dataset
2 parents abbde88 + 3a8c4d6 commit 1b9c65b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

supervision/dataset/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ def map_detections_class_id(
8383
)
8484

8585
detections_copy = copy.deepcopy(detections)
86-
detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
87-
detections_copy.class_id
88-
)
86+
87+
if len(detections) > 0:
88+
detections_copy.class_id = np.vectorize(source_to_target_mapping.get)(
89+
detections_copy.class_id
90+
)
8991

9092
return detections_copy
9193

test/dataset/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ def test_build_class_index_mapping(
204204
mock_detections(xyxy=[[0, 0, 10, 10]], class_id=[1]),
205205
DoesNotRaise()
206206
), # single mapping
207+
(
208+
{0: 1, 1: 2},
209+
Detections.empty(),
210+
Detections.empty(),
211+
DoesNotRaise()
212+
), # empty detections
207213
(
208214
{0: 1, 1: 2},
209215
mock_detections(xyxy=[[0, 0, 10, 10]], class_id=[0]),

0 commit comments

Comments
 (0)