Skip to content

Commit 2286120

Browse files
committed
Restore _split_alpha.
1 parent 090a0d7 commit 2286120

File tree

1 file changed

+7
-3
lines changed
  • torchvision/prototype/transforms/functional

1 file changed

+7
-3
lines changed

torchvision/prototype/transforms/functional/_meta.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,12 @@ def clamp_bounding_box(
183183
return convert_format_bounding_box(xyxy_boxes, BoundingBoxFormat.XYXY, format)
184184

185185

186+
def _split_alpha(image: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
187+
return torch.tensor_split(image, indices=(-1,), dim=-3)
188+
189+
186190
def _strip_alpha(image: torch.Tensor) -> torch.Tensor:
187-
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3)
191+
image, alpha = _split_alpha(image)
188192
if not torch.all(alpha == _FT._max_value(alpha.dtype)):
189193
raise RuntimeError(
190194
"Stripping the alpha channel if it contains values other than the max value is not supported."
@@ -233,7 +237,7 @@ def convert_color_space_image_tensor(
233237
elif old_color_space == ColorSpace.GRAY_ALPHA and new_color_space == ColorSpace.RGB:
234238
return _gray_to_rgb(_strip_alpha(image))
235239
elif old_color_space == ColorSpace.GRAY_ALPHA and new_color_space == ColorSpace.RGB_ALPHA:
236-
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3)
240+
image, alpha = _split_alpha(image)
237241
return _add_alpha(_gray_to_rgb(image), alpha)
238242
elif old_color_space == ColorSpace.RGB and new_color_space == ColorSpace.GRAY:
239243
return _rgb_to_gray(image)
@@ -244,7 +248,7 @@ def convert_color_space_image_tensor(
244248
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.GRAY:
245249
return _rgb_to_gray(_strip_alpha(image))
246250
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.GRAY_ALPHA:
247-
image, alpha = torch.tensor_split(image, indices=(-1,), dim=-3)
251+
image, alpha = _split_alpha(image)
248252
return _add_alpha(_rgb_to_gray(image), alpha)
249253
elif old_color_space == ColorSpace.RGB_ALPHA and new_color_space == ColorSpace.RGB:
250254
return _strip_alpha(image)

0 commit comments

Comments
 (0)