From cf45323d56c1060662245fd6908d4517d79d6297 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 10:50:36 +0200 Subject: [PATCH 1/6] Documentation fix for torchvision.transforms.transforms.Resize() The current documentation implies that the computation of Resize() is performed twice in some cases related to the ``max_size`` parameter. This is not the case in the code. The new description fixes this issue. --- torchvision/transforms/transforms.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index 46af416e407..627d2d1b9f2 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -307,13 +307,11 @@ class Resize(torch.nn.Module): ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported. The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well. max_size (int, optional): The maximum allowed for the longer edge of - the resized image: if the longer edge of the image is greater - than ``max_size`` after being resized according to ``size``, then - the image is resized again so that the longer edge is equal to - ``max_size``. As a result, ``size`` might be overruled, i.e. the - smaller edge may be shorter than ``size``. This is only supported - if ``size`` is an int (or a sequence of length 1 in torchscript - mode). + the resized image. If the longer edge of the image is greater + than ``max_size`` after being resized according to ``size``, + ``size`` will be overruled. As a result, the smaller edge may be + shorter than ``size``. This is only supported if ``size`` is an int + (or a sequence of length 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. It only affects **tensors** with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on From 8e6e9af17bedee8469ce84e20327b0fc0f2887d7 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 10:51:28 +0200 Subject: [PATCH 2/6] Documentation fix for torchvision.transforms.functional.Resize() The current documentation implies that the computation of Resize() is performed twice in some cases related to the ``max_size`` parameter. This is not the case in the code. The new description fixes this issue. --- torchvision/transforms/functional.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 09c8bdbcfeb..81d5aebfce9 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -423,13 +423,11 @@ def resize( supported. The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well. max_size (int, optional): The maximum allowed for the longer edge of - the resized image: if the longer edge of the image is greater - than ``max_size`` after being resized according to ``size``, then - the image is resized again so that the longer edge is equal to - ``max_size``. As a result, ``size`` might be overruled, i.e. the - smaller edge may be shorter than ``size``. This is only supported - if ``size`` is an int (or a sequence of length 1 in torchscript - mode). + the resized image. If the longer edge of the image is greater + than ``max_size`` after being resized according to ``size``, + ``size`` will be overruled. As a result, the smaller edge may be + shorter than ``size``. This is only supported if ``size`` is an int + (or a sequence of length 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. It only affects **tensors** with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on From 9cb4fda727b89d552cc4e730626c5ae42e19efd1 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 13:51:19 +0200 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: Nicolas Hug --- torchvision/transforms/functional.py | 4 +++- torchvision/transforms/transforms.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 81d5aebfce9..983f7999122 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -425,7 +425,9 @@ def resize( max_size (int, optional): The maximum allowed for the longer edge of the resized image. If the longer edge of the image is greater than ``max_size`` after being resized according to ``size``, - ``size`` will be overruled. As a result, the smaller edge may be + ``size`` will be overruled so that the longer edge is equal to + ``max_size``. + As a result, the smaller edge may be shorter than ``size``. This is only supported if ``size`` is an int (or a sequence of length 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index 627d2d1b9f2..a6b27b710ee 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -309,7 +309,9 @@ class Resize(torch.nn.Module): max_size (int, optional): The maximum allowed for the longer edge of the resized image. If the longer edge of the image is greater than ``max_size`` after being resized according to ``size``, - ``size`` will be overruled. As a result, the smaller edge may be + ``size`` will be overruled so that the longer edge is equal to + ``max_size``. + As a result, the smaller edge may be shorter than ``size``. This is only supported if ``size`` is an int (or a sequence of length 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. From 6722d52753a146b5ffe9ae3fe90740febbd50261 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 13:55:03 +0200 Subject: [PATCH 4/6] Update _geometry.py --- torchvision/transforms/v2/_geometry.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/torchvision/transforms/v2/_geometry.py b/torchvision/transforms/v2/_geometry.py index 59791c30b9d..1a52816394d 100644 --- a/torchvision/transforms/v2/_geometry.py +++ b/torchvision/transforms/v2/_geometry.py @@ -97,13 +97,13 @@ class Resize(Transform): ``InterpolationMode.BILINEAR`` and ``InterpolationMode.BICUBIC`` are supported. The corresponding Pillow integer constants, e.g. ``PIL.Image.BILINEAR`` are accepted as well. max_size (int, optional): The maximum allowed for the longer edge of - the resized image: if the longer edge of the image is greater - than ``max_size`` after being resized according to ``size``, then - the image is resized again so that the longer edge is equal to - ``max_size``. As a result, ``size`` might be overruled, i.e. the - smaller edge may be shorter than ``size``. This is only supported - if ``size`` is an int (or a sequence of length 1 in torchscript - mode). + the resized image. If the longer edge of the image is greater + than ``max_size`` after being resized according to ``size``, + ``size`` will be overruled so that the longer edge is equal to + ``max_size``. + As a result, the smaller edge may be shorter than ``size``. This + is only supported if ``size`` is an int (or a sequence of length + 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. It only affects **tensors** with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on From 87aff910e9edf5a941d76117583222cbb63bfdcf Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 13:55:51 +0200 Subject: [PATCH 5/6] Update functional.py --- torchvision/transforms/functional.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 983f7999122..1676aa2b744 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -427,9 +427,9 @@ def resize( than ``max_size`` after being resized according to ``size``, ``size`` will be overruled so that the longer edge is equal to ``max_size``. - As a result, the smaller edge may be - shorter than ``size``. This is only supported if ``size`` is an int - (or a sequence of length 1 in torchscript mode). + As a result, the smaller edge may be shorter than ``size``. This + is only supported if ``size`` is an int (or a sequence of length + 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. It only affects **tensors** with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on From 7c6c1bc766ab944437fae1154be913b43439cb08 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Tue, 25 Apr 2023 13:56:16 +0200 Subject: [PATCH 6/6] Update transforms.py --- torchvision/transforms/transforms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index a6b27b710ee..1edf772bc8f 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -311,9 +311,9 @@ class Resize(torch.nn.Module): than ``max_size`` after being resized according to ``size``, ``size`` will be overruled so that the longer edge is equal to ``max_size``. - As a result, the smaller edge may be - shorter than ``size``. This is only supported if ``size`` is an int - (or a sequence of length 1 in torchscript mode). + As a result, the smaller edge may be shorter than ``size``. This + is only supported if ``size`` is an int (or a sequence of length + 1 in torchscript mode). antialias (bool, optional): Whether to apply antialiasing. It only affects **tensors** with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on