diff --git a/src/transformers/models/detr/image_processing_detr_fast.py b/src/transformers/models/detr/image_processing_detr_fast.py index eadde59e55e4..b414b4224e68 100644 --- a/src/transformers/models/detr/image_processing_detr_fast.py +++ b/src/transformers/models/detr/image_processing_detr_fast.py @@ -347,7 +347,7 @@ def __init__( format: Union[str, AnnotationFormat] = AnnotationFormat.COCO_DETECTION, do_resize: bool = True, size: Dict[str, int] = None, - resample: [Union[PILImageResampling, F.InterpolationMode]] = PILImageResampling.BILINEAR, + resample: Union[PILImageResampling, "F.InterpolationMode"] = PILImageResampling.BILINEAR, do_rescale: bool = True, rescale_factor: Union[int, float] = 1 / 255, do_normalize: bool = True, @@ -462,7 +462,7 @@ def resize( self, image: torch.Tensor, size: SizeDict, - interpolation: F.InterpolationMode = F.InterpolationMode.BILINEAR, + interpolation: "F.InterpolationMode" = None, **kwargs, ) -> torch.Tensor: """ @@ -485,6 +485,7 @@ def resize( interpolation (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`): Resampling filter to use if resizing the image. """ + interpolation = interpolation if interpolation is not None else F.InterpolationMode.BILINEAR if size.shortest_edge and size.longest_edge: # Resize the image so that the shortest edge or the longest edge is of the given size # while maintaining the aspect ratio of the original image. @@ -517,7 +518,7 @@ def resize_annotation( orig_size: Tuple[int, int], target_size: Tuple[int, int], threshold: float = 0.5, - interpolation: F.InterpolationMode = F.InterpolationMode.NEAREST, + interpolation: "F.InterpolationMode" = None, ): """ Resizes an annotation to a target size. @@ -534,6 +535,7 @@ def resize_annotation( resample (`InterpolationMode`, defaults to `InterpolationMode.NEAREST`): The resampling filter to use when resizing the masks. """ + interpolation = interpolation if interpolation is not None else F.InterpolationMode.NEAREST ratio_height, ratio_width = [target / orig for target, orig in zip(target_size, orig_size)] new_annotation = {} @@ -680,7 +682,7 @@ def preprocess( masks_path: Optional[Union[str, pathlib.Path]] = None, do_resize: Optional[bool] = None, size: Optional[Dict[str, int]] = None, - resample: Optional[Union[PILImageResampling, F.InterpolationMode]] = None, + resample: Optional[Union[PILImageResampling, "F.InterpolationMode"]] = None, do_rescale: Optional[bool] = None, rescale_factor: Optional[Union[int, float]] = None, do_normalize: Optional[bool] = None, diff --git a/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py b/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py index 9f63b5b7ced4..0470352d38f4 100644 --- a/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py +++ b/src/transformers/models/rt_detr/image_processing_rt_detr_fast.py @@ -43,7 +43,6 @@ get_image_type, infer_channel_dimension_format, make_list_of_images, - pil_torch_interpolation_mapping, validate_annotations, ) from ...utils import ( @@ -197,7 +196,7 @@ def __init__( format: Union[str, AnnotationFormat] = AnnotationFormat.COCO_DETECTION, do_resize: bool = True, size: Dict[str, int] = None, - resample: Union[PILImageResampling, F.InterpolationMode] = PILImageResampling.BILINEAR, + resample: Union[PILImageResampling, "F.InterpolationMode"] = PILImageResampling.BILINEAR, do_rescale: bool = True, rescale_factor: Union[int, float] = 1 / 255, do_normalize: bool = False, @@ -256,7 +255,7 @@ def resize( self, image: torch.Tensor, size: SizeDict, - interpolation: F.InterpolationMode = F.InterpolationMode.BILINEAR, + interpolation: "F.InterpolationMode" = None, **kwargs, ) -> torch.Tensor: """ @@ -279,6 +278,7 @@ def resize( interpolation (`InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`): Resampling filter to use if resizing the image. """ + interpolation = interpolation if interpolation is not None else F.InterpolationMode.BILINEAR if size.shortest_edge and size.longest_edge: # Resize the image so that the shortest edge or the longest edge is of the given size # while maintaining the aspect ratio of the original image. @@ -312,7 +312,7 @@ def resize_annotation( orig_size: Tuple[int, int], target_size: Tuple[int, int], threshold: float = 0.5, - interpolation: F.InterpolationMode = F.InterpolationMode.NEAREST, + interpolation: "F.InterpolationMode" = None, ): """ Resizes an annotation to a target size. @@ -329,6 +329,7 @@ def resize_annotation( resample (`InterpolationMode`, defaults to `InterpolationMode.NEAREST`): The resampling filter to use when resizing the masks. """ + interpolation = interpolation if interpolation is not None else F.InterpolationMode.NEAREST ratio_height, ratio_width = [target / orig for target, orig in zip(target_size, orig_size)] new_annotation = {} @@ -480,7 +481,7 @@ def preprocess( masks_path: Optional[Union[str, pathlib.Path]] = None, do_resize: Optional[bool] = None, size: Optional[Dict[str, int]] = None, - resample: Optional[Union[PILImageResampling, F.InterpolationMode]] = None, + resample: Optional[Union[PILImageResampling, "F.InterpolationMode"]] = None, do_rescale: Optional[bool] = None, rescale_factor: Optional[Union[int, float]] = None, do_normalize: Optional[bool] = None,