Skip to content

fix antialias handling on resize and resized_crop #6913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2022
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
4 changes: 2 additions & 2 deletions torchvision/prototype/features/_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def resize( # type: ignore[override]
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> BoundingBox:
output, spatial_size = self._F.resize_bounding_box(
self.as_subclass(torch.Tensor), spatial_size=self.spatial_size, size=size, max_size=max_size
Expand All @@ -105,7 +105,7 @@ def resized_crop(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> BoundingBox:
output, spatial_size = self._F.resized_crop_bounding_box(
self.as_subclass(torch.Tensor), self.format, top, left, height, width, size=size
Expand Down
4 changes: 2 additions & 2 deletions torchvision/prototype/features/_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def resize( # type: ignore[override]
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> _Feature:
return self

Expand All @@ -182,7 +182,7 @@ def resized_crop(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> _Feature:
return self

Expand Down
4 changes: 2 additions & 2 deletions torchvision/prototype/features/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def resize( # type: ignore[override]
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Image:
output = self._F.resize_image_tensor(
self.as_subclass(torch.Tensor), size, interpolation=interpolation, max_size=max_size, antialias=antialias
Expand All @@ -146,7 +146,7 @@ def resized_crop(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Image:
output = self._F.resized_crop_image_tensor(
self.as_subclass(torch.Tensor),
Expand Down
4 changes: 2 additions & 2 deletions torchvision/prototype/features/_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def resize( # type: ignore[override]
size: List[int],
interpolation: InterpolationMode = InterpolationMode.NEAREST,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Mask:
output = self._F.resize_mask(self.as_subclass(torch.Tensor), size, max_size=max_size)
return Mask.wrap_like(self, output)
Expand All @@ -70,7 +70,7 @@ def resized_crop(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.NEAREST,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Mask:
output = self._F.resized_crop_mask(self.as_subclass(torch.Tensor), top, left, height, width, size=size)
return Mask.wrap_like(self, output)
Expand Down
4 changes: 2 additions & 2 deletions torchvision/prototype/features/_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def resize( # type: ignore[override]
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Video:
output = self._F.resize_video(
self.as_subclass(torch.Tensor),
Expand All @@ -106,7 +106,7 @@ def resized_crop(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> Video:
output = self._F.resized_crop_video(
self.as_subclass(torch.Tensor),
Expand Down
13 changes: 5 additions & 8 deletions torchvision/prototype/transforms/functional/_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def resize_image_tensor(
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> torch.Tensor:
antialias = False if antialias is None else antialias
align_corners: Optional[bool] = None
if interpolation == InterpolationMode.BILINEAR or interpolation == InterpolationMode.BICUBIC:
align_corners = False
Expand Down Expand Up @@ -196,7 +197,7 @@ def resize_video(
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
max_size: Optional[int] = None,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> torch.Tensor:
return resize_image_tensor(video, size=size, interpolation=interpolation, max_size=max_size, antialias=antialias)

Expand All @@ -209,10 +210,8 @@ def resize(
antialias: Optional[bool] = None,
) -> features.InputTypeJIT:
if isinstance(inpt, torch.Tensor) and (torch.jit.is_scripting() or not isinstance(inpt, features._Feature)):
antialias = False if antialias is None else antialias
return resize_image_tensor(inpt, size, interpolation=interpolation, max_size=max_size, antialias=antialias)
elif isinstance(inpt, features._Feature):
antialias = False if antialias is None else antialias
return inpt.resize(size, interpolation=interpolation, max_size=max_size, antialias=antialias)
else:
if antialias is not None and not antialias:
Expand Down Expand Up @@ -1396,7 +1395,7 @@ def resized_crop_image_tensor(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> torch.Tensor:
image = crop_image_tensor(image, top, left, height, width)
return resize_image_tensor(image, size, interpolation=interpolation, antialias=antialias)
Expand Down Expand Up @@ -1449,7 +1448,7 @@ def resized_crop_video(
width: int,
size: List[int],
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
antialias: bool = False,
antialias: Optional[bool] = None,
) -> torch.Tensor:
return resized_crop_image_tensor(
video, top, left, height, width, antialias=antialias, size=size, interpolation=interpolation
Expand All @@ -1467,12 +1466,10 @@ def resized_crop(
antialias: Optional[bool] = None,
) -> features.InputTypeJIT:
if isinstance(inpt, torch.Tensor) and (torch.jit.is_scripting() or not isinstance(inpt, features._Feature)):
antialias = False if antialias is None else antialias
return resized_crop_image_tensor(
inpt, top, left, height, width, antialias=antialias, size=size, interpolation=interpolation
)
elif isinstance(inpt, features._Feature):
antialias = False if antialias is None else antialias
return inpt.resized_crop(top, left, height, width, antialias=antialias, size=size, interpolation=interpolation)
else:
return resized_crop_image_pil(inpt, top, left, height, width, size=size, interpolation=interpolation)
Expand Down