未验证 提交 be85ecc9 编写于 作者: L LielinJiang 提交者: GitHub

Update en docs of to_tensor (#29718) (#29901)

* update to_tensor en docs
上级 41917fb5
...@@ -62,11 +62,11 @@ def to_tensor(pic, data_format='CHW'): ...@@ -62,11 +62,11 @@ def to_tensor(pic, data_format='CHW'):
Args: Args:
pic (PIL.Image|np.ndarray): Image to be converted to tensor. 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'. 'CHW'. Default: 'CHW'.
Returns: Returns:
Tensor: Converted image. Data format is same as input img. Tensor: Converted image. Data type is same as input img.
Examples: Examples:
.. code-block:: python .. code-block:: python
......
...@@ -40,7 +40,7 @@ def to_tensor(pic, data_format='CHW'): ...@@ -40,7 +40,7 @@ def to_tensor(pic, data_format='CHW'):
Args: Args:
pic (np.ndarray): Image to be converted to tensor. 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'. 'CHW'. Default: 'CHW'.
Returns: Returns:
......
...@@ -49,7 +49,7 @@ def to_tensor(pic, data_format='CHW'): ...@@ -49,7 +49,7 @@ def to_tensor(pic, data_format='CHW'):
Args: Args:
pic (PIL.Image): Image to be converted to tensor. 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'. 'CHW'. Default: 'CHW'.
Returns: Returns:
......
...@@ -296,15 +296,21 @@ class BaseTransform(object): ...@@ -296,15 +296,21 @@ class BaseTransform(object):
class ToTensor(BaseTransform): class ToTensor(BaseTransform):
"""Convert a ``PIL.Image`` or ``numpy.ndarray`` to ``paddle.Tensor``. """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 Converts a PIL.Image or numpy.ndarray (H x W x C) to a paddle.Tensor of shape (C x H x W).
[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) If input is a grayscale image (H x W), it will be converted to a image of shape (H x W x 1).
or if the numpy.ndarray has dtype = np.uint8 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. In the other cases, tensors are returned without scaling.
Args: 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'. 'CHW'. Default: 'CHW'.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册