Merge pull request #1698 from souhhmm/fix/xyxy-shape-crash

fix: is_empty check for filtering
This commit is contained in:
LinasKo 2024-12-04 12:15:31 +02:00 committed by GitHub
commit ae8e6b2976
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -1201,6 +1201,8 @@ class Detections:
"""
if isinstance(index, str):
return self.data.get(index)
if self.is_empty():
return Detections.empty()
if isinstance(index, int):
index = [index]
return Detections(

View File

@ -223,6 +223,12 @@ TEST_DET_DIFFERENT_METADATA = Detections(
None,
pytest.raises(IndexError),
),
(
Detections.empty(),
np.isin(Detections.empty()["class_name"], ["cat", "dog"]),
Detections.empty(),
DoesNotRaise(),
), # Filter an empty detections by specific class names
],
)
def test_getitem(