Browse Source

Add: constructors and comments for ActivationAdaptor

pull/1085/head
lingbai-kong 2 years ago
parent
commit
2464af2f2e
2 changed files with 42 additions and 21 deletions
  1. +35
    -21
      src/TensorFlowNET.Core/Keras/Activations/Activations.cs
  2. +7
    -0
      src/TensorFlowNET.Keras/Activations.cs

+ 35
- 21
src/TensorFlowNET.Core/Keras/Activations/Activations.cs View File

@@ -26,42 +26,56 @@ namespace Tensorflow.Keras
};
}
}

/// <summary>
/// The ActivationAdaptor is used to store string, Activation, and Func for Laysers Api to accept different types of activation parameters.
/// One of the properties must be specified while initializing.
/// </summary>
public class ActivationAdaptor
{
public string? Name { get; set; }
/// <summary>
/// The name of activaiton function, such as `tanh`, `sigmoid`.
/// </summary>
public string? Name { get; set; } = null;

/// <summary>
/// The available Activation instance of activaiton function, such as keras.activations.Tanh, keras.activations.Sigmoid.
/// </summary>
public Activation? Activation { get; set; } = null;

/// <summary>
/// The Func definition of activation function, which can be customized.
/// </summary>
public Func<Tensor, string, Tensor>? Func { get; set; } = null;

public ActivationAdaptor(string name)
{
Name = name;
}

public Activation? Activation { get; set; }
public ActivationAdaptor(Activation activation)
{
Activation = activation;
}

public Func<Tensor, string, Tensor>? Func { get; set; }
public ActivationAdaptor(Func<Tensor, string, Tensor> func)
{
Func = func;
}

public static implicit operator ActivationAdaptor(string name)
{
return new ActivationAdaptor()
{
Name = name,
Activation = null,
Func = null
};
return new ActivationAdaptor(name);
}

public static implicit operator ActivationAdaptor(Activation activation)
{
return new ActivationAdaptor()
{
Name = null,
Activation = activation,
Func = null
};
return new ActivationAdaptor(activation);
}

public static implicit operator ActivationAdaptor(Func<Tensor, string, Tensor> func)
{
return new ActivationAdaptor()
{
Name = null,
Activation = null,
Func = func
};
return new ActivationAdaptor(func);
}
}



+ 7
- 0
src/TensorFlowNET.Keras/Activations.cs View File

@@ -93,6 +93,13 @@ namespace Tensorflow.Keras
}
}

/// <summary>
/// Convert ActivationAdaptor to Activation.
/// If more than one properties of ActivationAdaptor are specified, the order of priority is `Name`, `Activation`, `Func`
/// </summary>
/// <param name="adaptor"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public Activation GetActivationFromAdaptor(ActivationAdaptor adaptor)
{
if(adaptor == null)


Loading…
Cancel
Save