From 10edfb6f21921a6ba0da1274a774bc5d2bbd3a30 Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Thu, 17 Dec 2020 22:10:02 +0800 Subject: [PATCH] Update en docs of to_tensor (#29718) * update to_tensor en docs --- python/paddle/vision/transforms/functional.py | 4 ++-- .../paddle/vision/transforms/functional_cv2.py | 2 +- .../paddle/vision/transforms/functional_pil.py | 2 +- python/paddle/vision/transforms/transforms.py | 16 +++++++++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index 67dff85f57..576415d543 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -62,11 +62,11 @@ def to_tensor(pic, data_format='CHW'): Args: pic (PIL.Image|np.ndarray): Image to be converted to tensor. - data_format (str, optional): Data format of input img, should be 'HWC' or + data_format (str, optional): Data format of output tensor, should be 'HWC' or 'CHW'. Default: 'CHW'. Returns: - Tensor: Converted image. Data format is same as input img. + Tensor: Converted image. Data type is same as input img. Examples: .. code-block:: python diff --git a/python/paddle/vision/transforms/functional_cv2.py b/python/paddle/vision/transforms/functional_cv2.py index 4cc04c39d0..65884f4ee5 100644 --- a/python/paddle/vision/transforms/functional_cv2.py +++ b/python/paddle/vision/transforms/functional_cv2.py @@ -40,7 +40,7 @@ def to_tensor(pic, data_format='CHW'): Args: pic (np.ndarray): Image to be converted to tensor. - data_format (str, optional): Data format of img, should be 'HWC' or + data_format (str, optional): Data format of output tensor, should be 'HWC' or 'CHW'. Default: 'CHW'. Returns: diff --git a/python/paddle/vision/transforms/functional_pil.py b/python/paddle/vision/transforms/functional_pil.py index 49b02fc049..1f06600b99 100644 --- a/python/paddle/vision/transforms/functional_pil.py +++ b/python/paddle/vision/transforms/functional_pil.py @@ -49,7 +49,7 @@ def to_tensor(pic, data_format='CHW'): Args: pic (PIL.Image): Image to be converted to tensor. - data_format (str, optional): Data format of img, should be 'HWC' or + data_format (str, optional): Data format of output tensor, should be 'HWC' or 'CHW'. Default: 'CHW'. Returns: diff --git a/python/paddle/vision/transforms/transforms.py b/python/paddle/vision/transforms/transforms.py index a24fc888ec..55790d977f 100644 --- a/python/paddle/vision/transforms/transforms.py +++ b/python/paddle/vision/transforms/transforms.py @@ -296,15 +296,21 @@ class BaseTransform(object): class ToTensor(BaseTransform): """Convert a ``PIL.Image`` or ``numpy.ndarray`` to ``paddle.Tensor``. - Converts a PIL.Image or numpy.ndarray (H x W x C) in the range - [0, 255] to a paddle.Tensor of shape (C x H x W) in the range [0.0, 1.0] - if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1) - or if the numpy.ndarray has dtype = np.uint8 + Converts a PIL.Image or numpy.ndarray (H x W x C) to a paddle.Tensor of shape (C x H x W). + + If input is a grayscale image (H x W), it will be converted to a image of shape (H x W x 1). + And the shape of output tensor will be (1 x H x W). + + If you want to keep the shape of output tensor as (H x W x C), you can set data_format = ``HWC`` . + + Converts a PIL.Image or numpy.ndarray in the range [0, 255] to a paddle.Tensor in the + range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, + RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8. In the other cases, tensors are returned without scaling. Args: - data_format (str, optional): Data format of input img, should be 'HWC' or + data_format (str, optional): Data format of output tensor, should be 'HWC' or 'CHW'. Default: 'CHW'. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. -- GitLab