Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/transformers/models/detr/image_processing_detr_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions src/transformers/models/rt_detr/image_processing_rt_detr_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
get_image_type,
infer_channel_dimension_format,
make_list_of_images,
pil_torch_interpolation_mapping,
validate_annotations,
)
from ...utils import (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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,
Expand Down