keras-nightly 3.14.0.dev2026012204__py3-none-any.whl → 3.14.0.dev2026012404__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- keras/_tf_keras/keras/ops/__init__.py +2 -0
- keras/_tf_keras/keras/ops/numpy/__init__.py +2 -0
- keras/ops/__init__.py +2 -0
- keras/ops/numpy/__init__.py +2 -0
- keras/src/backend/jax/numpy.py +10 -0
- keras/src/backend/numpy/numpy.py +8 -0
- keras/src/backend/openvino/numpy.py +41 -2
- keras/src/backend/tensorflow/numpy.py +40 -0
- keras/src/backend/torch/core.py +4 -1
- keras/src/backend/torch/nn.py +7 -4
- keras/src/backend/torch/numpy.py +36 -0
- keras/src/layers/layer.py +10 -1
- keras/src/layers/preprocessing/image_preprocessing/aug_mix.py +13 -0
- keras/src/layers/preprocessing/image_preprocessing/base_image_preprocessing_layer.py +58 -0
- keras/src/layers/preprocessing/image_preprocessing/cut_mix.py +13 -0
- keras/src/layers/preprocessing/image_preprocessing/max_num_bounding_box.py +23 -0
- keras/src/layers/preprocessing/image_preprocessing/rand_augment.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_color_degeneration.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_color_jitter.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_contrast.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_crop.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_elastic_transform.py +14 -0
- keras/src/layers/preprocessing/image_preprocessing/random_erasing.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_flip.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_gaussian_blur.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_grayscale.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_invert.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_perspective.py +14 -0
- keras/src/layers/preprocessing/image_preprocessing/random_posterization.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_rotation.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_sharpness.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_shear.py +15 -0
- keras/src/layers/preprocessing/image_preprocessing/random_translation.py +15 -0
- keras/src/layers/rnn/time_distributed.py +36 -28
- keras/src/ops/core.py +1 -1
- keras/src/ops/numpy.py +113 -0
- keras/src/regularizers/regularizers.py +2 -2
- keras/src/version.py +1 -1
- {keras_nightly-3.14.0.dev2026012204.dist-info → keras_nightly-3.14.0.dev2026012404.dist-info}/METADATA +1 -1
- {keras_nightly-3.14.0.dev2026012204.dist-info → keras_nightly-3.14.0.dev2026012404.dist-info}/RECORD +42 -42
- {keras_nightly-3.14.0.dev2026012204.dist-info → keras_nightly-3.14.0.dev2026012404.dist-info}/WHEEL +0 -0
- {keras_nightly-3.14.0.dev2026012204.dist-info → keras_nightly-3.14.0.dev2026012404.dist-info}/top_level.txt +0 -0
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_color_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.random import SeedGenerator
|
|
6
9
|
|
|
7
10
|
|
|
@@ -41,6 +44,10 @@ class RandomErasing(BaseImagePreprocessingLayer):
|
|
|
41
44
|
typically either `[0, 1]` or `[0, 255]` depending on how your
|
|
42
45
|
preprocessing pipeline is set up.
|
|
43
46
|
seed: Integer. Used to create a random seed.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
|
|
50
|
+
{{base_image_preprocessing_color_example}}
|
|
44
51
|
"""
|
|
45
52
|
|
|
46
53
|
_USE_BASE_FACTOR = False
|
|
@@ -326,3 +333,11 @@ class RandomErasing(BaseImagePreprocessingLayer):
|
|
|
326
333
|
}
|
|
327
334
|
base_config = super().get_config()
|
|
328
335
|
return {**base_config, **config}
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
RandomErasing.__doc__ = RandomErasing.__doc__.replace(
|
|
339
|
+
"{{base_image_preprocessing_color_example}}",
|
|
340
|
+
base_image_preprocessing_color_example.replace(
|
|
341
|
+
"{LayerName}", "RandomErasing"
|
|
342
|
+
),
|
|
343
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_transform_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import ( # noqa: E501
|
|
6
9
|
clip_to_image_size,
|
|
7
10
|
)
|
|
@@ -46,6 +49,10 @@ class RandomFlip(BaseImagePreprocessingLayer):
|
|
|
46
49
|
seed: Integer. Used to create a random seed.
|
|
47
50
|
**kwargs: Base layer keyword arguments, such as
|
|
48
51
|
`name` and `dtype`.
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
|
|
55
|
+
{{base_image_preprocessing_transform_example}}
|
|
49
56
|
"""
|
|
50
57
|
|
|
51
58
|
_USE_BASE_FACTOR = False
|
|
@@ -234,3 +241,11 @@ class RandomFlip(BaseImagePreprocessingLayer):
|
|
|
234
241
|
}
|
|
235
242
|
)
|
|
236
243
|
return config
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
RandomFlip.__doc__ = RandomFlip.__doc__.replace(
|
|
247
|
+
"{{base_image_preprocessing_transform_example}}",
|
|
248
|
+
base_image_preprocessing_transform_example.replace(
|
|
249
|
+
"{LayerName}", "RandomFlip"
|
|
250
|
+
),
|
|
251
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_color_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.random import SeedGenerator
|
|
6
9
|
|
|
7
10
|
|
|
@@ -35,6 +38,10 @@ class RandomGaussianBlur(BaseImagePreprocessingLayer):
|
|
|
35
38
|
typically either `[0, 1]` or `[0, 255]` depending on how your
|
|
36
39
|
preprocessing pipeline is set up.
|
|
37
40
|
seed: Integer. Used to create a random seed.
|
|
41
|
+
|
|
42
|
+
Example:
|
|
43
|
+
|
|
44
|
+
{{base_image_preprocessing_color_example}}
|
|
38
45
|
"""
|
|
39
46
|
|
|
40
47
|
_USE_BASE_FACTOR = False
|
|
@@ -218,3 +225,11 @@ class RandomGaussianBlur(BaseImagePreprocessingLayer):
|
|
|
218
225
|
}
|
|
219
226
|
)
|
|
220
227
|
return config
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
RandomGaussianBlur.__doc__ = RandomGaussianBlur.__doc__.replace(
|
|
231
|
+
"{{base_image_preprocessing_color_example}}",
|
|
232
|
+
base_image_preprocessing_color_example.replace(
|
|
233
|
+
"{LayerName}", "RandomGaussianBlur"
|
|
234
|
+
),
|
|
235
|
+
)
|
|
@@ -3,6 +3,9 @@ from keras.src.api_export import keras_export
|
|
|
3
3
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
4
4
|
BaseImagePreprocessingLayer,
|
|
5
5
|
)
|
|
6
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
7
|
+
base_image_preprocessing_color_example,
|
|
8
|
+
)
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
@keras_export("keras.layers.RandomGrayscale")
|
|
@@ -43,6 +46,10 @@ class RandomGrayscale(BaseImagePreprocessingLayer):
|
|
|
43
46
|
Same as input shape. The output maintains the same number of channels
|
|
44
47
|
as the input, even for grayscale-converted images where all channels
|
|
45
48
|
will have the same value.
|
|
49
|
+
|
|
50
|
+
Example:
|
|
51
|
+
|
|
52
|
+
{{base_image_preprocessing_color_example}}
|
|
46
53
|
"""
|
|
47
54
|
|
|
48
55
|
def __init__(self, factor=0.5, data_format=None, seed=None, **kwargs):
|
|
@@ -115,3 +122,11 @@ class RandomGrayscale(BaseImagePreprocessingLayer):
|
|
|
115
122
|
config = super().get_config()
|
|
116
123
|
config.update({"factor": self.factor})
|
|
117
124
|
return config
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
RandomGrayscale.__doc__ = RandomGrayscale.__doc__.replace(
|
|
128
|
+
"{{base_image_preprocessing_color_example}}",
|
|
129
|
+
base_image_preprocessing_color_example.replace(
|
|
130
|
+
"{LayerName}", "RandomGrayscale"
|
|
131
|
+
),
|
|
132
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_color_example,
|
|
7
|
+
)
|
|
5
8
|
|
|
6
9
|
|
|
7
10
|
@keras_export("keras.layers.RandomInvert")
|
|
@@ -30,6 +33,10 @@ class RandomInvert(BaseImagePreprocessingLayer):
|
|
|
30
33
|
represents the upper bound. Images passed to the layer should have
|
|
31
34
|
values within `value_range`. Defaults to `(0, 255)`.
|
|
32
35
|
seed: Integer. Used to create a random seed.
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
|
|
39
|
+
{{base_image_preprocessing_color_example}}
|
|
33
40
|
"""
|
|
34
41
|
|
|
35
42
|
_USE_BASE_FACTOR = False
|
|
@@ -127,3 +134,11 @@ class RandomInvert(BaseImagePreprocessingLayer):
|
|
|
127
134
|
}
|
|
128
135
|
base_config = super().get_config()
|
|
129
136
|
return {**base_config, **config}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
RandomInvert.__doc__ = RandomInvert.__doc__.replace(
|
|
140
|
+
"{{base_image_preprocessing_color_example}}",
|
|
141
|
+
base_image_preprocessing_color_example.replace(
|
|
142
|
+
"{LayerName}", "RandomInvert"
|
|
143
|
+
),
|
|
144
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_transform_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import ( # noqa: E501
|
|
6
9
|
clip_to_image_size,
|
|
7
10
|
)
|
|
@@ -43,6 +46,9 @@ class RandomPerspective(BaseImagePreprocessingLayer):
|
|
|
43
46
|
boundaries when `fill_mode="constant"`.
|
|
44
47
|
seed: Integer. Used to create a random seed.
|
|
45
48
|
|
|
49
|
+
Example:
|
|
50
|
+
|
|
51
|
+
{{base_image_preprocessing_transform_example}}
|
|
46
52
|
"""
|
|
47
53
|
|
|
48
54
|
_USE_BASE_FACTOR = False
|
|
@@ -337,3 +343,11 @@ class RandomPerspective(BaseImagePreprocessingLayer):
|
|
|
337
343
|
"seed": self.seed,
|
|
338
344
|
}
|
|
339
345
|
return {**base_config, **config}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
RandomPerspective.__doc__ = RandomPerspective.__doc__.replace(
|
|
349
|
+
"{{base_image_preprocessing_transform_example}}",
|
|
350
|
+
base_image_preprocessing_transform_example.replace(
|
|
351
|
+
"{LayerName}", "RandomPerspective"
|
|
352
|
+
),
|
|
353
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_color_example,
|
|
7
|
+
)
|
|
5
8
|
|
|
6
9
|
|
|
7
10
|
@keras_export("keras.layers.RandomPosterization")
|
|
@@ -22,6 +25,10 @@ class RandomPosterization(BaseImagePreprocessingLayer):
|
|
|
22
25
|
values within `value_range`. Defaults to `(0, 255)`.
|
|
23
26
|
factor: integer, the number of bits to keep for each channel. Must be a
|
|
24
27
|
value between 1-8.
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
|
|
31
|
+
{{base_image_preprocessing_color_example}}
|
|
25
32
|
"""
|
|
26
33
|
|
|
27
34
|
_USE_BASE_FACTOR = False
|
|
@@ -152,3 +159,11 @@ class RandomPosterization(BaseImagePreprocessingLayer):
|
|
|
152
159
|
|
|
153
160
|
def compute_output_shape(self, input_shape):
|
|
154
161
|
return input_shape
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
RandomPosterization.__doc__ = RandomPosterization.__doc__.replace(
|
|
165
|
+
"{{base_image_preprocessing_color_example}}",
|
|
166
|
+
base_image_preprocessing_color_example.replace(
|
|
167
|
+
"{LayerName}", "RandomPosterization"
|
|
168
|
+
),
|
|
169
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_transform_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes import (
|
|
6
9
|
converters,
|
|
7
10
|
)
|
|
@@ -75,6 +78,10 @@ class RandomRotation(BaseImagePreprocessingLayer):
|
|
|
75
78
|
`image_data_format` value found in your Keras config file at
|
|
76
79
|
`~/.keras/keras.json`. If you never set it, then it will be
|
|
77
80
|
`"channels_last"`.
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
|
|
84
|
+
{{base_image_preprocessing_transform_example}}
|
|
78
85
|
"""
|
|
79
86
|
|
|
80
87
|
_SUPPORTED_FILL_MODE = ("reflect", "wrap", "constant", "nearest")
|
|
@@ -247,3 +254,11 @@ class RandomRotation(BaseImagePreprocessingLayer):
|
|
|
247
254
|
}
|
|
248
255
|
base_config = super().get_config()
|
|
249
256
|
return {**base_config, **config}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
RandomRotation.__doc__ = RandomRotation.__doc__.replace(
|
|
260
|
+
"{{base_image_preprocessing_transform_example}}",
|
|
261
|
+
base_image_preprocessing_transform_example.replace(
|
|
262
|
+
"{LayerName}", "RandomRotation"
|
|
263
|
+
),
|
|
264
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_color_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.random import SeedGenerator
|
|
6
9
|
|
|
7
10
|
|
|
@@ -32,6 +35,10 @@ class RandomSharpness(BaseImagePreprocessingLayer):
|
|
|
32
35
|
typically either `[0, 1]` or `[0, 255]` depending on how your
|
|
33
36
|
preprocessing pipeline is set up.
|
|
34
37
|
seed: Integer. Used to create a random seed.
|
|
38
|
+
|
|
39
|
+
Example:
|
|
40
|
+
|
|
41
|
+
{{base_image_preprocessing_color_example}}
|
|
35
42
|
"""
|
|
36
43
|
|
|
37
44
|
_USE_BASE_FACTOR = False
|
|
@@ -169,3 +176,11 @@ class RandomSharpness(BaseImagePreprocessingLayer):
|
|
|
169
176
|
|
|
170
177
|
def compute_output_shape(self, input_shape):
|
|
171
178
|
return input_shape
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
RandomSharpness.__doc__ = RandomSharpness.__doc__.replace(
|
|
182
|
+
"{{base_image_preprocessing_color_example}}",
|
|
183
|
+
base_image_preprocessing_color_example.replace(
|
|
184
|
+
"{LayerName}", "RandomSharpness"
|
|
185
|
+
),
|
|
186
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_transform_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import ( # noqa: E501
|
|
6
9
|
clip_to_image_size,
|
|
7
10
|
)
|
|
@@ -61,6 +64,10 @@ class RandomShear(BaseImagePreprocessingLayer):
|
|
|
61
64
|
fill_value: A float representing the value to be filled outside the
|
|
62
65
|
boundaries when `fill_mode="constant"`.
|
|
63
66
|
seed: Integer. Used to create a random seed.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
|
|
70
|
+
{{base_image_preprocessing_transform_example}}
|
|
64
71
|
"""
|
|
65
72
|
|
|
66
73
|
_USE_BASE_FACTOR = False
|
|
@@ -402,3 +409,11 @@ class RandomShear(BaseImagePreprocessingLayer):
|
|
|
402
409
|
|
|
403
410
|
def compute_output_shape(self, input_shape):
|
|
404
411
|
return input_shape
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
RandomShear.__doc__ = RandomShear.__doc__.replace(
|
|
415
|
+
"{{base_image_preprocessing_transform_example}}",
|
|
416
|
+
base_image_preprocessing_transform_example.replace(
|
|
417
|
+
"{LayerName}", "RandomShear"
|
|
418
|
+
),
|
|
419
|
+
)
|
|
@@ -2,6 +2,9 @@ from keras.src.api_export import keras_export
|
|
|
2
2
|
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
3
3
|
BaseImagePreprocessingLayer,
|
|
4
4
|
)
|
|
5
|
+
from keras.src.layers.preprocessing.image_preprocessing.base_image_preprocessing_layer import ( # noqa: E501
|
|
6
|
+
base_image_preprocessing_transform_example,
|
|
7
|
+
)
|
|
5
8
|
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import ( # noqa: E501
|
|
6
9
|
clip_to_image_size,
|
|
7
10
|
)
|
|
@@ -87,6 +90,10 @@ class RandomTranslation(BaseImagePreprocessingLayer):
|
|
|
87
90
|
`~/.keras/keras.json`. If you never set it, then it will be
|
|
88
91
|
`"channels_last"`.
|
|
89
92
|
**kwargs: Base layer keyword arguments, such as `name` and `dtype`.
|
|
93
|
+
|
|
94
|
+
Example:
|
|
95
|
+
|
|
96
|
+
{{base_image_preprocessing_transform_example}}
|
|
90
97
|
"""
|
|
91
98
|
|
|
92
99
|
_USE_BASE_FACTOR = False
|
|
@@ -382,3 +389,11 @@ class RandomTranslation(BaseImagePreprocessingLayer):
|
|
|
382
389
|
"data_format": self.data_format,
|
|
383
390
|
}
|
|
384
391
|
return {**base_config, **config}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
RandomTranslation.__doc__ = RandomTranslation.__doc__.replace(
|
|
395
|
+
"{{base_image_preprocessing_transform_example}}",
|
|
396
|
+
base_image_preprocessing_transform_example.replace(
|
|
397
|
+
"{LayerName}", "RandomTranslation"
|
|
398
|
+
),
|
|
399
|
+
)
|
|
@@ -71,37 +71,43 @@ class TimeDistributed(Wrapper):
|
|
|
71
71
|
super().build(child_input_shape)
|
|
72
72
|
|
|
73
73
|
def call(self, inputs, training=None, mask=None):
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# not a constant.
|
|
82
|
-
if backend.backend() == "tensorflow":
|
|
83
|
-
from keras.src.utils.module_utils import tensorflow as tf
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
not tf.executing_eagerly
|
|
87
|
-
and mask_shape is not None
|
|
88
|
-
and mask_shape[1:2] != (timesteps,)
|
|
89
|
-
):
|
|
74
|
+
# Validate mask shape using static shape info when available
|
|
75
|
+
if mask is not None:
|
|
76
|
+
mask_shape = mask.shape
|
|
77
|
+
input_shape = inputs.shape
|
|
78
|
+
|
|
79
|
+
# Check if mask has at least 2 dimensions (batch and timesteps)
|
|
80
|
+
if len(mask_shape) < 2:
|
|
90
81
|
raise ValueError(
|
|
91
|
-
"`
|
|
92
|
-
|
|
93
|
-
f"
|
|
82
|
+
"The `mask` passed to the `TimeDistributed` layer must be "
|
|
83
|
+
"at least 2D (e.g., `(batch_size, timesteps)`), but it has "
|
|
84
|
+
f"{len(mask_shape)} dimension(s) with shape {mask_shape}."
|
|
94
85
|
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
|
|
87
|
+
# Check batch size and timesteps dimensions match
|
|
88
|
+
batch_mismatch = (
|
|
89
|
+
input_shape[0] is not None
|
|
90
|
+
and mask_shape[0] is not None
|
|
91
|
+
and input_shape[0] != mask_shape[0]
|
|
92
|
+
)
|
|
93
|
+
time_mismatch = (
|
|
94
|
+
input_shape[1] is not None
|
|
95
|
+
and mask_shape[1] is not None
|
|
96
|
+
and input_shape[1] != mask_shape[1]
|
|
103
97
|
)
|
|
104
98
|
|
|
99
|
+
if batch_mismatch or time_mismatch:
|
|
100
|
+
raise ValueError(
|
|
101
|
+
"The `mask` passed to the `TimeDistributed` layer has a "
|
|
102
|
+
f"shape {mask_shape} that is incompatible with the input "
|
|
103
|
+
f"shape {input_shape}. The first two dimensions of the "
|
|
104
|
+
"mask (batch size and timesteps) must match the input's "
|
|
105
|
+
"first two dimensions. Expected mask shape prefix: "
|
|
106
|
+
f"({input_shape[0]}, {input_shape[1]})."
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
input_shape = ops.shape(inputs)
|
|
110
|
+
|
|
105
111
|
def time_distributed_transpose(data):
|
|
106
112
|
"""Swaps the timestep and batch dimensions of a tensor."""
|
|
107
113
|
axes = [1, 0, *range(2, len(data.shape))]
|
|
@@ -129,5 +135,7 @@ class TimeDistributed(Wrapper):
|
|
|
129
135
|
|
|
130
136
|
# Implementation #2: use backend.vectorized_map.
|
|
131
137
|
|
|
132
|
-
outputs = backend.vectorized_map(
|
|
138
|
+
outputs = backend.vectorized_map(
|
|
139
|
+
step_function, ops.arange(input_shape[0])
|
|
140
|
+
)
|
|
133
141
|
return time_distributed_transpose(outputs)
|
keras/src/ops/core.py
CHANGED
|
@@ -277,7 +277,7 @@ def associative_scan(f, elems, reverse=False, axis=0):
|
|
|
277
277
|
[0, 1, 3, 6, 10]
|
|
278
278
|
|
|
279
279
|
>>> sum_fn = lambda x, y: [x[0] + y[0], x[1] + y[1], x[2] + y[2]]
|
|
280
|
-
>>> xs = [keras.ops.array([
|
|
280
|
+
>>> xs = [keras.ops.array([1, 2]) for _ in range(3)]
|
|
281
281
|
>>> ys = keras.ops.associative_scan(sum_fn, xs, axis=0)
|
|
282
282
|
>>> ys
|
|
283
283
|
[[1, 3], [1, 3], [1, 3]]
|
keras/src/ops/numpy.py
CHANGED
|
@@ -5064,6 +5064,119 @@ def moveaxis(x, source, destination):
|
|
|
5064
5064
|
return backend.numpy.moveaxis(x, source=source, destination=destination)
|
|
5065
5065
|
|
|
5066
5066
|
|
|
5067
|
+
class Nanmax(Operation):
|
|
5068
|
+
def __init__(self, axis=None, keepdims=False, *, name=None):
|
|
5069
|
+
super().__init__(name=name)
|
|
5070
|
+
self.axis = axis
|
|
5071
|
+
self.keepdims = keepdims
|
|
5072
|
+
|
|
5073
|
+
def call(self, x):
|
|
5074
|
+
return backend.numpy.nanmax(x, axis=self.axis, keepdims=self.keepdims)
|
|
5075
|
+
|
|
5076
|
+
def compute_output_spec(self, x):
|
|
5077
|
+
dtype = dtypes.result_type(getattr(x, "dtype", backend.floatx()))
|
|
5078
|
+
|
|
5079
|
+
if backend.backend() == "torch" and dtype == "uint32":
|
|
5080
|
+
dtype = "int32"
|
|
5081
|
+
|
|
5082
|
+
return KerasTensor(
|
|
5083
|
+
reduce_shape(x.shape, axis=self.axis, keepdims=self.keepdims),
|
|
5084
|
+
dtype=dtype,
|
|
5085
|
+
)
|
|
5086
|
+
|
|
5087
|
+
|
|
5088
|
+
@keras_export(["keras.ops.nanmax", "keras.ops.numpy.nanmax"])
|
|
5089
|
+
def nanmax(x, axis=None, keepdims=False):
|
|
5090
|
+
"""Maximum of a tensor over the given axes, ignoring NaNs.
|
|
5091
|
+
|
|
5092
|
+
Args:
|
|
5093
|
+
x: Input tensor.
|
|
5094
|
+
axis: Axis or axes along which the maximum is computed.
|
|
5095
|
+
The default is to compute the maximum of the flattened tensor.
|
|
5096
|
+
keepdims: If this is set to `True`, the axes which are reduced are left
|
|
5097
|
+
in the result as dimensions with size one. Defaults
|
|
5098
|
+
to `False`.
|
|
5099
|
+
|
|
5100
|
+
Returns:
|
|
5101
|
+
Output tensor containing the maximum, with NaN values ignored. If all
|
|
5102
|
+
values along a reduced axis are NaN, the result is NaN.
|
|
5103
|
+
|
|
5104
|
+
Examples:
|
|
5105
|
+
>>> import numpy as np
|
|
5106
|
+
>>> from keras import ops
|
|
5107
|
+
>>> x = np.array([[1.0, np.nan, 3.0],
|
|
5108
|
+
... [np.nan, 2.0, 1.0]])
|
|
5109
|
+
>>> ops.nanmax(x)
|
|
5110
|
+
3.0
|
|
5111
|
+
|
|
5112
|
+
>>> ops.nanmax(x, axis=1)
|
|
5113
|
+
array([3., 2.])
|
|
5114
|
+
|
|
5115
|
+
>>> ops.nanmax(x, axis=1, keepdims=True)
|
|
5116
|
+
array([[3.],
|
|
5117
|
+
[2.]])
|
|
5118
|
+
"""
|
|
5119
|
+
if any_symbolic_tensors((x,)):
|
|
5120
|
+
return Nanmax(axis=axis, keepdims=keepdims).symbolic_call(x)
|
|
5121
|
+
return backend.numpy.nanmax(x, axis=axis, keepdims=keepdims)
|
|
5122
|
+
|
|
5123
|
+
|
|
5124
|
+
class Nanmin(Operation):
|
|
5125
|
+
def __init__(self, axis=None, keepdims=False, *, name=None):
|
|
5126
|
+
super().__init__(name=name)
|
|
5127
|
+
self.axis = axis
|
|
5128
|
+
self.keepdims = keepdims
|
|
5129
|
+
|
|
5130
|
+
def call(self, x):
|
|
5131
|
+
return backend.numpy.nanmin(x, axis=self.axis, keepdims=self.keepdims)
|
|
5132
|
+
|
|
5133
|
+
def compute_output_spec(self, x):
|
|
5134
|
+
dtype = dtypes.result_type(getattr(x, "dtype", backend.floatx()))
|
|
5135
|
+
|
|
5136
|
+
if backend.backend() == "torch" and dtype == "uint32":
|
|
5137
|
+
dtype = "int32"
|
|
5138
|
+
|
|
5139
|
+
return KerasTensor(
|
|
5140
|
+
reduce_shape(x.shape, axis=self.axis, keepdims=self.keepdims),
|
|
5141
|
+
dtype=dtype,
|
|
5142
|
+
)
|
|
5143
|
+
|
|
5144
|
+
|
|
5145
|
+
@keras_export(["keras.ops.nanmin", "keras.ops.numpy.nanmin"])
|
|
5146
|
+
def nanmin(x, axis=None, keepdims=False):
|
|
5147
|
+
"""Minimum of a tensor over the given axes, ignoring NaNs.
|
|
5148
|
+
|
|
5149
|
+
Args:
|
|
5150
|
+
x: Input tensor.
|
|
5151
|
+
axis: Axis or axes along which the minimum is computed.
|
|
5152
|
+
The default is to compute the minimum of the flattened tensor.
|
|
5153
|
+
keepdims: If this is set to `True`, the axes which are reduced are left
|
|
5154
|
+
in the result as dimensions with size one.
|
|
5155
|
+
|
|
5156
|
+
Returns:
|
|
5157
|
+
Output tensor containing the minimum, with NaN values ignored. If all
|
|
5158
|
+
values along a reduced axis are NaN, the result is NaN.
|
|
5159
|
+
|
|
5160
|
+
Examples:
|
|
5161
|
+
>>> import numpy as np
|
|
5162
|
+
>>> from keras import ops
|
|
5163
|
+
>>> x = np.array([[1.0, np.nan, 3.0],
|
|
5164
|
+
... [np.nan, 2.0, 1.0]])
|
|
5165
|
+
>>> ops.nanmin(x)
|
|
5166
|
+
1.0
|
|
5167
|
+
|
|
5168
|
+
>>> ops.nanmin(x, axis=1)
|
|
5169
|
+
array([1., 1.])
|
|
5170
|
+
|
|
5171
|
+
>>> ops.nanmin(x, axis=1, keepdims=True)
|
|
5172
|
+
array([[1.],
|
|
5173
|
+
[1.]])
|
|
5174
|
+
"""
|
|
5175
|
+
if any_symbolic_tensors((x,)):
|
|
5176
|
+
return Nanmin(axis=axis, keepdims=keepdims).symbolic_call(x)
|
|
5177
|
+
return backend.numpy.nanmin(x, axis=axis, keepdims=keepdims)
|
|
5178
|
+
|
|
5179
|
+
|
|
5067
5180
|
class Nansum(Operation):
|
|
5068
5181
|
def __init__(self, axis=None, keepdims=False, *, name=None):
|
|
5069
5182
|
super().__init__(name=name)
|
|
@@ -45,8 +45,8 @@ class Regularizer:
|
|
|
45
45
|
>>> out = layer(tensor)
|
|
46
46
|
|
|
47
47
|
>>> # The kernel regularization term is 0.25
|
|
48
|
-
>>> # The activity regularization term (after dividing by
|
|
49
|
-
>>> # is 5
|
|
48
|
+
>>> # The activity regularization term (after dividing by batch size of 5)
|
|
49
|
+
>>> # is 5.0
|
|
50
50
|
>>> ops.sum(layer.losses)
|
|
51
51
|
5.25
|
|
52
52
|
|
keras/src/version.py
CHANGED