Skip to content

Commit 42631ec

Browse files
committed
Merge branch 'master' of github.com:keras-team/keras
2 parents f0869a9 + 49a3063 commit 42631ec

Some content is hidden

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

54 files changed

+2171
-646
lines changed

.github/workflows/actions.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Test applications with pytest
5555
if: ${{ steps.filter.outputs.applications == 'true' }}
5656
run: |
57-
pytest keras/src/applications --cov=keras/src/applications
57+
pytest keras/src/applications --cov=keras/src/applications --cov-config=pyproject.toml
5858
coverage xml --include='keras/src/applications/*' -o apps-coverage.xml
5959
- name: Codecov keras.applications
6060
if: ${{ steps.filter.outputs.applications == 'true' }}
@@ -86,19 +86,16 @@ jobs:
8686
python integration_tests/torch_custom_fit_test.py
8787
- name: Test with pytest
8888
run: |
89-
pytest keras --ignore keras/src/applications
90-
# - name: Test with pytest
91-
# run: |
92-
# pytest keras --ignore keras/src/applications --cov=keras
93-
# coverage xml --omit='keras/src/applications/*,keras/api' -o core-coverage.xml
94-
# - name: Codecov keras
95-
# uses: codecov/codecov-action@v4
96-
# with:
97-
# env_vars: PYTHON,KERAS_HOME
98-
# flags: keras,keras-${{ matrix.backend }}
99-
# files: core-coverage.xml
100-
# token: ${{ secrets.CODECOV_TOKEN }}
101-
# fail_ci_if_error: false
89+
pytest keras --ignore keras/src/applications --cov=keras --cov-config=pyproject.toml
90+
coverage xml --omit='keras/src/applications/*,keras/api' -o core-coverage.xml
91+
- name: Codecov keras
92+
uses: codecov/codecov-action@v4
93+
with:
94+
env_vars: PYTHON,KERAS_HOME
95+
flags: keras,keras-${{ matrix.backend }}
96+
files: core-coverage.xml
97+
token: ${{ secrets.CODECOV_TOKEN }}
98+
fail_ci_if_error: false
10299

103100
format:
104101
name: Check the code format

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
pytest integration_tests/torch_workflow_test.py
5656
- name: Test with pytest
5757
run: |
58-
pytest keras --ignore keras/src/applications --cov=keras
58+
pytest keras --ignore keras/src/applications --cov=keras --cov-config=pyproject.toml
5959
6060
format:
6161
name: Check the code format

.kokoro/github/ubuntu/gpu/build.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ then
3636
# TODO: keras/layers/merging/merging_test.py::MergingLayersTest::test_sparse_dot_2d Fatal Python error: Aborted
3737
pytest keras --ignore keras/src/applications \
3838
--ignore keras/src/layers/merging/merging_test.py \
39-
--cov=keras
39+
--cov=keras \
40+
--cov-config=pyproject.toml
4041
fi
4142

4243
if [ "$KERAS_BACKEND" == "jax" ]
@@ -56,9 +57,10 @@ then
5657
--ignore keras/src/trainers/data_adapters/py_dataset_adapter_test.py \
5758
--ignore keras/src/backend/jax/distribution_lib_test.py \
5859
--ignore keras/src/distribution/distribution_lib_test.py \
59-
--cov=keras
60+
--cov=keras \
61+
--cov-config=pyproject.toml
6062

61-
pytest keras/src/distribution/distribution_lib_test.py --cov=keras
63+
pytest keras/src/distribution/distribution_lib_test.py --cov=keras --cov-config=pyproject.toml
6264
fi
6365

6466
if [ "$KERAS_BACKEND" == "torch" ]
@@ -71,5 +73,7 @@ then
7173
python3 -c 'import torch;assert torch.cuda.is_available()'
7274

7375
pytest keras --ignore keras/src/applications \
74-
--cov=keras
76+
--cov=keras \
77+
--cov-config=pyproject.toml
78+
7579
fi

