From 4bd953e79868737dcc4abb907fb2278c4366e45d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 27 Aug 2020 00:22:40 +0000 Subject: [PATCH] Beautifier image doc --- tensorflow_addons/image/color_ops.py | 14 +++--- tensorflow_addons/image/compose_ops.py | 36 +++++++------- .../image/connected_components.py | 2 +- tensorflow_addons/image/cutout_ops.py | 35 ++++++------- tensorflow_addons/image/dense_image_warp.py | 8 +-- tensorflow_addons/image/distance_transform.py | 7 +-- tensorflow_addons/image/distort_image_ops.py | 18 +++---- tensorflow_addons/image/interpolate_spline.py | 49 ++++++++++--------- tensorflow_addons/image/resampler_ops.py | 6 +-- tensorflow_addons/image/sparse_image_warp.py | 30 ++++++------ tensorflow_addons/image/transform_ops.py | 18 ++++--- tensorflow_addons/image/translate_ops.py | 24 ++++----- tensorflow_addons/image/utils.py | 32 ++++++------ 13 files changed, 143 insertions(+), 136 deletions(-) diff --git a/tensorflow_addons/image/color_ops.py b/tensorflow_addons/image/color_ops.py index 34b88e3d64..5420897788 100644 --- a/tensorflow_addons/image/color_ops.py +++ b/tensorflow_addons/image/color_ops.py @@ -86,11 +86,11 @@ def equalize( Args: images: A tensor of shape - (num_images, num_rows, num_columns, num_channels) (NHWC), or - (num_images, num_channels, num_rows, num_columns) (NCHW), or - (num_rows, num_columns, num_channels) (HWC), or - (num_channels, num_rows, num_columns) (CHW), or - (num_rows, num_columns) (HW). The rank must be statically known (the + `(num_images, num_rows, num_columns, num_channels)` (NHWC), or + `(num_images, num_channels, num_rows, num_columns)` (NCHW), or + `(num_rows, num_columns, num_channels)` (HWC), or + `(num_channels, num_rows, num_columns)` (CHW), or + `(num_rows, num_columns)` (HW). The rank must be statically known (the shape is not `TensorShape(None)`). data_format: Either 'channels_first' or 'channels_last' name: The name of the op. @@ -149,8 +149,8 @@ def sharpness(image: TensorLike, factor: Number) -> tf.Tensor: Args: images: A tensor of shape - (num_images, num_rows, num_columns, num_channels) (NHWC), or - (num_rows, num_columns, num_channels) (HWC) + `(num_images, num_rows, num_columns, num_channels)` (NHWC), or + `(num_rows, num_columns, num_channels)` (HWC) factor: A floating point value or Tensor above 0.0. Returns: Image(s) with the same type and shape as `images`, sharper. diff --git a/tensorflow_addons/image/compose_ops.py b/tensorflow_addons/image/compose_ops.py index 827b360cf8..9d3aacac97 100644 --- a/tensorflow_addons/image/compose_ops.py +++ b/tensorflow_addons/image/compose_ops.py @@ -20,26 +20,28 @@ def blend(image1: TensorLike, image2: TensorLike, factor: Number) -> tf.Tensor: - """Blend image1 and image2 using 'factor'. + """Blend `image1` and `image2` using `factor`. - Factor can be above 0.0. A value of 0.0 means only image1 is used. - A value of 1.0 means only image2 is used. A value between 0.0 and - 1.0 means we linearly interpolate the pixel values between the two - images. A value greater than 1.0 "extrapolates" the difference - between the two pixel values, and we clip the results to values - between 0 and 255. + Factor can be above 0.0. A value of 0.0 means only `image1` is used. + A value of 1.0 means only `image2` is used. A value between 0.0 and + 1.0 means we linearly interpolate the pixel values between the two + images. A value greater than 1.0 "extrapolates" the difference + between the two pixel values, and we clip the results to values + between 0 and 255. - Args: - image1: An image Tensor of shape (num_rows, num_columns, - num_channels) (HWC), or (num_rows, num_columns) (HW), - or (num_channels, num_rows, num_columns). - image2: An image Tensor of shape (num_rows, num_columns, - num_channels) (HWC), or (num_rows, num_columns) (HW), - or (num_channels, num_rows, num_columns). - factor: A floating point value or Tensor of type tf.float32 above 0.0. + Args: + image1: An image Tensor of shape + `(num_rows, num_columns, num_channels)` (HWC), or + `(num_rows, num_columns)` (HW), or + `(num_channels, num_rows, num_columns)` (CHW). + image2: An image Tensor of shape + `(num_rows, num_columns, num_channels)` (HWC), or + `(num_rows, num_columns)` (HW), or + `(num_channels, num_rows, num_columns)`. + factor: A floating point value or Tensor of type `tf.float32` above 0.0. - Returns: - A blended image Tensor of tf.float32. + Returns: + A blended image Tensor of `tf.float32`. """ with tf.name_scope("blend"): diff --git a/tensorflow_addons/image/connected_components.py b/tensorflow_addons/image/connected_components.py index e60ee2dfe7..cedf70c65b 100644 --- a/tensorflow_addons/image/connected_components.py +++ b/tensorflow_addons/image/connected_components.py @@ -44,7 +44,7 @@ def connected_components( (which is the connectivity used here). Args: - images: A 2D (H, W) or 3D (N, H, W) Tensor of image (integer, + images: A 2D (H, W) or 3D (N, H, W) `Tensor` of image (integer, floating point and boolean types are supported). name: The name of the op. diff --git a/tensorflow_addons/image/cutout_ops.py b/tensorflow_addons/image/cutout_ops.py index 34c35a7849..6cf52b0980 100644 --- a/tensorflow_addons/image/cutout_ops.py +++ b/tensorflow_addons/image/cutout_ops.py @@ -54,18 +54,18 @@ def random_cutout( ) -> tf.Tensor: """Apply cutout (https://arxiv.org/abs/1708.04552) to images. - This operation applies a (mask_height x mask_width) mask of zeros to - a random location within `img`. The pixel values filled in will be of the - value `replace`. The located where the mask will be applied is randomly - chosen uniformly over the whole images. + This operation applies a `(mask_height x mask_width)` mask of zeros to + a random location within `images`. The pixel values filled in will be of + the value `replace`. The located where the mask will be applied is + randomly chosen uniformly over the whole images. Args: images: A tensor of shape - (batch_size, height, width, channels) - (NHWC), (batch_size, channels, height, width)(NCHW). + `(batch_size, height, width, channels)` + (NHWC), `(batch_size, channels, height, width)` (NCHW). mask_size: Specifies how big the zero mask that will be generated is that is applied to the images. The mask will be of size - (mask_height x mask_width). Note: mask_size should be divisible by 2. + `(mask_height x mask_width)`. Note: mask_size should be divisible by 2. constant_values: What pixel value to fill in the images in the area that has the cutout mask applied to it. seed: A Python integer. Used in combination with `tf.random.set_seed` to @@ -76,9 +76,9 @@ def random_cutout( `(batch_size, ..., channels)` while `channels_first` corresponds to inputs with shape `(batch_size, channels, ...)`. Returns: - An image Tensor. + An image `Tensor`. Raises: - InvalidArgumentError: if mask_size can't be divisible by 2. + InvalidArgumentError: if `mask_size` can't be divisible by 2. """ if data_format == "channels_first": warnings.warn( @@ -112,18 +112,19 @@ def cutout( ) -> tf.Tensor: """Apply cutout (https://arxiv.org/abs/1708.04552) to images. - This operation applies a (mask_height x mask_width) mask of zeros to - a location within `img` specified by the offset. The pixel values filled in will be of the - value `replace`. The located where the mask will be applied is randomly + This operation applies a `(mask_height x mask_width)` mask of zeros to + a location within `images` specified by the offset. + The pixel values filled in will be of the value `replace`. + The located where the mask will be applied is randomly chosen uniformly over the whole images. Args: - images: A tensor of shape (batch_size, height, width, channels) - (NHWC), (batch_size, channels, height, width)(NCHW). + images: A tensor of shape `(batch_size, height, width, channels)` + (NHWC), `(batch_size, channels, height, width)` (NCHW). mask_size: Specifies how big the zero mask that will be generated is that is applied to the images. The mask will be of size - (mask_height x mask_width). Note: mask_size should be divisible by 2. - offset: A tuple of (height, width) or (batch_size, 2) + `(mask_height x mask_width)`. Note: mask_size should be divisible by 2. + offset: A tuple of `(height, width)` or `(batch_size, 2)` constant_values: What pixel value to fill in the images in the area that has the cutout mask applied to it. data_format: A string, one of `channels_last` (default) or `channels_first`. @@ -134,7 +135,7 @@ def cutout( Returns: An image Tensor. Raises: - InvalidArgumentError: if mask_size can't be divisible by 2. + InvalidArgumentError: if `mask_size` can't be divisible by 2. """ if data_format == "channels_first": warnings.warn( diff --git a/tensorflow_addons/image/dense_image_warp.py b/tensorflow_addons/image/dense_image_warp.py index 291f552b7d..0fed349838 100644 --- a/tensorflow_addons/image/dense_image_warp.py +++ b/tensorflow_addons/image/dense_image_warp.py @@ -210,7 +210,7 @@ def dense_image_warp( `(b, j - flow[b, j, i, 0], i - flow[b, j, i, 1])`. For locations outside of the image, we use the nearest pixel values at the image boundary. - PLEASE NOTE: The definition of the flow field above is different from that + NOTE: The definition of the flow field above is different from that of optical flow. This function expects the negative forward flow from output image to source image. Given two images `I_1` and `I_2` and the optical flow `F_12` from `I_1` to `I_2`, the image `I_1` can be @@ -221,15 +221,15 @@ def dense_image_warp( flow: A 4-D float `Tensor` with shape `[batch, height, width, 2]`. name: A name for the operation (optional). - Note that image and flow can be of type tf.half, tf.float32, or - tf.float64, and do not necessarily have to be the same type. + Note that image and flow can be of type `tf.half`, `tf.float32`, or + `tf.float64`, and do not necessarily have to be the same type. Returns: A 4-D float `Tensor` with shape`[batch, height, width, channels]` and same type as input image. Raises: - ValueError: if height < 2 or width < 2 or the inputs have the wrong + ValueError: if `height < 2` or `width < 2` or the inputs have the wrong number of dimensions. """ with tf.name_scope(name or "dense_image_warp"): diff --git a/tensorflow_addons/image/distance_transform.py b/tensorflow_addons/image/distance_transform.py index deaca635f7..f6916a167c 100644 --- a/tensorflow_addons/image/distance_transform.py +++ b/tensorflow_addons/image/distance_transform.py @@ -34,9 +34,10 @@ def euclidean_dist_transform( """Applies euclidean distance transform(s) to the image(s). Args: - images: A tensor of shape (num_images, num_rows, num_columns, 1) (NHWC), - or (num_rows, num_columns, 1) (HWC) or (num_rows, num_columns) (HW). - dtype: DType of the output tensor. + images: A tensor of shape `(num_images, num_rows, num_columns, 1)` + (NHWC), or `(num_rows, num_columns, 1)` (HWC) or + `(num_rows, num_columns)` (HW). + dtype: `tf.dtypes.DType` of the output tensor. name: The name of the op. Returns: diff --git a/tensorflow_addons/image/distort_image_ops.py b/tensorflow_addons/image/distort_image_ops.py index de498ae462..9d1bc71d4b 100644 --- a/tensorflow_addons/image/distort_image_ops.py +++ b/tensorflow_addons/image/distort_image_ops.py @@ -43,12 +43,12 @@ def random_hsv_in_yiq( Args: image: RGB image or images. Size of the last dimension must be 3. - max_delta_hue: float. Maximum value for the random delta_hue. Passing 0 + max_delta_hue: `float`. Maximum value for the random delta_hue. Passing 0 disables adjusting hue. - lower_saturation: float. Lower bound for the random scale_saturation. - upper_saturation: float. Upper bound for the random scale_saturation. - lower_value: float. Lower bound for the random scale_value. - upper_value: float. Upper bound for the random scale_value. + lower_saturation: `float`. Lower bound for the random scale_saturation. + upper_saturation: `float`. Upper bound for the random scale_saturation. + lower_value: `float`. Lower bound for the random scale_value. + upper_value: `float`. Upper bound for the random scale_value. seed: An operation-specific seed. It will be used in conjunction with the graph-level seed to determine the real seeds that will be used in this operation. Please see the documentation of @@ -56,7 +56,7 @@ def random_hsv_in_yiq( name: A name for this operation (optional). Returns: - 3-D float tensor of shape `[height, width, channels]`. + 3-D float `Tensor` of shape `[height, width, channels]`. Raises: ValueError: if `max_delta`, `lower_saturation`, `upper_saturation`, @@ -122,9 +122,9 @@ def adjust_hsv_in_yiq( Args: image: RGB image or images. Size of the last dimension must be 3. - delta_hue: float, the hue rotation amount, in radians. - scale_saturation: float, factor to multiply the saturation by. - scale_value: float, factor to multiply the value by. + delta_hue: `float`, the hue rotation amount, in radians. + scale_saturation: `float`, factor to multiply the saturation by. + scale_value: `float`, factor to multiply the value by. name: A name for this operation (optional). Returns: diff --git a/tensorflow_addons/image/interpolate_spline.py b/tensorflow_addons/image/interpolate_spline.py index dfac3165c0..6d27599245 100644 --- a/tensorflow_addons/image/interpolate_spline.py +++ b/tensorflow_addons/image/interpolate_spline.py @@ -23,14 +23,15 @@ def _cross_squared_distance_matrix(x: TensorLike, y: TensorLike) -> tf.Tensor: """Pairwise squared distance between two (batch) matrices' rows (2nd dim). - Computes the pairwise distances between rows of x and rows of y + Computes the pairwise distances between rows of x and rows of y. + Args: - x: [batch_size, n, d] float `Tensor` - y: [batch_size, m, d] float `Tensor` + x: `[batch_size, n, d]` float `Tensor`. + y: `[batch_size, m, d]` float `Tensor`. Returns: - squared_dists: [batch_size, n, m] float `Tensor`, where - squared_dists[b,i,j] = ||x[b,i,:] - y[b,j,:]||^2 + squared_dists: `[batch_size, n, m]` float `Tensor`, where + `squared_dists[b,i,j] = ||x[b,i,:] - y[b,j,:]||^2`. """ x_norm_squared = tf.reduce_sum(tf.square(x), 2) y_norm_squared = tf.reduce_sum(tf.square(y), 2) @@ -52,14 +53,14 @@ def _pairwise_squared_distance_matrix(x: TensorLike) -> tf.Tensor: """Pairwise squared distance among a (batch) matrix's rows (2nd dim). This saves a bit of computation vs. using - _cross_squared_distance_matrix(x,x) + `_cross_squared_distance_matrix(x, x)` Args: - x: `[batch_size, n, d]` float `Tensor` + x: `[batch_size, n, d]` float `Tensor`. Returns: squared_dists: `[batch_size, n, n]` float `Tensor`, where - squared_dists[b,i,j] = ||x[b,i,:] - x[b,j,:]||^2 + `squared_dists[b,i,j] = ||x[b,i,:] - x[b,j,:]||^2`. """ x_x_transpose = tf.matmul(x, x, adjoint_b=True) @@ -83,17 +84,17 @@ def _solve_interpolation( order: int, regularization_weight: FloatTensorLike, ) -> TensorLike: - """Solve for interpolation coefficients. + r"""Solve for interpolation coefficients. Computes the coefficients of the polyharmonic interpolant for the - 'training' data defined by (train_points, train_values) using the kernel - phi. + 'training' data defined by `(train_points, train_values)` using the kernel + $\phi$. Args: - train_points: `[b, n, d]` interpolation centers - train_values: `[b, n, k]` function values - order: order of the interpolation - regularization_weight: weight to place on smoothness regularization term + train_points: `[b, n, d]` interpolation centers. + train_values: `[b, n, k]` function values. + order: order of the interpolation. + regularization_weight: weight to place on smoothness regularization term. Returns: w: `[b, n, k]` weights on each interpolation center @@ -173,15 +174,15 @@ def _apply_interpolation( interpolated function values at query_points. Args: - query_points: `[b, m, d]` x values to evaluate the interpolation at + query_points: `[b, m, d]` x values to evaluate the interpolation at. train_points: `[b, n, d]` x values that act as the interpolation centers - ( the c variables in the wikipedia article) - w: `[b, n, k]` weights on each interpolation center - v: `[b, d, k]` weights on each input dimension - order: order of the interpolation + (the c variables in the wikipedia article). + w: `[b, n, k]` weights on each interpolation center. + v: `[b, d, k]` weights on each input dimension. + order: order of the interpolation. Returns: - Polyharmonic interpolation evaluated at points defined in query_points. + Polyharmonic interpolation evaluated at points defined in `query_points`. """ # First, compute the contribution from the rbf term. @@ -207,11 +208,11 @@ def _phi(r: FloatTensorLike, order: int) -> FloatTensorLike: See https://en.wikipedia.org/wiki/Polyharmonic_spline for the definition. Args: - r: input op - order: interpolation order + r: input op. + order: interpolation order. Returns: - phi_k evaluated coordinate-wise on r, for k = r + `phi_k` evaluated coordinate-wise on `r`, for `k = r`. """ # using EPSILON prevents log(0), sqrt0), etc. diff --git a/tensorflow_addons/image/resampler_ops.py b/tensorflow_addons/image/resampler_ops.py index 6e769f53a0..7ac57c922f 100644 --- a/tensorflow_addons/image/resampler_ops.py +++ b/tensorflow_addons/image/resampler_ops.py @@ -33,13 +33,13 @@ def resampler( The resampler currently only supports bilinear interpolation of 2D data. Args: - data: Tensor of shape `[batch_size, data_height, data_width, + data: `Tensor` of shape `[batch_size, data_height, data_width, data_num_channels]` containing 2D data that will be resampled. warp: Tensor of minimum rank 2 containing the coordinates at which resampling will be performed. Since only bilinear interpolation is currently supported, the last dimension of the - `warp` tensor must be 2, representing the (x, y) coordinate where - x is the index for width and y is the index for height. + `warp` tensor must be 2, representing the `(x, y)` coordinate where + `x` is the index for width and `y` is the index for height. name: Optional name of the op. Returns: Tensor of resampled values from `data`. The output tensor shape diff --git a/tensorflow_addons/image/sparse_image_warp.py b/tensorflow_addons/image/sparse_image_warp.py index c19bde27a8..9b50a4da08 100644 --- a/tensorflow_addons/image/sparse_image_warp.py +++ b/tensorflow_addons/image/sparse_image_warp.py @@ -24,7 +24,7 @@ def _get_grid_locations( image_height: TensorLike, image_width: TensorLike ) -> TensorLike: - """Wrapper for np.meshgrid.""" + """Wrapper for `np.meshgrid`.""" y_range = np.linspace(0, image_height - 1, image_height) x_range = np.linspace(0, image_width - 1, image_width) @@ -65,18 +65,18 @@ def _add_zero_flow_controls_at_boundary( boundary of the image that have zero flow. Args: - control_point_locations: input control points - control_point_flows: their flows - image_height: image height - image_width: image width + control_point_locations: input control points. + control_point_flows: their flows. + image_height: image height. + image_width: image width. boundary_points_per_edge: number of points to add in the middle of each - edge (not including the corners). - The total number of points added is - 4 + 4*(boundary_points_per_edge). + edge (not including the corners). + The total number of points added is + `4 + 4*(boundary_points_per_edge)`. Returns: - merged_control_point_locations: augmented set of control point locations - merged_control_point_flows: augmented set of control point flows + merged_control_point_locations: augmented set of control point locations. + merged_control_point_flows: augmented set of control point flows. """ batch_size = tf.compat.dimension_value(control_point_locations.shape[0]) @@ -148,12 +148,12 @@ def sparse_image_warp( interpolation_order: polynomial order used by the spline interpolation regularization_weight: weight on smoothness regularizer in interpolation num_boundary_points: How many zero-flow boundary points to include at - each image edge.Usage: - num_boundary_points=0: don't add zero-flow points - num_boundary_points=1: 4 corners of the image - num_boundary_points=2: 4 corners and one in the middle of each edge + each image edge. Usage: + `num_boundary_points=0`: don't add zero-flow points + `num_boundary_points=1`: 4 corners of the image + `num_boundary_points=2`: 4 corners and one in the middle of each edge (8 points total) - num_boundary_points=n: 4 corners and n-1 along each edge + `num_boundary_points=n`: 4 corners and n-1 along each edge name: A name for the operation (optional). Note that image and offsets can be of type tf.half, tf.float32, or diff --git a/tensorflow_addons/image/transform_ops.py b/tensorflow_addons/image/transform_ops.py index 80bc5c8950..0361cb8203 100644 --- a/tensorflow_addons/image/transform_ops.py +++ b/tensorflow_addons/image/transform_ops.py @@ -274,10 +274,10 @@ def rotate( Args: images: A tensor of shape - (num_images, num_rows, num_columns, num_channels) - (NHWC), (num_rows, num_columns, num_channels) (HWC), or - (num_rows, num_columns) (HW). - angles: A scalar angle to rotate all images by, or (if images has rank 4) + `(num_images, num_rows, num_columns, num_channels)` + (NHWC), `(num_rows, num_columns, num_channels)` (HWC), or + `(num_rows, num_columns)` (HW). + angles: A scalar angle to rotate all images by, or (if `images` has rank 4) a vector of length num_images, with an angle for each image in the batch. interpolation: Interpolation mode. Supported values: "NEAREST", @@ -289,7 +289,7 @@ def rotate( angle(s). Empty space due to the rotation will be filled with zeros. Raises: - TypeError: If `image` is an invalid type. + TypeError: If `images` is an invalid type. """ with tf.name_scope(name or "rotate"): image_or_images = tf.convert_to_tensor(images) @@ -309,7 +309,8 @@ def rotate( def shear_x(image: TensorLike, level: float, replace: int) -> TensorLike: - """Perform shear operation on an image (x-axis) + """Perform shear operation on an image (x-axis). + Args: image: A 3D image Tensor. level: A float denoting shear element along y-axis @@ -327,9 +328,10 @@ def shear_x(image: TensorLike, level: float, replace: int) -> TensorLike: def shear_y(image: TensorLike, level: float, replace: int) -> TensorLike: - """Perform shear operation on an image (y-axis) + """Perform shear operation on an image (y-axis). + Args: - image: A 3D image Tensor. + image: A 3D image `Tensor`. level: A float denoting shear element along x-axis replace: A one or three value 1D tensor to fill empty pixels. Returns: diff --git a/tensorflow_addons/image/translate_ops.py b/tensorflow_addons/image/translate_ops.py index cb6a1a0611..bf3c96ac9e 100644 --- a/tensorflow_addons/image/translate_ops.py +++ b/tensorflow_addons/image/translate_ops.py @@ -28,13 +28,13 @@ def translations_to_projective_transforms( """Returns projective transform(s) for the given translation(s). Args: - translations: A 2-element list representing [dx, dy] or a matrix of - 2-element lists representing [dx, dy] to translate for each image + translations: A 2-element list representing `[dx, dy]` or a matrix of + 2-element lists representing `[dx, dy]` to translate for each image (for a batch of images). The rank must be statically known (the shape is not `TensorShape(None)`). name: The name of the op. Returns: - A tensor of shape (num_images, 8) projective transforms which can be + A tensor of shape `(num_images, 8)` projective transforms which can be given to `tfa.image.transform`. """ with tf.name_scope(name or "translations_to_projective_transforms"): @@ -81,12 +81,12 @@ def translate( Args: images: A tensor of shape - (num_images, num_rows, num_columns, num_channels) (NHWC), - (num_rows, num_columns, num_channels) (HWC), or - (num_rows, num_columns) (HW). The rank must be statically known (the + `(num_images, num_rows, num_columns, num_channels)` (NHWC), + `(num_rows, num_columns, num_channels)` (HWC), or + `(num_rows, num_columns)` (HW). The rank must be statically known (the shape is not `TensorShape(None)`). - translations: A vector representing [dx, dy] or (if images has rank 4) - a matrix of length num_images, with a [dx, dy] vector for each image + translations: A vector representing `[dx, dy]` or (if `images` has rank 4) + a matrix of length num_images, with a `[dx, dy]` vector for each image in the batch. interpolation: Interpolation mode. Supported values: "NEAREST", "BILINEAR". @@ -112,12 +112,12 @@ def translate_xy( """Translates image in X or Y dimension. Args: - image: A 3D image Tensor. - translate_to: A 1D tensor to translate [x, y] - replace: A one or three value 1D tensor to fill empty pixels. + image: A 3D image `Tensor`. + translate_to: A 1D `Tensor` to translate [x, y] + replace: A one or three value 1D `Tensor` to fill empty pixels. Returns: Translated image along X or Y axis, with space outside image - filled with replace. + filled with replace. Raises: ValueError: if axis is neither 0 nor 1. """ diff --git a/tensorflow_addons/image/utils.py b/tensorflow_addons/image/utils.py index 4bd4bf46d7..e4bf497ebc 100644 --- a/tensorflow_addons/image/utils.py +++ b/tensorflow_addons/image/utils.py @@ -25,10 +25,10 @@ def to_4D_image(image): """Convert 2/3/4D image to 4D image. Args: - image: 2/3/4D tensor. + image: 2/3/4D `Tensor`. Returns: - 4D tensor with the same type. + 4D `Tensor` with the same type. """ with tf.control_dependencies( [ @@ -71,11 +71,11 @@ def from_4D_image(image, ndims): """Convert back to an image with `ndims` rank. Args: - image: 4D tensor. + image: 4D `Tensor`. ndims: The original rank of the image. Returns: - `ndims`-D tensor with the same type. + `ndims`-D `Tensor` with the same type. """ with tf.control_dependencies( [tf.debugging.assert_rank(image, 4, message="`image` must be 4D tensor")] @@ -102,7 +102,7 @@ def _dynamic_from_4D_image(image, original_rank): def wrap(image): - """Returns 'image' with an extra channel set to all 1s.""" + """Returns `image` with an extra channel set to all 1s.""" shape = tf.shape(image) extended_channel = tf.ones([shape[0], shape[1], 1], image.dtype) extended = tf.concat([image, extended_channel], 2) @@ -112,20 +112,20 @@ def wrap(image): def unwrap(image, replace): """Unwraps an image produced by wrap. - Where there is a 0 in the last channel for every spatial position, - the rest of the three channels in that spatial dimension are grayed - (set to 128). Operations like translate and shear on a wrapped - Tensor will leave 0s in empty locations. Some transformations look - at the intensity of values to do preprocessing, and we want these - empty pixels to assume the 'average' value, rather than pure black. + Where there is a 0 in the last channel for every spatial position, + the rest of the three channels in that spatial dimension are grayed + (set to 128). Operations like translate and shear on a wrapped + Tensor will leave 0s in empty locations. Some transformations look + at the intensity of values to do preprocessing, and we want these + empty pixels to assume the 'average' value, rather than pure black. - Args: - image: A 3D Image Tensor with 4 channels. - replace: A one or three value 1D tensor to fill empty pixels. + Args: + image: A 3D image `Tensor` with 4 channels. + replace: A one or three value 1D `Tensor` to fill empty pixels. - Returns: - image: A 3D image Tensor with 3 channels. + Returns: + image: A 3D image `Tensor` with 3 channels. """ image_shape = tf.shape(image) # Flatten the spatial dimensions.