Unverified Commit 59611a0f authored by amyeroberts's avatar amyeroberts Committed by GitHub
Browse files

Fix DETR tests after #21144 (#21365)

* Fix annotation check

* Fix annotation check

* Update type annotations
parent 7a2e1320
...@@ -77,6 +77,9 @@ if is_scipy_available(): ...@@ -77,6 +77,9 @@ if is_scipy_available():
import scipy.stats import scipy.stats
AnnotationType = Dict[str, Union[int, str, List[Dict]]]
class AnnotionFormat(ExplicitEnum): class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection" COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
...@@ -1071,7 +1074,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1071,7 +1074,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
annotations: Optional[Union[List[Dict], List[List[Dict]]]] = None, annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
return_segmentation_masks: bool = None, return_segmentation_masks: bool = None,
masks_path: Optional[Union[str, pathlib.Path]] = None, masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None, do_resize: Optional[bool] = None,
...@@ -1094,7 +1097,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1094,7 +1097,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
Args: Args:
images (`ImageInput`): images (`ImageInput`):
Image or batch of images to preprocess. Image or batch of images to preprocess.
annotations (`List[Dict]` or `List[List[Dict]]`, *optional*): annotations (`AnnotationType` or `List[AnnotationType]`, *optional*):
List of annotations associated with the image or batch of images. If annotionation is for object List of annotations associated with the image or batch of images. If annotionation is for object
detection, the annotations should be a dictionary with the following keys: detection, the annotations should be a dictionary with the following keys:
- "image_id" (`int`): The image id. - "image_id" (`int`): The image id.
...@@ -1173,7 +1176,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor): ...@@ -1173,7 +1176,7 @@ class ConditionalDetrImageProcessor(BaseImageProcessor):
raise ValueError("Image mean and std must be specified if do_normalize is True.") raise ValueError("Image mean and std must be specified if do_normalize is True.")
images = make_list_of_images(images) images = make_list_of_images(images)
if annotations is not None and isinstance(annotations[0], dict): if annotations is not None and isinstance(annotations, dict):
annotations = [annotations] annotations = [annotations]
if annotations is not None and len(images) != len(annotations): if annotations is not None and len(images) != len(annotations):
......
...@@ -76,6 +76,9 @@ if is_scipy_available(): ...@@ -76,6 +76,9 @@ if is_scipy_available():
import scipy.stats import scipy.stats
AnnotationType = Dict[str, Union[int, str, List[Dict]]]
class AnnotionFormat(ExplicitEnum): class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection" COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
...@@ -1069,7 +1072,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1069,7 +1072,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
annotations: Optional[Union[List[Dict], List[List[Dict]]]] = None, annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
return_segmentation_masks: bool = None, return_segmentation_masks: bool = None,
masks_path: Optional[Union[str, pathlib.Path]] = None, masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None, do_resize: Optional[bool] = None,
...@@ -1092,7 +1095,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1092,7 +1095,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
Args: Args:
images (`ImageInput`): images (`ImageInput`):
Image or batch of images to preprocess. Image or batch of images to preprocess.
annotations (`List[Dict]` or `List[List[Dict]]`, *optional*): annotations (`AnnotationType` or `List[AnnotationType]`, *optional*):
List of annotations associated with the image or batch of images. If annotionation is for object List of annotations associated with the image or batch of images. If annotionation is for object
detection, the annotations should be a dictionary with the following keys: detection, the annotations should be a dictionary with the following keys:
- "image_id" (`int`): The image id. - "image_id" (`int`): The image id.
...@@ -1171,7 +1174,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor): ...@@ -1171,7 +1174,7 @@ class DeformableDetrImageProcessor(BaseImageProcessor):
raise ValueError("Image mean and std must be specified if do_normalize is True.") raise ValueError("Image mean and std must be specified if do_normalize is True.")
images = make_list_of_images(images) images = make_list_of_images(images)
if annotations is not None and isinstance(annotations[0], dict): if annotations is not None and isinstance(annotations, dict):
annotations = [annotations] annotations = [annotations]
if annotations is not None and len(images) != len(annotations): if annotations is not None and len(images) != len(annotations):
......
...@@ -76,6 +76,9 @@ if is_scipy_available(): ...@@ -76,6 +76,9 @@ if is_scipy_available():
import scipy.stats import scipy.stats
AnnotationType = Dict[str, Union[int, str, List[Dict]]]
class AnnotionFormat(ExplicitEnum): class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection" COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
...@@ -1037,7 +1040,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1037,7 +1040,7 @@ class DetrImageProcessor(BaseImageProcessor):
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
annotations: Optional[Union[List[Dict], List[List[Dict]]]] = None, annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
return_segmentation_masks: bool = None, return_segmentation_masks: bool = None,
masks_path: Optional[Union[str, pathlib.Path]] = None, masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None, do_resize: Optional[bool] = None,
...@@ -1060,7 +1063,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1060,7 +1063,7 @@ class DetrImageProcessor(BaseImageProcessor):
Args: Args:
images (`ImageInput`): images (`ImageInput`):
Image or batch of images to preprocess. Image or batch of images to preprocess.
annotations (`List[Dict]` or `List[List[Dict]]`, *optional*): annotations (`AnnotationType` or `List[AnnotationType]`, *optional*):
List of annotations associated with the image or batch of images. If annotionation is for object List of annotations associated with the image or batch of images. If annotionation is for object
detection, the annotations should be a dictionary with the following keys: detection, the annotations should be a dictionary with the following keys:
- "image_id" (`int`): The image id. - "image_id" (`int`): The image id.
...@@ -1139,7 +1142,7 @@ class DetrImageProcessor(BaseImageProcessor): ...@@ -1139,7 +1142,7 @@ class DetrImageProcessor(BaseImageProcessor):
raise ValueError("Image mean and std must be specified if do_normalize is True.") raise ValueError("Image mean and std must be specified if do_normalize is True.")
images = make_list_of_images(images) images = make_list_of_images(images)
if annotations is not None and isinstance(annotations[0], dict): if annotations is not None and isinstance(annotations, dict):
annotations = [annotations] annotations = [annotations]
if annotations is not None and len(images) != len(annotations): if annotations is not None and len(images) != len(annotations):
......
...@@ -75,6 +75,9 @@ if is_scipy_available(): ...@@ -75,6 +75,9 @@ if is_scipy_available():
import scipy.stats import scipy.stats
AnnotationType = Dict[str, Union[int, str, List[Dict]]]
class AnnotionFormat(ExplicitEnum): class AnnotionFormat(ExplicitEnum):
COCO_DETECTION = "coco_detection" COCO_DETECTION = "coco_detection"
COCO_PANOPTIC = "coco_panoptic" COCO_PANOPTIC = "coco_panoptic"
...@@ -937,7 +940,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -937,7 +940,7 @@ class YolosImageProcessor(BaseImageProcessor):
def preprocess( def preprocess(
self, self,
images: ImageInput, images: ImageInput,
annotations: Optional[Union[List[Dict], List[List[Dict]]]] = None, annotations: Optional[Union[AnnotationType, List[AnnotationType]]] = None,
return_segmentation_masks: bool = None, return_segmentation_masks: bool = None,
masks_path: Optional[Union[str, pathlib.Path]] = None, masks_path: Optional[Union[str, pathlib.Path]] = None,
do_resize: Optional[bool] = None, do_resize: Optional[bool] = None,
...@@ -960,7 +963,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -960,7 +963,7 @@ class YolosImageProcessor(BaseImageProcessor):
Args: Args:
images (`ImageInput`): images (`ImageInput`):
Image or batch of images to preprocess. Image or batch of images to preprocess.
annotations (`List[Dict]` or `List[List[Dict]]`, *optional*): annotations (`AnnotationType` or `List[AnnotationType]`, *optional*):
List of annotations associated with the image or batch of images. If annotionation is for object List of annotations associated with the image or batch of images. If annotionation is for object
detection, the annotations should be a dictionary with the following keys: detection, the annotations should be a dictionary with the following keys:
- "image_id" (`int`): The image id. - "image_id" (`int`): The image id.
...@@ -1039,7 +1042,7 @@ class YolosImageProcessor(BaseImageProcessor): ...@@ -1039,7 +1042,7 @@ class YolosImageProcessor(BaseImageProcessor):
raise ValueError("Image mean and std must be specified if do_normalize is True.") raise ValueError("Image mean and std must be specified if do_normalize is True.")
images = make_list_of_images(images) images = make_list_of_images(images)
if annotations is not None and isinstance(annotations[0], dict): if annotations is not None and isinstance(annotations, dict):
annotations = [annotations] annotations = [annotations]
if annotations is not None and len(images) != len(annotations): if annotations is not None and len(images) != len(annotations):
......
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