You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ELU.cs 1.3 kB

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