|
6 | 6 | using static Tensorflow.Binding; |
7 | 7 |
|
8 | 8 | namespace Tensorflow.Keras.Layers { |
9 | | - /// <summary> |
10 | | - /// ELU Layer: |
11 | | - /// x = 0 when x > 0, x = alpha( e^x-1 ) elsewhere |
12 | | - /// </summary> |
13 | | - public class ELU : Layer { |
14 | | - ELUArgs args; |
15 | | - float alpha => args.Alpha; |
16 | | - public ELU ( ELUArgs args ) : base(args) { |
17 | | - this.args = args; |
18 | | - } |
19 | | - protected override void build ( Tensors inputs ) { |
20 | | - if ( alpha < 0f ) { |
21 | | - throw new ValueError("Alpha must be a number greater than 0."); |
22 | | - } |
23 | | - built = true; |
24 | | - } |
25 | | - protected override Tensors Call ( Tensors inputs, Tensor state = null, bool? training = null ) { |
26 | | - Tensor output = inputs; |
27 | | - output = tf.where(output > 0f, output, |
28 | | - tf.multiply(alpha, tf.sub(tf.exp(output), 1f))); |
29 | | - return output; |
30 | | - } |
31 | | - public override Shape ComputeOutputShape ( Shape input_shape ) { |
32 | | - return input_shape; |
| 9 | + /// <summary> |
| 10 | + /// ELU Layer: |
| 11 | + /// x = 0 when x > 0, x = alpha( e^x-1 ) elsewhere |
| 12 | + /// </summary> |
| 13 | + public class ELU : Layer |
| 14 | + { |
| 15 | + ELUArgs args; |
| 16 | + float alpha => args.Alpha; |
| 17 | + public ELU(ELUArgs args) : base(args) |
| 18 | + { |
| 19 | + this.args = args; |
| 20 | + } |
| 21 | + |
| 22 | + public override void build(Shape input_shape) |
| 23 | + { |
| 24 | + if (alpha < 0f) |
| 25 | + { |
| 26 | + throw new ValueError("Alpha must be a number greater than 0."); |
33 | 27 | } |
34 | | - } |
| 28 | + built = true; |
| 29 | + } |
| 30 | + |
| 31 | + protected override Tensors Call(Tensors inputs, Tensor state = null, bool? training = null) |
| 32 | + { |
| 33 | + Tensor output = inputs; |
| 34 | + output = tf.where(output > 0f, output, |
| 35 | + tf.multiply(alpha, tf.sub(tf.exp(output), 1f))); |
| 36 | + return output; |
| 37 | + } |
| 38 | + public override Shape ComputeOutputShape(Shape input_shape) |
| 39 | + { |
| 40 | + return input_shape; |
| 41 | + } |
| 42 | + } |
35 | 43 | } |
0 commit comments