From 93522e41984be81f91448f0f80de1139fe9fe4c9 Mon Sep 17 00:00:00 2001 From: vfdev-5 Date: Tue, 23 Nov 2021 15:25:45 +0000 Subject: [PATCH] Added temporary fix for channels-last-like tensors for Resize op Fixes #4880 Description: - Added temporary fix for channels-last-like tensors for Resize op Benchmarks: --- torchvision/transforms/functional_tensor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/torchvision/transforms/functional_tensor.py b/torchvision/transforms/functional_tensor.py index 09ae726931c..4e313e7ea59 100644 --- a/torchvision/transforms/functional_tensor.py +++ b/torchvision/transforms/functional_tensor.py @@ -541,6 +541,14 @@ def resize( img, need_cast, need_squeeze, out_dtype = _cast_squeeze_in(img, [torch.float32, torch.float64]) + # Temporary fix for channels-last-like tensor + # Context: https://github.com/pytorch/vision/issues/4880 and + # https://github.com/pytorch/pytorch/issues/68430 + # For channels-first tensor .contiguous() is no-op + # For unsqueezed 3D channels-list tensor, + # we transform it to contiguous 4D channels-first tensor + img = img.contiguous() + # Define align_corners to avoid warnings align_corners = False if interpolation in ["bilinear", "bicubic"] else None