keras/api/_tf_keras/keras/activations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from keras.src.activations import deserialize
88
from keras.src.activations import get
99
from keras.src.activations import serialize
10+
from keras.src.activations.activations import celu
1011
from keras.src.activations.activations import elu
1112
from keras.src.activations.activations import exponential
1213
from keras.src.activations.activations import gelu

keras/api/_tf_keras/keras/layers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
from keras.src.layers.preprocessing.image_preprocessing.center_crop import (
146146
CenterCrop,
147147
)
148+
from keras.src.layers.preprocessing.image_preprocessing.max_num_bounding_box import (
149+
MaxNumBoundingBoxes,
150+
)
148151
from keras.src.layers.preprocessing.image_preprocessing.random_brightness import (
149152
RandomBrightness,
150153
)

keras/api/_tf_keras/keras/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from keras.src.ops.nn import batch_normalization
6363
from keras.src.ops.nn import binary_crossentropy
6464
from keras.src.ops.nn import categorical_crossentropy
65+
from keras.src.ops.nn import celu
6566
from keras.src.ops.nn import conv
6667
from keras.src.ops.nn import conv_transpose
6768
from keras.src.ops.nn import ctc_decode

keras/api/_tf_keras/keras/ops/nn/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from keras.src.ops.nn import batch_normalization
99
from keras.src.ops.nn import binary_crossentropy
1010
from keras.src.ops.nn import categorical_crossentropy
11+
from keras.src.ops.nn import celu
1112
from keras.src.ops.nn import conv
1213
from keras.src.ops.nn import conv_transpose
1314
from keras.src.ops.nn import ctc_decode

keras/api/_tf_keras/keras/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
since your modifications would be overwritten.
55
"""
66

7+
from keras.api.utils import bounding_boxes
78
from keras.api.utils import legacy
89
from keras.src.backend.common.global_state import clear_session
910
from keras.src.backend.common.keras_tensor import is_keras_tensor
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""DO NOT EDIT.
2+
3+
This file was autogenerated. Do not edit it by hand,
4+
since your modifications would be overwritten.
5+
"""
6+
7+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
8+
affine_transform,
9+
)
10+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
11+
clip_to_image_size,
12+
)
13+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
14+
convert_format,
15+
)
16+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
17+
crop,
18+
)
19+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
20+
pad,
21+
)

keras/api/activations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from keras.src.activations import deserialize
88
from keras.src.activations import get
99
from keras.src.activations import serialize
10+
from keras.src.activations.activations import celu
1011
from keras.src.activations.activations import elu
1112
from keras.src.activations.activations import exponential
1213
from keras.src.activations.activations import gelu

keras/api/layers/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
from keras.src.layers.preprocessing.image_preprocessing.center_crop import (
146146
CenterCrop,
147147
)
148+
from keras.src.layers.preprocessing.image_preprocessing.max_num_bounding_box import (
149+
MaxNumBoundingBoxes,
150+
)
148151
from keras.src.layers.preprocessing.image_preprocessing.random_brightness import (
149152
RandomBrightness,
150153
)

keras/api/ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from keras.src.ops.nn import batch_normalization
6363
from keras.src.ops.nn import binary_crossentropy
6464
from keras.src.ops.nn import categorical_crossentropy
65+
from keras.src.ops.nn import celu
6566
from keras.src.ops.nn import conv
6667
from keras.src.ops.nn import conv_transpose
6768
from keras.src.ops.nn import ctc_decode

keras/api/ops/nn/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from keras.src.ops.nn import batch_normalization
99
from keras.src.ops.nn import binary_crossentropy
1010
from keras.src.ops.nn import categorical_crossentropy
11+
from keras.src.ops.nn import celu
1112
from keras.src.ops.nn import conv
1213
from keras.src.ops.nn import conv_transpose
1314
from keras.src.ops.nn import ctc_decode

keras/api/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
since your modifications would be overwritten.
55
"""
66

7+
from keras.api.utils import bounding_boxes
78
from keras.api.utils import legacy
89
from keras.src.backend.common.global_state import clear_session
910
from keras.src.backend.common.keras_tensor import is_keras_tensor
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""DO NOT EDIT.
2+
3+
This file was autogenerated. Do not edit it by hand,
4+
since your modifications would be overwritten.
5+
"""
6+
7+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
8+
affine_transform,
9+
)
10+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
11+
clip_to_image_size,
12+
)
13+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
14+
convert_format,
15+
)
16+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
17+
crop,
18+
)
19+
from keras.src.layers.preprocessing.image_preprocessing.bounding_boxes.converters import (
20+
pad,
21+
)

keras/src/activations/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import types
22

3+
from keras.src.activations.activations import celu
34
from keras.src.activations.activations import elu
45
from keras.src.activations.activations import exponential
56
from keras.src.activations.activations import gelu
@@ -27,6 +28,7 @@
2728
leaky_relu,
2829
relu6,
2930
softmax,
31+
celu,
3032
elu,
3133
selu,
3234
softplus,

keras/src/activations/activations.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,27 @@ def gelu(x, approximate=False):
302302
return ops.gelu(x, approximate=approximate)
303303

304304

305+
@keras_export("keras.activations.celu")
306+
def celu(x, alpha=1.0):
307+
"""Continuously Differentiable Exponential Linear Unit.
308+
309+
The CeLU activation function is defined as:
310+
311+
`celu(x) = alpha * (exp(x / alpha) - 1) for x < 0`,`celu(x) = x for x >= 0`.
312+
313+
where `alpha` is a scaling parameter that controls the activation's shape.
314+
315+
Args:
316+
x: Input tensor.
317+
alpha: The α value for the CeLU formulation. Defaults to `1.0`.
318+
319+
Reference:
320+
321+
- [Barron, J. T., 2017](https://arxiv.org/abs/1704.07483)
322+
"""
323+
return ops.celu(x, alpha=alpha)
324+
325+
305326
@keras_export("keras.activations.tanh")
306327
def tanh(x):
307328
"""Hyperbolic tangent activation function.

keras/src/activations/activations_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,22 @@ def gelu(x, approximate=False):
582582
expected = gelu(x, True)
583583
self.assertAllClose(result, expected, rtol=1e-05)
584584

585+
def test_celu(self):
586+
def celu(x, alpha=1.0):
587+
return np.maximum(x, 0.0) + alpha * np.expm1(
588+
np.minimum(x, 0.0) / alpha
589+
)
590+
591+
x = np.random.random((2, 5))
592+
result = activations.celu(x[np.newaxis, :])[0]
593+
expected = celu(x)
594+
self.assertAllClose(result, expected, rtol=1e-05)
595+
596+
x = np.random.random((2, 5))
597+
result = activations.celu(x[np.newaxis, :], alpha=0.5)[0]
598+
expected = celu(x, True)
599+
self.assertAllClose(result, expected, rtol=1e-05)
600+
585601
def test_elu(self):
586602
x = np.random.random((2, 5))
587603
result = activations.elu(x[np.newaxis, :])[0]

keras/src/backend/jax/nn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ def gelu(x, approximate=True):
8585
return jnn.gelu(x, approximate)
8686

8787

88+
def celu(x, alpha=1.0):
89+
x = convert_to_tensor(x)
90+
return jnn.celu(x, alpha=alpha)
91+
92+
8893
def softmax(x, axis=-1):
8994
x = convert_to_tensor(x)
9095
return jnn.softmax(x, axis=axis)

keras/src/backend/jax/trainer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def fit(
381381
)
382382

383383
self._symbolic_build(iterator=epoch_iterator)
384+
epoch_iterator.reset()
384385

385386
# Container that configures and calls callbacks.
386387
if not isinstance(callbacks, callbacks_module.CallbackList):
@@ -405,7 +406,7 @@ def fit(
405406
callbacks.on_epoch_begin(epoch)
406407

407408
self._jax_state_synced = True
408-
for step, data in epoch_iterator.enumerate_epoch():
409+
for step, data in epoch_iterator:
409410
# Callbacks
410411
callbacks.on_train_batch_begin(step)
411412

@@ -539,6 +540,7 @@ def evaluate(
539540
)
540541

541542
self._symbolic_build(iterator=epoch_iterator)
543+
epoch_iterator.reset()
542544

543545
# Container that configures and calls callbacks.
544546
if not isinstance(callbacks, callbacks_module.CallbackList):
@@ -560,7 +562,7 @@ def evaluate(
560562
self.reset_metrics()
561563

562564
self._jax_state_synced = True
563-
for step, data in epoch_iterator.enumerate_epoch():
565+
for step, data in epoch_iterator:
564566
callbacks.on_test_batch_begin(step)
565567

566568
if self._jax_state_synced:
@@ -625,7 +627,7 @@ def predict(
625627

626628
if not all(layer.built for layer in self._flatten_layers()):
627629
# Build the model on one batch of data.
628-
for _, data in epoch_iterator.enumerate_epoch():
630+
for _, data in epoch_iterator:
629631
# Build model
630632
x, _, _ = data_adapter_utils.unpack_x_y_sample_weight(data[0])
631633
with backend.StatelessScope():
@@ -667,7 +669,7 @@ def append_to_outputs(batch_outputs, outputs):
667669
self._jax_state_synced = True
668670
outputs = None
669671
non_trainable_variables = None
670-
for step, x in epoch_iterator.enumerate_epoch():
672+
for step, x in epoch_iterator:
671673
callbacks.on_predict_batch_begin(step)
672674
if self._jax_state_synced:
673675
# The state may have been synced by a callback.

keras/src/backend/numpy/nn.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ def gelu(x, approximate=True):
113113
)
114114

115115

116+
def celu(x, alpha=1.0):
117+
x = convert_to_tensor(x)
118+
alpha = np.array(alpha, x.dtype)
119+
return np.maximum(x, np.array(0.0, dtype=x.dtype)) + alpha * np.expm1(
120+
np.minimum(x, np.array(0.0, dtype=x.dtype)) / alpha
121+
)
122+
123+
116124
def softmax(x, axis=None):
117125
exp_x = np.exp(x - np.max(x, axis=axis, keepdims=True))
118126
return exp_x / np.sum(exp_x, axis=axis, keepdims=True)

keras/src/backend/numpy/trainer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def append_to_outputs(batch_outputs, outputs):
212212
self.stop_predicting = False
213213
callbacks.on_predict_begin()
214214
outputs = None
215-
for step, data in epoch_iterator.enumerate_epoch():
215+
for step, data in epoch_iterator:
216216
callbacks.on_predict_batch_begin(step)
217217
batch_outputs = self.predict_function(data)
218218
outputs = append_to_outputs(batch_outputs, outputs)
@@ -256,7 +256,7 @@ def evaluate(
256256

257257
if not all(layer.built for layer in self._flatten_layers()):
258258
# Build the model on one batch of data.
259-
for _, data in epoch_iterator.enumerate_epoch():
259+
for _, data in epoch_iterator:
260260
data_batch = data[0]
261261
self._symbolic_build(data_batch)
262262
break
@@ -278,7 +278,7 @@ def evaluate(
278278
callbacks.on_test_begin()
279279
logs = {}
280280
self.reset_metrics()
281-
for step, data in epoch_iterator.enumerate_epoch():
281+
for step, data in epoch_iterator:
282282
callbacks.on_test_batch_begin(step)
283283
logs = self.test_function(data)
284284
callbacks.on_test_batch_end(step, logs)

keras/src/backend/tensorflow/distribute_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_epoch_iterator(self):
103103
distribute_strategy=strategy,
104104
)
105105
steps_seen = []
106-
for step, data_iterator in epoch_iterator.enumerate_epoch():
106+
for step, data_iterator in epoch_iterator:
107107
steps_seen.append(step)
108108
batch = next(data_iterator)
109109
self.assertEqual(len(batch), 3)

0 commit comments

Comments
 (0)