Skip to content

Commit 7e0a756

Browse files
authored
Merge pull request #1485 from rstudio/retether-3-8-0
Retether Keras 3.8.0
2 parents 2c83041 + 89b5ccb commit 7e0a756

File tree

508 files changed

+11159
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

508 files changed

+11159
-438
lines changed

.tether/man/Layer.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class Layer(keras.src.backend.tensorflow.layer.TFLayer, keras.src.ops.operation.
244244
| autocast=True,
245245
| regularizer=None,
246246
| constraint=None,
247-
| aggregation='mean',
247+
| aggregation='none',
248248
| name=None
249249
| )
250250
| Add a weight variable to the layer.
@@ -271,10 +271,11 @@ class Layer(keras.src.backend.tensorflow.layer.TFLayer, keras.src.ops.operation.
271271
| constraint: Contrainst object to call on the variable after any
272272
| optimizer update, or string name of a built-in constraint.
273273
| Defaults to `None`.
274-
| aggregation: String, one of `'mean'`, `'sum'`,
275-
| `'only_first_replica'`. Annotates the variable with the type
276-
| of multi-replica aggregation to be used for this variable
277-
| when writing custom data parallel training loops.
274+
| aggregation: Optional string, one of `None`, `"none"`, `"mean"`,
275+
| `"sum"` or `"only_first_replica"`. Annotates the variable with
276+
| the type of multi-replica aggregation to be used for this
277+
| variable when writing custom data parallel training loops.
278+
| Defaults to `"none"`.
278279
| name: String name of the variable. Useful for debugging purposes.
279280
|
280281
| build(self, input_shape)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
__signature__
2+
keras.activations.sparse_plus(x)
3+
__doc__
4+
SparsePlus activation function.
5+
6+
SparsePlus is defined as:
7+
8+
`sparse_plus(x) = 0` for `x <= -1`.
9+
`sparse_plus(x) = (1/4) * (x + 1)^2` for `-1 < x < 1`.
10+
`sparse_plus(x) = x` for `x >= 1`.
11+
12+
Args:
13+
x: Input tensor.
14+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
__signature__
2+
keras.activations.sparsemax(x, axis=-1)
3+
__doc__
4+
Sparsemax activation function.
5+
6+
For each batch `i`, and class `j`,
7+
sparsemax activation function is defined as:
8+
9+
`sparsemax(x)[i, j] = max(x[i, j] - τ(x[i, :]), 0).`
10+
11+
Args:
12+
x: Input tensor.
13+
axis: `int`, axis along which the sparsemax operation is applied.
14+
15+
Returns:
16+
A tensor, output of sparsemax transformation. Has the same type and
17+
shape as `x`.
18+
19+
Reference:
20+
21+
- [Martins et.al., 2016](https://arxiv.org/abs/1602.02068)
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
__signature__
2+
keras.activations.threshold(
3+
x,
4+
threshold,
5+
default_value
6+
)
7+
__doc__
8+
Threshold activation function.
9+
10+
It is defined as:
11+
12+
`threshold(x) = x` if `x > threshold`,
13+
`threshold(x) = default_value` otherwise.
14+
15+
Args:
16+
x: Input tensor.
17+
threshold: The value that decides when to retain or replace x.
18+
default_value: Value to assign when `x <= threshold`.
19+

.tether/man/callback_backup_and_restore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BackupAndRestore(keras.src.callbacks.callback.Callback)
3333
| >>> callback = keras.callbacks.BackupAndRestore(backup_dir="/tmp/backup")
3434
| >>> model = keras.models.Sequential([keras.layers.Dense(10)])
3535
| >>> model.compile(keras.optimizers.SGD(), loss='mse')
36+
| >>> model.build(input_shape=(None, 20))
3637
| >>> try:
3738
| ... model.fit(np.arange(100).reshape(5, 20), np.zeros(5), epochs=10,
3839
| ... batch_size=1, callbacks=[callback, InterruptingCallback()],

.tether/man/callback_model_checkpoint.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ class ModelCheckpoint(keras.src.callbacks.callback.Callback)
6464
| which will be filled the value of `epoch` and keys in `logs`
6565
| (passed in `on_epoch_end`).
6666
| The `filepath` name needs to end with `".weights.h5"` when
67-
| `save_weights_only=True` or should end with `".keras"` when
68-
| checkpoint saving the whole model (default).
67+
| `save_weights_only=True` or should end with `".keras"` or `".h5"`
68+
| when checkpoint saving the whole model (default).
6969
| For example:
70-
| if `filepath` is `"{epoch:02d}-{val_loss:.2f}.keras"`, then the
71-
| model checkpoints will be saved with the epoch number and the
72-
| validation loss in the filename. The directory of the filepath
70+
| if `filepath` is `"{epoch:02d}-{val_loss:.2f}.keras"` or
71+
| "{epoch:02d}-{val_loss:.2f}.weights.h5"`, then the model
72+
| checkpoints will be saved with the epoch number and the validation
73+
| loss in the filename. The directory of the filepath
7374
| should not be reused by any other callbacks to avoid conflicts.
7475
| monitor: The metric name to monitor. Typically the metrics are set by
7576
| the `Model.compile` method. Note:
@@ -183,3 +184,4 @@ class ModelCheckpoint(keras.src.callbacks.callback.Callback)
183184
| batch: Integer, index of batch within the current epoch.
184185
| logs: Dict. Aggregated metric results up until this batch.
185186
|
187+

.tether/man/export_savedmodel.keras.src.models.model.Model.txt

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,65 @@ keras.Model.export(
33
self,
44
filepath,
55
format='tf_saved_model',
6-
verbose=True
6+
verbose=True,
7+
input_signature=None,
8+
**kwargs
79
)
810
__doc__
9-
Create a TF SavedModel artifact for inference.
11+
Export the model as an artifact for inference.
1012

11-
**Note:** This can currently only be used with
12-
the TensorFlow or JAX backends.
13-
14-
This method lets you export a model to a lightweight SavedModel artifact
15-
that contains the model's forward pass only (its `call()` method)
16-
and can be served via e.g. TF-Serving. The forward pass is registered
17-
under the name `serve()` (see example below).
13+
Args:
14+
filepath: `str` or `pathlib.Path` object. The path to save the
15+
artifact.
16+
format: `str`. The export format. Supported values:
17+
`"tf_saved_model"` and `"onnx"`. Defaults to
18+
`"tf_saved_model"`.
19+
verbose: `bool`. Whether to print a message during export. Defaults
20+
to `True`.
21+
input_signature: Optional. Specifies the shape and dtype of the
22+
model inputs. Can be a structure of `keras.InputSpec`,
23+
`tf.TensorSpec`, `backend.KerasTensor`, or backend tensor. If
24+
not provided, it will be automatically computed. Defaults to
25+
`None`.
26+
**kwargs: Additional keyword arguments:
27+
- Specific to the JAX backend and `format="tf_saved_model"`:
28+
- `is_static`: Optional `bool`. Indicates whether `fn` is
29+
static. Set to `False` if `fn` involves state updates
30+
(e.g., RNG seeds and counters).
31+
- `jax2tf_kwargs`: Optional `dict`. Arguments for
32+
`jax2tf.convert`. See the documentation for
33+
[`jax2tf.convert`](
34+
https://github.com/google/jax/blob/main/jax/experimental/jax2tf/README.md).
35+
If `native_serialization` and `polymorphic_shapes` are
36+
not provided, they will be automatically computed.
1837

19-
The original code of the model (including any custom layers you may
20-
have used) is *no longer* necessary to reload the artifact -- it is
21-
entirely standalone.
38+
**Note:** This feature is currently supported only with TensorFlow, JAX
39+
and Torch backends.
2240

23-
Args:
24-
filepath: `str` or `pathlib.Path` object. Path where to save
25-
the artifact.
26-
verbose: whether to print all the variables of the exported model.
41+
Examples:
2742

28-
Example:
43+
Here's how to export a TensorFlow SavedModel for inference.
2944

3045
```python
31-
# Create the artifact
32-
model.export("path/to/location")
46+
# Export the model as a TensorFlow SavedModel artifact
47+
model.export("path/to/location", format="tf_saved_model")
3348

34-
# Later, in a different process/environment...
49+
# Load the artifact in a different process/environment
3550
reloaded_artifact = tf.saved_model.load("path/to/location")
3651
predictions = reloaded_artifact.serve(input_data)
3752
```
3853

39-
If you would like to customize your serving endpoints, you can
40-
use the lower-level `keras.export.ExportArchive` class. The
41-
`export()` method relies on `ExportArchive` internally.
54+
Here's how to export an ONNX for inference.
55+
56+
```python
57+
# Export the model as a ONNX artifact
58+
model.export("path/to/location", format="onnx")
59+
60+
# Load the artifact in a different process/environment
61+
ort_session = onnxruntime.InferenceSession("path/to/location")
62+
ort_inputs = {
63+
k.name: v for k, v in zip(ort_session.get_inputs(), input_data)
64+
}
65+
predictions = ort_session.run(None, ort_inputs)
66+
```
4267

.tether/man/keras.activations.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ soft_shrink(x, threshold=0.5)
3030
softmax(x, axis=-1)
3131
softplus(x)
3232
softsign(x)
33+
sparse_plus(x)
34+
sparsemax(x, axis=-1)
3335
squareplus(x, b=4)
3436
swish(x)
3537
tanh(x)
3638
tanh_shrink(x)
39+
threshold(
40+
x,
41+
threshold,
42+
default_value
43+
)
3744

.tether/man/keras.layers.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ Embedding(
542542
lora_rank=None,
543543
**kwargs
544544
)
545+
Equalization(
546+
value_range=(0, 255),
547+
bins=256,
548+
data_format=None,
549+
**kwargs
550+
)
545551
Flatten(data_format=None, **kwargs)
546552
FlaxLayer(
547553
module,
@@ -913,6 +919,12 @@ MelSpectrogram(
913919
)
914920
minimum(inputs, **kwargs)
915921
Minimum(**kwargs)
922+
MixUp(
923+
alpha=0.2,
924+
data_format=None,
925+
seed=None,
926+
**kwargs
927+
)
916928
MultiHeadAttention(
917929
num_heads,
918930
key_dim,
@@ -950,14 +962,41 @@ PReLU(
950962
shared_axes=None,
951963
**kwargs
952964
)
965+
RandAugment(
966+
value_range=(0, 255),
967+
num_ops=2,
968+
factor=0.5,
969+
interpolation='bilinear',
970+
seed=None,
971+
data_format=None,
972+
**kwargs
973+
)
953974
RandomBrightness(
954975
factor,
955976
value_range=(0, 255),
956977
seed=None,
957978
**kwargs
958979
)
980+
RandomColorDegeneration(
981+
factor,
982+
value_range=(0, 255),
983+
data_format=None,
984+
seed=None,
985+
**kwargs
986+
)
987+
RandomColorJitter(
988+
value_range=(0, 255),
989+
brightness_factor=None,
990+
contrast_factor=None,
991+
saturation_factor=None,
992+
hue_factor=None,
993+
seed=None,
994+
data_format=None,
995+
**kwargs
996+
)
959997
RandomContrast(
960998
factor,
999+
value_range=(0, 255),
9611000
seed=None,
9621001
**kwargs
9631002
)
@@ -975,6 +1014,26 @@ RandomFlip(
9751014
data_format=None,
9761015
**kwargs
9771016
)
1017+
RandomGrayscale(
1018+
factor=0.5,
1019+
data_format=None,
1020+
seed=None,
1021+
**kwargs
1022+
)
1023+
RandomHue(
1024+
factor,
1025+
value_range=(0, 255),
1026+
data_format=None,
1027+
seed=None,
1028+
**kwargs
1029+
)
1030+
RandomPosterization(
1031+
factor,
1032+
value_range=(0, 255),
1033+
data_format=None,
1034+
seed=None,
1035+
**kwargs
1036+
)
9781037
RandomRotation(
9791038
factor,
9801039
fill_mode='reflect',
@@ -984,6 +1043,30 @@ RandomRotation(
9841043
data_format=None,
9851044
**kwargs
9861045
)
1046+
RandomSaturation(
1047+
factor,
1048+
value_range=(0, 255),
1049+
data_format=None,
1050+
seed=None,
1051+
**kwargs
1052+
)
1053+
RandomSharpness(
1054+
factor,
1055+
value_range=(0, 255),
1056+
data_format=None,
1057+
seed=None,
1058+
**kwargs
1059+
)
1060+
RandomShear(
1061+
x_factor=0.0,
1062+
y_factor=0.0,
1063+
interpolation='bilinear',
1064+
fill_mode='reflect',
1065+
fill_value=0.0,
1066+
data_format=None,
1067+
seed=None,
1068+
**kwargs
1069+
)
9871070
RandomTranslation(
9881071
height_factor,
9891072
width_factor,

.tether/man/keras.losses.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,15 @@ tversky(
210210
y_true,
211211
y_pred,
212212
alpha=0.5,
213-
beta=0.5
213+
beta=0.5,
214+
axis=None
214215
)
215216
Tversky(
216217
alpha=0.5,
217218
beta=0.5,
218219
reduction='sum_over_batch_size',
219220
name='tversky',
221+
axis=None,
220222
dtype=None
221223
)
222224

0 commit comments

Comments
 (0)