Skip to content

Commit e8c4030

Browse files
SamuelMarkstensorflower-gardener
authored andcommitted
PR #17953: [keras/utils] Standardise docstring usage of "Default to"
Imported from GitHub PR #17953 This is one of many PRs. Discussion + request to split into multiple PRs @ #17748 Copybara import of the project: -- 6893bd5 by Samuel Marks <[email protected]>: [keras/utils/audio_dataset.py,keras/utils/conv_utils.py,keras/utils/data_utils.py,keras/utils/dataset_utils.py,keras/utils/feature_space.py,keras/utils/generic_utils.py,keras/utils/image_dataset.py,keras/utils/image_utils.py,keras/utils/layer_utils.py,keras/utils/losses_utils.py,keras/utils/metrics_utils.py,keras/utils/text_dataset.py] Standardise docstring usage of "Default to" Merging this change closes #17953 FUTURE_COPYBARA_INTEGRATE_REVIEW=#17953 from SamuelMarks:keras.utils-defaults-to 4cbcdf8 PiperOrigin-RevId: 535277920
1 parent b4d71f1 commit e8c4030

File tree

8 files changed

+40
-37
lines changed

8 files changed

+40
-37
lines changed

keras/utils/conv_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def normalize_tuple(value, n, name, allow_zero=False):
6363
n: The size of the tuple to be returned.
6464
name: The name of the argument being validated, e.g. "strides" or
6565
"kernel_size". This is only used to format error messages.
66-
allow_zero: Default to False. A ValueError will raised if zero is received
67-
and this param is False.
66+
allow_zero: A ValueError will be raised if zero is received
67+
and this param is False. Defaults to `False`.
6868
6969
Returns:
7070
A tuple of n integers.

keras/utils/data_utils.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def get_file(
247247
The default `'auto'` corresponds to `['tar', 'zip']`.
248248
None or an empty list will return no matches found.
249249
cache_dir: Location to store cached files, when None it
250-
defaults to the default directory `~/.keras/`.
250+
defaults to `~/.keras/`.
251251
252252
Returns:
253253
Path to the downloaded file.
@@ -1063,14 +1063,16 @@ def pad_sequences(
10631063
maxlen: Optional Int, maximum length of all sequences. If not provided,
10641064
sequences will be padded to the length of the longest individual
10651065
sequence.
1066-
dtype: (Optional, defaults to `"int32"`). Type of the output sequences.
1066+
dtype: (Optional). Type of the output sequences.
10671067
To pad sequences with variable length strings, you can use `object`.
1068-
padding: String, "pre" or "post" (optional, defaults to `"pre"`):
1069-
pad either before or after each sequence.
1070-
truncating: String, "pre" or "post" (optional, defaults to `"pre"`):
1068+
Defaults to `"int32"`.
1069+
padding: String, "pre" or "post" (optional):
1070+
pad either before or after each sequence. Defaults to `"pre"`.
1071+
truncating: String, "pre" or "post" (optional):
10711072
remove values from sequences larger than
10721073
`maxlen`, either at the beginning or at the end of the sequences.
1073-
value: Float or String, padding value. (Optional, defaults to 0.)
1074+
Defaults to `"pre"`.
1075+
value: Float or String, padding value. (Optional). Defaults to `0.`.
10741076
10751077
Returns:
10761078
Numpy array with shape `(len(sequences), maxlen)`

keras/utils/generic_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def update(self, current, values=None, finalize=None):
187187
as-is. Else, an average of the metric over time will be
188188
displayed.
189189
finalize: Whether this is the last update for the progress bar. If
190-
`None`, defaults to `current >= self.target`.
190+
`None`, uses `current >= self.target`. Defaults to `None`.
191191
"""
192192
if finalize is None:
193193
if self.target is None:

keras/utils/image_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ def image_dataset_from_directory(
100100
color_mode: One of `"grayscale"`, `"rgb"`, `"rgba"`.
101101
Defaults to `"rgb"`. Whether the images will be converted to
102102
have 1, 3, or 4 channels.
103-
batch_size: Size of the batches of data. Defaults to 32.
103+
batch_size: Size of the batches of data.
104104
If `None`, the data will not be batched
105-
(the dataset will yield individual samples).
105+
(the dataset will yield individual samples). Defaults to 32.
106106
image_size: Size to resize images to after they are read from disk,
107-
specified as `(height, width)`. Defaults to `(256, 256)`.
107+
specified as `(height, width)`.
108108
Since the pipeline processes batches of images that must all have
109-
the same size, this must be provided.
109+
the same size, this must be provided. Defaults to `(256, 256)`.
110110
shuffle: Whether to shuffle the data. Defaults to `True`.
111111
If set to `False`, sorts the data in alphanumeric order.
112112
seed: Optional random seed for shuffling and transformations.

keras/utils/image_utils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def smart_resize(x, size, interpolation="bilinear"):
120120
format `(height, width, channels)` or `(batch_size, height, width,
121121
channels)`.
122122
size: Tuple of `(height, width)` integer. Target size.
123-
interpolation: String, interpolation to use for resizing. Defaults to
124-
`'bilinear'`. Supports `bilinear`, `nearest`, `bicubic`, `area`,
125-
`lanczos3`, `lanczos5`, `gaussian`, `mitchellcubic`.
123+
interpolation: String, interpolation to use for resizing. Supports
124+
`bilinear`, `nearest`, `bicubic`, `area`, `lanczos3`, `lanczos5`,
125+
`gaussian`, `mitchellcubic`. Defaults to `'bilinear'`.
126126
127127
Returns:
128128
Array with shape `(size[0], size[1], channels)`. If the input image was a
@@ -216,14 +216,14 @@ def array_to_img(x, data_format=None, scale=True, dtype=None):
216216
Args:
217217
x: Input data, in any form that can be converted to a Numpy array.
218218
data_format: Image data format, can be either `"channels_first"` or
219-
`"channels_last"`. Defaults to `None`, in which case the global
219+
`"channels_last"`. None means the global
220220
setting `tf.keras.backend.image_data_format()` is used (unless you
221-
changed it, it defaults to `"channels_last"`).
221+
changed it, it uses `"channels_last"`). Defaults to `None`.
222222
scale: Whether to rescale the image such that minimum and maximum values
223223
are 0 and 255 respectively. Defaults to `True`.
224-
dtype: Dtype to use. Default to `None`, in which case the global setting
225-
`tf.keras.backend.floatx()` is used (unless you changed it, it
226-
defaults to `"float32"`)
224+
dtype: Dtype to use. None makes the global setting
225+
`tf.keras.backend.floatx()` to be used (unless you changed it, it
226+
uses `"float32"`). Defaults to `None`.
227227
228228
Returns:
229229
A PIL Image instance.
@@ -298,12 +298,12 @@ def img_to_array(img, data_format=None, dtype=None):
298298
Args:
299299
img: Input PIL Image instance.
300300
data_format: Image data format, can be either `"channels_first"` or
301-
`"channels_last"`. Defaults to `None`, in which case the global
301+
`"channels_last"`. None means the global
302302
setting `tf.keras.backend.image_data_format()` is used (unless you
303-
changed it, it defaults to `"channels_last"`).
304-
dtype: Dtype to use. Default to `None`, in which case the global setting
305-
`tf.keras.backend.floatx()` is used (unless you changed it, it
306-
defaults to `"float32"`).
303+
changed it, it uses `"channels_last"`). Defaults to `None`.
304+
dtype: Dtype to use. None makes the global setting
305+
`tf.keras.backend.floatx()` to be used (unless you changed it, it
306+
uses `"float32"`). Defaults to `None`.
307307
308308
Returns:
309309
A 3D Numpy array.

keras/utils/layer_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,12 @@ def print_summary(
335335
It will be called on each line of the summary.
336336
You can set it to a custom function
337337
in order to capture the string summary.
338-
It defaults to `print` (prints to stdout).
338+
When `None`, uses `print` (prints to stdout).
339+
Defaults to `None`.
339340
expand_nested: Whether to expand the nested models.
340-
If not provided, defaults to `False`.
341+
Defaults to `False`.
341342
show_trainable: Whether to show if a layer is trainable.
342-
If not provided, defaults to `False`.
343+
Defaults to `False`.
343344
layer_range: List or tuple containing two strings,
344345
the starting layer name and ending layer name (both inclusive),
345346
indicating the range of layers to be printed in the summary. The
@@ -1042,9 +1043,9 @@ def warmstart_embedding_matrix(
10421043
embedding matrix.
10431044
new_embeddings_initializer: Initializer for embedding vectors for
10441045
previously unseen terms to be added to the new embedding matrix (see
1045-
`keras.initializers`). Defaults to "uniform". new_embedding matrix
1046+
`keras.initializers`). new_embedding matrix
10461047
needs to be specified with "constant" initializer.
1047-
matrix. Default value is None.
1048+
matrix. None means "uniform". Default value is None.
10481049
10491050
Returns:
10501051
tf.tensor of remapped embedding layer matrix

keras/utils/losses_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class ReductionV2:
3232
Contains the following values:
3333
3434
* `AUTO`: Indicates that the reduction option will be determined by the
35-
usage context. For almost all cases this defaults to
36-
`SUM_OVER_BATCH_SIZE`. When used with `tf.distribute.Strategy`, outside of
37-
built-in training loops such as `tf.keras` `compile` and `fit`, we expect
38-
reduction value to be `SUM` or `NONE`. Using `AUTO` in that case will
39-
raise an error.
35+
usage context. For almost all cases this uses `SUM_OVER_BATCH_SIZE`.
36+
When used with `tf.distribute.Strategy`, outside of built-in training
37+
loops such as `tf.keras` `compile` and `fit`, we expect reduction
38+
value to be `SUM` or `NONE`. Using `AUTO` in that case will raise an
39+
error.
4040
* `NONE`: No **additional** reduction is applied to the output of the
4141
wrapped loss function. When non-scalar losses are returned to Keras
4242
functions like `fit`/`evaluate`, the unreduced vector loss is passed to

keras/utils/metrics_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def sparse_top_k_categorical_matches(y_true, y_pred, k=5):
979979
y_true: tensor of true targets.
980980
y_pred: tensor of predicted targets.
981981
k: (Optional) Number of top elements to look at for computing accuracy.
982-
Defaults to 5.
982+
Defaults to `5`.
983983
984984
Returns:
985985
Match tensor: 1.0 for label-prediction match, 0.0 for mismatch.

0 commit comments

Comments
 (0)