Skip to content

Commit e40a266

Browse files
authored
beautifier image doc (#2101)
1 parent f3a50e7 commit e40a266

13 files changed

+143
-136
lines changed

tensorflow_addons/image/color_ops.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def equalize(
8686
8787
Args:
8888
images: A tensor of shape
89-
(num_images, num_rows, num_columns, num_channels) (NHWC), or
90-
(num_images, num_channels, num_rows, num_columns) (NCHW), or
91-
(num_rows, num_columns, num_channels) (HWC), or
92-
(num_channels, num_rows, num_columns) (CHW), or
93-
(num_rows, num_columns) (HW). The rank must be statically known (the
89+
`(num_images, num_rows, num_columns, num_channels)` (NHWC), or
90+
`(num_images, num_channels, num_rows, num_columns)` (NCHW), or
91+
`(num_rows, num_columns, num_channels)` (HWC), or
92+
`(num_channels, num_rows, num_columns)` (CHW), or
93+
`(num_rows, num_columns)` (HW). The rank must be statically known (the
9494
shape is not `TensorShape(None)`).
9595
data_format: Either 'channels_first' or 'channels_last'
9696
name: The name of the op.
@@ -149,8 +149,8 @@ def sharpness(image: TensorLike, factor: Number) -> tf.Tensor:
149149
150150
Args:
151151
images: A tensor of shape
152-
(num_images, num_rows, num_columns, num_channels) (NHWC), or
153-
(num_rows, num_columns, num_channels) (HWC)
152+
`(num_images, num_rows, num_columns, num_channels)` (NHWC), or
153+
`(num_rows, num_columns, num_channels)` (HWC)
154154
factor: A floating point value or Tensor above 0.0.
155155
Returns:
156156
Image(s) with the same type and shape as `images`, sharper.

tensorflow_addons/image/compose_ops.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,28 @@
2020

2121

2222
def blend(image1: TensorLike, image2: TensorLike, factor: Number) -> tf.Tensor:
23-
"""Blend image1 and image2 using 'factor'.
23+
"""Blend `image1` and `image2` using `factor`.
2424
25-
Factor can be above 0.0. A value of 0.0 means only image1 is used.
26-
A value of 1.0 means only image2 is used. A value between 0.0 and
27-
1.0 means we linearly interpolate the pixel values between the two
28-
images. A value greater than 1.0 "extrapolates" the difference
29-
between the two pixel values, and we clip the results to values
30-
between 0 and 255.
25+
Factor can be above 0.0. A value of 0.0 means only `image1` is used.
26+
A value of 1.0 means only `image2` is used. A value between 0.0 and
27+
1.0 means we linearly interpolate the pixel values between the two
28+
images. A value greater than 1.0 "extrapolates" the difference
29+
between the two pixel values, and we clip the results to values
30+
between 0 and 255.
3131
32-
Args:
33-
image1: An image Tensor of shape (num_rows, num_columns,
34-
num_channels) (HWC), or (num_rows, num_columns) (HW),
35-
or (num_channels, num_rows, num_columns).
36-
image2: An image Tensor of shape (num_rows, num_columns,
37-
num_channels) (HWC), or (num_rows, num_columns) (HW),
38-
or (num_channels, num_rows, num_columns).
39-
factor: A floating point value or Tensor of type tf.float32 above 0.0.
32+
Args:
33+
image1: An image Tensor of shape
34+
`(num_rows, num_columns, num_channels)` (HWC), or
35+
`(num_rows, num_columns)` (HW), or
36+
`(num_channels, num_rows, num_columns)` (CHW).
37+
image2: An image Tensor of shape
38+
`(num_rows, num_columns, num_channels)` (HWC), or
39+
`(num_rows, num_columns)` (HW), or
40+
`(num_channels, num_rows, num_columns)`.
41+
factor: A floating point value or Tensor of type `tf.float32` above 0.0.
4042
41-
Returns:
42-
A blended image Tensor of tf.float32.
43+
Returns:
44+
A blended image Tensor of `tf.float32`.
4345
4446
"""
4547
with tf.name_scope("blend"):

tensorflow_addons/image/connected_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def connected_components(
4444
(which is the connectivity used here).
4545
4646
Args:
47-
images: A 2D (H, W) or 3D (N, H, W) Tensor of image (integer,
47+
images: A 2D (H, W) or 3D (N, H, W) `Tensor` of image (integer,
4848
floating point and boolean types are supported).
4949
name: The name of the op.
5050

tensorflow_addons/image/cutout_ops.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ def random_cutout(
5454
) -> tf.Tensor:
5555
"""Apply cutout (https://arxiv.org/abs/1708.04552) to images.
5656
57-
This operation applies a (mask_height x mask_width) mask of zeros to
58-
a random location within `img`. The pixel values filled in will be of the
59-
value `replace`. The located where the mask will be applied is randomly
60-
chosen uniformly over the whole images.
57+
This operation applies a `(mask_height x mask_width)` mask of zeros to
58+
a random location within `images`. The pixel values filled in will be of
59+
the value `replace`. The located where the mask will be applied is
60+
randomly chosen uniformly over the whole images.
6161
6262
Args:
6363
images: A tensor of shape
64-
(batch_size, height, width, channels)
65-
(NHWC), (batch_size, channels, height, width)(NCHW).
64+
`(batch_size, height, width, channels)`
65+
(NHWC), `(batch_size, channels, height, width)` (NCHW).
6666
mask_size: Specifies how big the zero mask that will be generated is that
6767
is applied to the images. The mask will be of size
68-
(mask_height x mask_width). Note: mask_size should be divisible by 2.
68+
`(mask_height x mask_width)`. Note: mask_size should be divisible by 2.
6969
constant_values: What pixel value to fill in the images in the area that has
7070
the cutout mask applied to it.
7171
seed: A Python integer. Used in combination with `tf.random.set_seed` to
@@ -76,9 +76,9 @@ def random_cutout(
7676
`(batch_size, ..., channels)` while `channels_first` corresponds to
7777
inputs with shape `(batch_size, channels, ...)`.
7878
Returns:
79-
An image Tensor.
79+
An image `Tensor`.
8080
Raises:
81-
InvalidArgumentError: if mask_size can't be divisible by 2.
81+
InvalidArgumentError: if `mask_size` can't be divisible by 2.
8282
"""
8383
if data_format == "channels_first":
8484
warnings.warn(
@@ -112,18 +112,19 @@ def cutout(
112112
) -> tf.Tensor:
113113
"""Apply cutout (https://arxiv.org/abs/1708.04552) to images.
114114
115-
This operation applies a (mask_height x mask_width) mask of zeros to
116-
a location within `img` specified by the offset. The pixel values filled in will be of the
117-
value `replace`. The located where the mask will be applied is randomly
115+
This operation applies a `(mask_height x mask_width)` mask of zeros to
116+
a location within `images` specified by the offset.
117+
The pixel values filled in will be of the value `replace`.
118+
The located where the mask will be applied is randomly
118119
chosen uniformly over the whole images.
119120
120121
Args:
121-
images: A tensor of shape (batch_size, height, width, channels)
122-
(NHWC), (batch_size, channels, height, width)(NCHW).
122+
images: A tensor of shape `(batch_size, height, width, channels)`
123+
(NHWC), `(batch_size, channels, height, width)` (NCHW).
123124
mask_size: Specifies how big the zero mask that will be generated is that
124125
is applied to the images. The mask will be of size
125-
(mask_height x mask_width). Note: mask_size should be divisible by 2.
126-
offset: A tuple of (height, width) or (batch_size, 2)
126+
`(mask_height x mask_width)`. Note: mask_size should be divisible by 2.
127+
offset: A tuple of `(height, width)` or `(batch_size, 2)`
127128
constant_values: What pixel value to fill in the images in the area that has
128129
the cutout mask applied to it.
129130
data_format: A string, one of `channels_last` (default) or `channels_first`.
@@ -134,7 +135,7 @@ def cutout(
134135
Returns:
135136
An image Tensor.
136137
Raises:
137-
InvalidArgumentError: if mask_size can't be divisible by 2.
138+
InvalidArgumentError: if `mask_size` can't be divisible by 2.
138139
"""
139140
if data_format == "channels_first":
140141
warnings.warn(

tensorflow_addons/image/dense_image_warp.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def dense_image_warp(
210210
`(b, j - flow[b, j, i, 0], i - flow[b, j, i, 1])`. For locations outside
211211
of the image, we use the nearest pixel values at the image boundary.
212212
213-
PLEASE NOTE: The definition of the flow field above is different from that
213+
NOTE: The definition of the flow field above is different from that
214214
of optical flow. This function expects the negative forward flow from
215215
output image to source image. Given two images `I_1` and `I_2` and the
216216
optical flow `F_12` from `I_1` to `I_2`, the image `I_1` can be
@@ -221,15 +221,15 @@ def dense_image_warp(
221221
flow: A 4-D float `Tensor` with shape `[batch, height, width, 2]`.
222222
name: A name for the operation (optional).
223223
224-
Note that image and flow can be of type tf.half, tf.float32, or
225-
tf.float64, and do not necessarily have to be the same type.
224+
Note that image and flow can be of type `tf.half`, `tf.float32`, or
225+
`tf.float64`, and do not necessarily have to be the same type.
226226
227227
Returns:
228228
A 4-D float `Tensor` with shape`[batch, height, width, channels]`
229229
and same type as input image.
230230
231231
Raises:
232-
ValueError: if height < 2 or width < 2 or the inputs have the wrong
232+
ValueError: if `height < 2` or `width < 2` or the inputs have the wrong
233233
number of dimensions.
234234
"""
235235
with tf.name_scope(name or "dense_image_warp"):

tensorflow_addons/image/distance_transform.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ def euclidean_dist_transform(
3434
"""Applies euclidean distance transform(s) to the image(s).
3535
3636
Args:
37-
images: A tensor of shape (num_images, num_rows, num_columns, 1) (NHWC),
38-
or (num_rows, num_columns, 1) (HWC) or (num_rows, num_columns) (HW).
39-
dtype: DType of the output tensor.
37+
images: A tensor of shape `(num_images, num_rows, num_columns, 1)`
38+
(NHWC), or `(num_rows, num_columns, 1)` (HWC) or
39+
`(num_rows, num_columns)` (HW).
40+
dtype: `tf.dtypes.DType` of the output tensor.
4041
name: The name of the op.
4142
4243
Returns:

tensorflow_addons/image/distort_image_ops.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ def random_hsv_in_yiq(
4343
4444
Args:
4545
image: RGB image or images. Size of the last dimension must be 3.
46-
max_delta_hue: float. Maximum value for the random delta_hue. Passing 0
46+
max_delta_hue: `float`. Maximum value for the random delta_hue. Passing 0
4747
disables adjusting hue.
48-
lower_saturation: float. Lower bound for the random scale_saturation.
49-
upper_saturation: float. Upper bound for the random scale_saturation.
50-
lower_value: float. Lower bound for the random scale_value.
51-
upper_value: float. Upper bound for the random scale_value.
48+
lower_saturation: `float`. Lower bound for the random scale_saturation.
49+
upper_saturation: `float`. Upper bound for the random scale_saturation.
50+
lower_value: `float`. Lower bound for the random scale_value.
51+
upper_value: `float`. Upper bound for the random scale_value.
5252
seed: An operation-specific seed. It will be used in conjunction
5353
with the graph-level seed to determine the real seeds that will be
5454
used in this operation. Please see the documentation of
5555
set_random_seed for its interaction with the graph-level random seed.
5656
name: A name for this operation (optional).
5757
5858
Returns:
59-
3-D float tensor of shape `[height, width, channels]`.
59+
3-D float `Tensor` of shape `[height, width, channels]`.
6060
6161
Raises:
6262
ValueError: if `max_delta`, `lower_saturation`, `upper_saturation`,
@@ -122,9 +122,9 @@ def adjust_hsv_in_yiq(
122122
123123
Args:
124124
image: RGB image or images. Size of the last dimension must be 3.
125-
delta_hue: float, the hue rotation amount, in radians.
126-
scale_saturation: float, factor to multiply the saturation by.
127-
scale_value: float, factor to multiply the value by.
125+
delta_hue: `float`, the hue rotation amount, in radians.
126+
scale_saturation: `float`, factor to multiply the saturation by.
127+
scale_value: `float`, factor to multiply the value by.
128128
name: A name for this operation (optional).
129129
130130
Returns:

tensorflow_addons/image/interpolate_spline.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
def _cross_squared_distance_matrix(x: TensorLike, y: TensorLike) -> tf.Tensor:
2424
"""Pairwise squared distance between two (batch) matrices' rows (2nd dim).
2525
26-
Computes the pairwise distances between rows of x and rows of y
26+
Computes the pairwise distances between rows of x and rows of y.
27+
2728
Args:
28-
x: [batch_size, n, d] float `Tensor`
29-
y: [batch_size, m, d] float `Tensor`
29+
x: `[batch_size, n, d]` float `Tensor`.
30+
y: `[batch_size, m, d]` float `Tensor`.
3031
3132
Returns:
32-
squared_dists: [batch_size, n, m] float `Tensor`, where
33-
squared_dists[b,i,j] = ||x[b,i,:] - y[b,j,:]||^2
33+
squared_dists: `[batch_size, n, m]` float `Tensor`, where
34+
`squared_dists[b,i,j] = ||x[b,i,:] - y[b,j,:]||^2`.
3435
"""
3536
x_norm_squared = tf.reduce_sum(tf.square(x), 2)
3637
y_norm_squared = tf.reduce_sum(tf.square(y), 2)
@@ -52,14 +53,14 @@ def _pairwise_squared_distance_matrix(x: TensorLike) -> tf.Tensor:
5253
"""Pairwise squared distance among a (batch) matrix's rows (2nd dim).
5354
5455
This saves a bit of computation vs. using
55-
_cross_squared_distance_matrix(x,x)
56+
`_cross_squared_distance_matrix(x, x)`
5657
5758
Args:
58-
x: `[batch_size, n, d]` float `Tensor`
59+
x: `[batch_size, n, d]` float `Tensor`.
5960
6061
Returns:
6162
squared_dists: `[batch_size, n, n]` float `Tensor`, where
62-
squared_dists[b,i,j] = ||x[b,i,:] - x[b,j,:]||^2
63+
`squared_dists[b,i,j] = ||x[b,i,:] - x[b,j,:]||^2`.
6364
"""
6465

6566
x_x_transpose = tf.matmul(x, x, adjoint_b=True)
@@ -83,17 +84,17 @@ def _solve_interpolation(
8384
order: int,
8485
regularization_weight: FloatTensorLike,
8586
) -> TensorLike:
86-
"""Solve for interpolation coefficients.
87+
r"""Solve for interpolation coefficients.
8788
8889
Computes the coefficients of the polyharmonic interpolant for the
89-
'training' data defined by (train_points, train_values) using the kernel
90-
phi.
90+
'training' data defined by `(train_points, train_values)` using the kernel
91+
$\phi$.
9192
9293
Args:
93-
train_points: `[b, n, d]` interpolation centers
94-
train_values: `[b, n, k]` function values
95-
order: order of the interpolation
96-
regularization_weight: weight to place on smoothness regularization term
94+
train_points: `[b, n, d]` interpolation centers.
95+
train_values: `[b, n, k]` function values.
96+
order: order of the interpolation.
97+
regularization_weight: weight to place on smoothness regularization term.
9798
9899
Returns:
99100
w: `[b, n, k]` weights on each interpolation center
@@ -173,15 +174,15 @@ def _apply_interpolation(
173174
interpolated function values at query_points.
174175
175176
Args:
176-
query_points: `[b, m, d]` x values to evaluate the interpolation at
177+
query_points: `[b, m, d]` x values to evaluate the interpolation at.
177178
train_points: `[b, n, d]` x values that act as the interpolation centers
178-
( the c variables in the wikipedia article)
179-
w: `[b, n, k]` weights on each interpolation center
180-
v: `[b, d, k]` weights on each input dimension
181-
order: order of the interpolation
179+
(the c variables in the wikipedia article).
180+
w: `[b, n, k]` weights on each interpolation center.
181+
v: `[b, d, k]` weights on each input dimension.
182+
order: order of the interpolation.
182183
183184
Returns:
184-
Polyharmonic interpolation evaluated at points defined in query_points.
185+
Polyharmonic interpolation evaluated at points defined in `query_points`.
185186
"""
186187

187188
# First, compute the contribution from the rbf term.
@@ -207,11 +208,11 @@ def _phi(r: FloatTensorLike, order: int) -> FloatTensorLike:
207208
See https://en.wikipedia.org/wiki/Polyharmonic_spline for the definition.
208209
209210
Args:
210-
r: input op
211-
order: interpolation order
211+
r: input op.
212+
order: interpolation order.
212213
213214
Returns:
214-
phi_k evaluated coordinate-wise on r, for k = r
215+
`phi_k` evaluated coordinate-wise on `r`, for `k = r`.
215216
"""
216217

217218
# using EPSILON prevents log(0), sqrt0), etc.

tensorflow_addons/image/resampler_ops.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def resampler(
3333
The resampler currently only supports bilinear interpolation of 2D data.
3434
3535
Args:
36-
data: Tensor of shape `[batch_size, data_height, data_width,
36+
data: `Tensor` of shape `[batch_size, data_height, data_width,
3737
data_num_channels]` containing 2D data that will be resampled.
3838
warp: Tensor of minimum rank 2 containing the coordinates at
3939
which resampling will be performed. Since only bilinear
4040
interpolation is currently supported, the last dimension of the
41-
`warp` tensor must be 2, representing the (x, y) coordinate where
42-
x is the index for width and y is the index for height.
41+
`warp` tensor must be 2, representing the `(x, y)` coordinate where
42+
`x` is the index for width and `y` is the index for height.
4343
name: Optional name of the op.
4444
Returns:
4545
Tensor of resampled values from `data`. The output tensor shape

0 commit comments

Comments
 (0)