Unverified Commit 8afd5476 authored by Syed Raza's avatar Syed Raza Committed by GitHub
Browse files

Added Type Check for cocodetection dataset (#8227)


Co-authored-by: default avatarRazaProdigy <rizaidi@hotmail.com>
Co-authored-by: default avatarNicolas Hug <nh.nicolas.hug@gmail.com>
parent 6d64cb3a
...@@ -827,6 +827,11 @@ class CocoDetectionTestCase(datasets_utils.ImageDatasetTestCase): ...@@ -827,6 +827,11 @@ class CocoDetectionTestCase(datasets_utils.ImageDatasetTestCase):
with self.create_dataset(transform=v2.Resize(size=expected_size)) as (dataset, _): with self.create_dataset(transform=v2.Resize(size=expected_size)) as (dataset, _):
datasets_utils.check_transforms_v2_wrapper_spawn(dataset, expected_size=expected_size) datasets_utils.check_transforms_v2_wrapper_spawn(dataset, expected_size=expected_size)
def test_slice_error(self):
with self.create_dataset() as (dataset, _):
with pytest.raises(ValueError, match="Index must be of type integer"):
dataset[:2]
class CocoCaptionsTestCase(CocoDetectionTestCase): class CocoCaptionsTestCase(CocoDetectionTestCase):
DATASET_CLASS = datasets.CocoCaptions DATASET_CLASS = datasets.CocoCaptions
......
...@@ -44,6 +44,10 @@ class CocoDetection(VisionDataset): ...@@ -44,6 +44,10 @@ class CocoDetection(VisionDataset):
return self.coco.loadAnns(self.coco.getAnnIds(id)) return self.coco.loadAnns(self.coco.getAnnIds(id))
def __getitem__(self, index: int) -> Tuple[Any, Any]: def __getitem__(self, index: int) -> Tuple[Any, Any]:
if not isinstance(index, int):
raise ValueError(f"Index must be of type integer, got {type(index)} instead.")
id = self.ids[index] id = self.ids[index]
image = self._load_image(id) image = self._load_image(id)
target = self._load_target(id) target = self._load_target(id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment