diff --git a/paddle/fluid/operators/controlflow/bitwise_op.cc b/paddle/fluid/operators/controlflow/bitwise_op.cc index 90faea31532de771f7a6a0e6d7246770b9673180..4b339f4bd58627c0e6d18b0ae0fa9610fda7c019 100644 --- a/paddle/fluid/operators/controlflow/bitwise_op.cc +++ b/paddle/fluid/operators/controlflow/bitwise_op.cc @@ -48,7 +48,9 @@ It operates ``%s`` on Tensor ``X`` and ``Y`` . %s .. note:: - ``paddle.%s`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.%s`` supports broadcasting. If you want know more about broadcasting, please refer to please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor. )DOC", comment.type, comment.equation, diff --git a/python/paddle/distribution/uniform.py b/python/paddle/distribution/uniform.py index 1b1ef5906d964338f5c969f66c5ba274c39a7bdc..9b41dd026709f43326c1de44f6a8310d29b4e9da 100644 --- a/python/paddle/distribution/uniform.py +++ b/python/paddle/distribution/uniform.py @@ -49,7 +49,12 @@ class Uniform(distribution.Distribution): * :math:`Z`: is the normalizing constant. The parameters `low` and `high` must be shaped in a way that supports - :ref:`user_guide_broadcasting` (e.g., `high - low` is a valid operation). + `Boardcasting` (e.g., `high - low` is a valid operation). + + Note: + If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: low(int|float|list|tuple|numpy.ndarray|Tensor): The lower boundary of diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index e44582c0f3a11b009c56688b52a5e61733767f57..e5005dbe16f206dcb454b5334041dfcf4a59eb8b 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -2005,8 +2005,10 @@ def complex(real, imag, name=None): Returns: Tensor: The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``real`` and ``imag``. - **Note**: - ``paddle.complex`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + Note: + ``paddle.complex`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Examples: .. code-block:: python diff --git a/python/paddle/tensor/logic.py b/python/paddle/tensor/logic.py index a4cc95edfc7c35dc7d8fbb7145256341d2582f26..271aa7240115f1f08b056b51b1e8923e0c0aadda 100755 --- a/python/paddle/tensor/logic.py +++ b/python/paddle/tensor/logic.py @@ -96,7 +96,9 @@ def logical_and(x, y, out=None, name=None): out = x \&\& y Note: - ``paddle.logical_and`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.logical_and`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64. @@ -136,7 +138,9 @@ def logical_or(x, y, out=None, name=None): out = x || y Note: - ``paddle.logical_or`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.logical_or`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64. @@ -178,7 +182,9 @@ def logical_xor(x, y, out=None, name=None): out = (x || y) \&\& !(x \&\& y) Note: - ``paddle.logical_xor`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.logical_xor`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64. @@ -221,6 +227,11 @@ def logical_not(x, out=None, name=None): out = !x + Note: + ``paddle.logical_not`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor + Args: x(Tensor): Operand of logical_not operator. Must be a Tensor of type bool, int8, int16, in32, in64, float32, or float64. out(Tensor): The ``Tensor`` that specifies the output of the operator, which can be any ``Tensor`` that has been created in the program. The default value is None, and a new ``Tensor` will be created to save the output. diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 40dd2291e4c0a6a9a982308ca393cee97575fb95..857f99c8f6bce29d9d1fb54f8c7dd977686214b3 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -420,7 +420,9 @@ def pow(x, y, name=None): out = x^{y} Note: - ``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensors Args: @@ -679,7 +681,9 @@ def subtract(x, y, name=None): out = x - y Note: - ``paddle.subtract`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.subtract`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64. @@ -773,7 +777,9 @@ def divide(x, y, name=None): out = x / y Note: - ``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64. @@ -817,7 +823,10 @@ def floor_divide(x, y, name=None): out = trunc(x / y) Note: - ``paddle.floor_divide`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.floor_divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor + Also note that the name ``floor_divide`` can be misleading, as the quotinents are actually rounded toward zero, not toward negative infinite. Args: @@ -859,7 +868,9 @@ def remainder(x, y, name=None): out = x \% y Note: - ``paddle.remainder`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.remainder`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64. @@ -924,7 +935,9 @@ def multiply(x, y, name=None): out = x * y Note: - ``paddle.multiply`` supports broadcasting. If you would like to know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.multiply`` supports broadcasting. If you would like to know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, its data type should be one of float32, float64, int32, int64, bool. @@ -980,7 +993,9 @@ def maximum(x, y, name=None): out = max(x, y) Note: - ``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64. @@ -1046,7 +1061,9 @@ def minimum(x, y, name=None): out = min(x, y) Note: - ``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64. @@ -1114,7 +1131,9 @@ def fmax(x, y, name=None): out = fmax(x, y) Note: - ``paddle.fmax`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.fmax`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64. @@ -1182,7 +1201,9 @@ def fmin(x, y, name=None): out = fmin(x, y) Note: - ``paddle.fmin`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` . + ``paddle.fmin`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64. @@ -3962,7 +3983,12 @@ def any(x, axis=None, keepdim=False, name=None): def broadcast_shape(x_shape, y_shape): """ - The function returns the shape of doing operation with broadcasting on tensors of x_shape and y_shape, please refer to :ref:`user_guide_broadcasting` for more details. + The function returns the shape of doing operation with broadcasting on tensors of x_shape and y_shape. + + Note: + If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x_shape (list[int]|tuple[int]): A shape of tensor. @@ -4991,7 +5017,9 @@ def heaviside(x, y, name=None): \right. Note: - ``paddle.heaviside`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`. + ``paddle.heaviside`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . + + .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor Args: x (Tensor): The input tensor of Heaviside step function, it's data type should be float16, float32, float64, int32 or int64. diff --git a/python/paddle/vision/image.py b/python/paddle/vision/image.py index 8285132e4ea3e45ba01b2eb124d93a76e366d6ab..7a512176c1efe4171a9a89a3ec5dd20882f16912 100644 --- a/python/paddle/vision/image.py +++ b/python/paddle/vision/image.py @@ -23,8 +23,8 @@ _image_backend = 'pil' def set_image_backend(backend): """ - Specifies the backend used to load images in class ``paddle.vision.datasets.ImageFolder`` - and ``paddle.vision.datasets.DatasetFolder`` . Now support backends are pillow and opencv. + Specifies the backend used to load images in class :ref:`api_paddle_datasets_ImageFolder` + and :ref:`api_paddle_datasets_DatasetFolder` . Now support backends are pillow and opencv. If backend not set, will use 'pil' as default. Args: @@ -117,7 +117,7 @@ def image_load(path, backend=None): path (str): Path of the image. backend (str, optional): The image decoding backend type. Options are `cv2`, `pil`, `None`. If backend is None, the global _imread_backend - specified by ``paddle.vision.set_image_backend`` will be used. Default: None. + specified by :ref:`api_paddle_vision_set_image_backend` will be used. Default: None. Returns: PIL.Image or np.array: Loaded image. diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index b5889981d248700d3ea88251b0ae251d1edd7feb..d58c0f610edb37d9d4291997dfafcec26c266399 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -42,7 +42,18 @@ def _is_numpy_image(img): def to_tensor(pic, data_format='CHW'): """Converts a ``PIL.Image`` or ``numpy.ndarray`` to paddle.Tensor. - See ``ToTensor`` for more details. + 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 an 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: pic (PIL.Image|np.ndarray): Image to be converted to tensor. @@ -764,7 +775,7 @@ def rotate( center (2-list|2-tuple, optional): Optional center of rotation. Origin is the upper left corner. Default is the center of the image. - fill (3-list|3-tuple or int): RGB pixel fill value for area outside the rotated image. + fill (3-list|3-tuple or int, optional): RGB pixel fill value for area outside the rotated image. If int, it is used for all channels respectively. Default value is 0. diff --git a/python/paddle/vision/transforms/transforms.py b/python/paddle/vision/transforms/transforms.py index 9b14c775982a3b785273264ff3de34f9ab0cf5f3..cb48598c8fd1419a0c1fbae36648775ea161d944 100644 --- a/python/paddle/vision/transforms/transforms.py +++ b/python/paddle/vision/transforms/transforms.py @@ -136,6 +136,8 @@ class BaseTransform: calling logic: + .. code-block:: text + if keys is None: _get_params -> _apply_image() else: @@ -153,14 +155,11 @@ class BaseTransform: Current available strings & data type are describe below: - - "image": input image, with shape of (H, W, C) - - "coords": coordinates, with shape of (N, 2) - - "boxes": bounding boxes, with shape of (N, 4), "xyxy" format, - - the 1st "xy" represents top left point of a box, - the 2nd "xy" represents right bottom point. - - - "mask": map used for segmentation, with shape of (H, W, 1) + - "image": input image, with shape of (H, W, C) + - "coords": coordinates, with shape of (N, 2) + - "boxes": bounding boxes, with shape of (N, 4), "xyxy" format,the 1st "xy" represents + top left point of a box,the 2nd "xy" represents right bottom point. + - "mask": map used for segmentation, with shape of (H, W, 1) You can also customize your data types only if you implement the corresponding _apply_*() methods, otherwise ``NotImplementedError`` will be raised. @@ -433,9 +432,9 @@ class RandomResizedCrop(BaseTransform): Args: size (int|list|tuple): Target size of output image, with (height, width) shape. - scale (list|tuple): Scale range of the cropped image before resizing, relatively to the origin - image. Default: (0.08, 1.0) - ratio (list|tuple): Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33) + scale (list|tuple, optional): Scale range of the cropped image before resizing, relatively to the origin + image. Default: (0.08, 1.0). + ratio (list|tuple, optional): Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33) interpolation (int|str, optional): Interpolation method. Default: 'bilinear'. when use pil backend, support method are as following: - "nearest": Image.NEAREST, @@ -778,7 +777,7 @@ class BrightnessTransform(BaseTransform): Args: value (float): How much to adjust the brightness. Can be any - non negative number. 0 gives the original image + non negative number. 0 gives the original image. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: @@ -821,7 +820,7 @@ class ContrastTransform(BaseTransform): Args: value (float): How much to adjust the contrast. Can be any - non negative number. 0 gives the original image + non negative number. 0 gives the original image. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: @@ -866,7 +865,7 @@ class SaturationTransform(BaseTransform): Args: value (float): How much to adjust the saturation. Can be any - non negative number. 0 gives the original image + non negative number. 0 gives the original image. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: @@ -909,7 +908,7 @@ class HueTransform(BaseTransform): Args: value (float): How much to adjust the hue. Can be any number - between 0 and 0.5, 0 gives the original image + between 0 and 0.5, 0 gives the original image. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: @@ -953,14 +952,14 @@ class ColorJitter(BaseTransform): """Randomly change the brightness, contrast, saturation and hue of an image. Args: - brightness (float): How much to jitter brightness. - Chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. Should be non negative numbers. - contrast (float): How much to jitter contrast. - Chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. Should be non negative numbers. - saturation (float): How much to jitter saturation. - Chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. Should be non negative numbers. - hue (float): How much to jitter hue. - Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5. + brightness (float, optional): How much to jitter brightness. + Chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. Should be non negative numbers. Default: 0. + contrast (float, optional): How much to jitter contrast. + Chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. Should be non negative numbers. Default: 0. + saturation (float, optional): How much to jitter saturation. + Chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. Should be non negative numbers. Default: 0. + hue (float, optional): How much to jitter hue. + Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5. Default: 0. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: @@ -1665,7 +1664,7 @@ class Grayscale(BaseTransform): """Converts image to grayscale. Args: - num_output_channels (int): (1 or 3) number of channels desired for output image + num_output_channels (int, optional): (1 or 3) number of channels desired for output image. Default: 1. keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None. Shape: