Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/keras/src/layers/activation/elu.py: 55%
22 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Exponential Linear Unit activation layer."""
18from keras.src import backend
19from keras.src.engine.base_layer import Layer
20from keras.src.utils import tf_utils
22# isort: off
23from tensorflow.python.util.tf_export import keras_export
26@keras_export("keras.layers.ELU")
27class ELU(Layer):
28 """Exponential Linear Unit.
30 It follows:
32 ```
33 f(x) = alpha * (exp(x) - 1.) for x < 0
34 f(x) = x for x >= 0
35 ```
37 Input shape:
38 Arbitrary. Use the keyword argument `input_shape`
39 (tuple of integers, does not include the samples axis)
40 when using this layer as the first layer in a model.
42 Output shape:
43 Same shape as the input.
45 Args:
46 alpha: Scale for the negative factor.
47 """
49 def __init__(self, alpha=1.0, **kwargs):
50 super().__init__(**kwargs)
51 if alpha is None:
52 raise ValueError(
53 "Alpha of an ELU layer cannot be None, expecting a float. "
54 f"Received: {alpha}"
55 )
56 self.supports_masking = True
57 self.alpha = backend.cast_to_floatx(alpha)
59 def call(self, inputs):
60 return backend.elu(inputs, self.alpha)
62 def get_config(self):
63 config = {"alpha": float(self.alpha)}
64 base_config = super().get_config()
65 return dict(list(base_config.items()) + list(config.items()))
67 @tf_utils.shape_type_conversion
68 def compute_output_shape(self, input_shape):
69 return input_shape