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.

Softsign.cs 835 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Tensorflow.Common.Types;
  5. using Tensorflow.Keras.ArgsDefinition;
  6. using Tensorflow.Keras.Engine;
  7. using static Tensorflow.Binding;
  8. namespace Tensorflow.Keras.Layers {
  9. public class Softsign : Layer {
  10. public Softsign ( LayerArgs args ) : base(args) {
  11. // Softsign has no arguments
  12. }
  13. protected override Tensors Call ( Tensors inputs, Tensors state = null, bool? training = null, IOptionalArgs? optional_args = null) {
  14. Tensor x = inputs;
  15. // x / (abs(x) + 1)
  16. return tf.div(x, tf.add(1f, tf.abs(x)));
  17. }
  18. public override Shape ComputeOutputShape ( Shape input_shape ) {
  19. return input_shape;
  20. }
  21. }
  22. }