Skip to content

Commit 95b594e

Browse files
authored
fix antialias handling on resize and resized_crop (#6913)
1 parent 9e6dab7 commit 95b594e

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

torchvision/prototype/features/_bounding_box.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def resize( # type: ignore[override]
7878
size: List[int],
7979
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
8080
max_size: Optional[int] = None,
81-
antialias: bool = False,
81+
antialias: Optional[bool] = None,
8282
) -> BoundingBox:
8383
output, spatial_size = self._F.resize_bounding_box(
8484
self.as_subclass(torch.Tensor), spatial_size=self.spatial_size, size=size, max_size=max_size
@@ -105,7 +105,7 @@ def resized_crop(
105105
width: int,
106106
size: List[int],
107107
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
108-
antialias: bool = False,
108+
antialias: Optional[bool] = None,
109109
) -> BoundingBox:
110110
output, spatial_size = self._F.resized_crop_bounding_box(
111111
self.as_subclass(torch.Tensor), self.format, top, left, height, width, size=size

torchvision/prototype/features/_feature.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def resize( # type: ignore[override]
164164
size: List[int],
165165
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
166166
max_size: Optional[int] = None,
167-
antialias: bool = False,
167+
antialias: Optional[bool] = None,
168168
) -> _Feature:
169169
return self
170170

@@ -182,7 +182,7 @@ def resized_crop(
182182
width: int,
183183
size: List[int],
184184
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
185-
antialias: bool = False,
185+
antialias: Optional[bool] = None,
186186
) -> _Feature:
187187
return self
188188

torchvision/prototype/features/_image.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def resize( # type: ignore[override]
123123
size: List[int],
124124
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
125125
max_size: Optional[int] = None,
126-
antialias: bool = False,
126+
antialias: Optional[bool] = None,
127127
) -> Image:
128128
output = self._F.resize_image_tensor(
129129
self.as_subclass(torch.Tensor), size, interpolation=interpolation, max_size=max_size, antialias=antialias
@@ -146,7 +146,7 @@ def resized_crop(
146146
width: int,
147147
size: List[int],
148148
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
149-
antialias: bool = False,
149+
antialias: Optional[bool] = None,
150150
) -> Image:
151151
output = self._F.resized_crop_image_tensor(
152152
self.as_subclass(torch.Tensor),

torchvision/prototype/features/_mask.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def resize( # type: ignore[override]
4949
size: List[int],
5050
interpolation: InterpolationMode = InterpolationMode.NEAREST,
5151
max_size: Optional[int] = None,
52-
antialias: bool = False,
52+
antialias: Optional[bool] = None,
5353
) -> Mask:
5454
output = self._F.resize_mask(self.as_subclass(torch.Tensor), size, max_size=max_size)
5555
return Mask.wrap_like(self, output)
@@ -70,7 +70,7 @@ def resized_crop(
7070
width: int,
7171
size: List[int],
7272
interpolation: InterpolationMode = InterpolationMode.NEAREST,
73-
antialias: bool = False,
73+
antialias: Optional[bool] = None,
7474
) -> Mask:
7575
output = self._F.resized_crop_mask(self.as_subclass(torch.Tensor), top, left, height, width, size=size)
7676
return Mask.wrap_like(self, output)

torchvision/prototype/features/_video.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def resize( # type: ignore[override]
7979
size: List[int],
8080
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
8181
max_size: Optional[int] = None,
82-
antialias: bool = False,
82+
antialias: Optional[bool] = None,
8383
) -> Video:
8484
output = self._F.resize_video(
8585
self.as_subclass(torch.Tensor),
@@ -106,7 +106,7 @@ def resized_crop(
106106
width: int,
107107
size: List[int],
108108
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
109-
antialias: bool = False,
109+
antialias: Optional[bool] = None,
110110
) -> Video:
111111
output = self._F.resized_crop_video(
112112
self.as_subclass(torch.Tensor),

torchvision/prototype/transforms/functional/_geometry.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ def resize_image_tensor(
115115
size: List[int],
116116
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
117117
max_size: Optional[int] = None,
118-
antialias: bool = False,
118+
antialias: Optional[bool] = None,
119119
) -> torch.Tensor:
120+
antialias = False if antialias is None else antialias
120121
align_corners: Optional[bool] = None
121122
if interpolation == InterpolationMode.BILINEAR or interpolation == InterpolationMode.BICUBIC:
122123
align_corners = False
@@ -196,7 +197,7 @@ def resize_video(
196197
size: List[int],
197198
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
198199
max_size: Optional[int] = None,
199-
antialias: bool = False,
200+
antialias: Optional[bool] = None,
200201
) -> torch.Tensor:
201202
return resize_image_tensor(video, size=size, interpolation=interpolation, max_size=max_size, antialias=antialias)
202203

@@ -209,10 +210,8 @@ def resize(
209210
antialias: Optional[bool] = None,
210211
) -> features.InputTypeJIT:
211212
if isinstance(inpt, torch.Tensor) and (torch.jit.is_scripting() or not isinstance(inpt, features._Feature)):
212-
antialias = False if antialias is None else antialias
213213
return resize_image_tensor(inpt, size, interpolation=interpolation, max_size=max_size, antialias=antialias)
214214
elif isinstance(inpt, features._Feature):
215-
antialias = False if antialias is None else antialias
216215
return inpt.resize(size, interpolation=interpolation, max_size=max_size, antialias=antialias)
217216
else:
218217
if antialias is not None and not antialias:
@@ -1396,7 +1395,7 @@ def resized_crop_image_tensor(
13961395
width: int,
13971396
size: List[int],
13981397
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
1399-
antialias: bool = False,
1398+
antialias: Optional[bool] = None,
14001399
) -> torch.Tensor:
14011400
image = crop_image_tensor(image, top, left, height, width)
14021401
return resize_image_tensor(image, size, interpolation=interpolation, antialias=antialias)
@@ -1449,7 +1448,7 @@ def resized_crop_video(
14491448
width: int,
14501449
size: List[int],
14511450
interpolation: InterpolationMode = InterpolationMode.BILINEAR,
1452-
antialias: bool = False,
1451+
antialias: Optional[bool] = None,
14531452
) -> torch.Tensor:
14541453
return resized_crop_image_tensor(
14551454
video, top, left, height, width, antialias=antialias, size=size, interpolation=interpolation
@@ -1467,12 +1466,10 @@ def resized_crop(
14671466
antialias: Optional[bool] = None,
14681467
) -> features.InputTypeJIT:
14691468
if isinstance(inpt, torch.Tensor) and (torch.jit.is_scripting() or not isinstance(inpt, features._Feature)):
1470-
antialias = False if antialias is None else antialias
14711469
return resized_crop_image_tensor(
14721470
inpt, top, left, height, width, antialias=antialias, size=size, interpolation=interpolation
14731471
)
14741472
elif isinstance(inpt, features._Feature):
1475-
antialias = False if antialias is None else antialias
14761473
return inpt.resized_crop(top, left, height, width, antialias=antialias, size=size, interpolation=interpolation)
14771474
else:
14781475
return resized_crop_image_pil(inpt, top, left, height, width, size=size, interpolation=interpolation)

0 commit comments

Comments
 (0)