Clone, not copy, the RGB slice of a tensor in tensor_convert_rgb

tensor_convert_rgb is typed for NHWC torch tensors, but with prefer_copy it called image.copy(), which torch.Tensor does not have, so every RGBA image raised AttributeError. Use clone() for a tensor and keep copy() for a numpy array.

Fixes #1194, fixes #1178.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrew
2026-10-11 10:40:42 -05:00
co-authored by Claude Opus 5.5
parent 429d0159ad
commit 64c6c8d71d
+2 -1
View File
@@ -54,7 +54,8 @@ def tensor_convert_rgb(image, prefer_copy=True):
if n_channel == 4:
image = image[..., :3]
if prefer_copy:
image = image.copy()
# torch tensors have clone(), not copy(); numpy arrays have copy().
image = image.clone() if torch.is_tensor(image) else image.copy()
return image
if n_channel == 1: