|
14 | 14 | pil_to_tensor,
|
15 | 15 | to_pil_image,
|
16 | 16 | )
|
17 |
| -from torchvision.transforms.functional_tensor import ( |
18 |
| - _cast_squeeze_in, |
19 |
| - _cast_squeeze_out, |
20 |
| - _parse_pad_padding, |
21 |
| - interpolate, |
22 |
| -) |
| 17 | +from torchvision.transforms.functional_tensor import _parse_pad_padding |
23 | 18 |
|
24 | 19 | from ._meta import (
|
25 | 20 | convert_format_bounding_box,
|
@@ -130,32 +125,12 @@ def resize_image_tensor(
|
130 | 125 | if image.numel() > 0:
|
131 | 126 | image = image.view(-1, num_channels, old_height, old_width)
|
132 | 127 |
|
133 |
| - # This is a perf hack to avoid slow channels_last upsample code path |
134 |
| - # Related issue: https://github.com/pytorch/pytorch/issues/83840 |
135 |
| - # We are transforming (N, 1, H, W) into (N, 2, H, W) to force to take channels_first path |
136 |
| - if image.shape[1] == 1 and interpolation == InterpolationMode.NEAREST: |
137 |
| - # Below code is copied from _FT.resize |
138 |
| - # This is due to the fact that we need to apply the hack on casted image and not before |
139 |
| - # Otherwise, image will be copied while cast to float and interpolate will work on twice more data |
140 |
| - image, need_cast, need_squeeze, out_dtype = _cast_squeeze_in(image, [torch.float32, torch.float64]) |
141 |
| - |
142 |
| - shape = (image.shape[0], 2, image.shape[2], image.shape[3]) |
143 |
| - image = image.expand(shape) |
144 |
| - |
145 |
| - image = interpolate( |
146 |
| - image, size=[new_height, new_width], mode=interpolation.value, align_corners=None, antialias=False |
147 |
| - ) |
148 |
| - |
149 |
| - image = image[:, 0, ...] |
150 |
| - image = _cast_squeeze_out(image, need_cast=need_cast, need_squeeze=need_squeeze, out_dtype=out_dtype) |
151 |
| - |
152 |
| - else: |
153 |
| - image = _FT.resize( |
154 |
| - image, |
155 |
| - size=[new_height, new_width], |
156 |
| - interpolation=interpolation.value, |
157 |
| - antialias=antialias, |
158 |
| - ) |
| 128 | + image = _FT.resize( |
| 129 | + image, |
| 130 | + size=[new_height, new_width], |
| 131 | + interpolation=interpolation.value, |
| 132 | + antialias=antialias, |
| 133 | + ) |
159 | 134 |
|
160 | 135 | return image.view(extra_dims + (num_channels, new_height, new_width))
|
161 | 136 |
|
|
0 commit comments