Skip to content

Commit e1db889

Browse files
committed
add tf.nn.elu activation function. #294
1 parent 23e70e2 commit e1db889

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/TensorFlowNET.Core/APIs/tf.nn.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public static (Tensor, Tensor) dynamic_rnn(RNNCell cell, Tensor inputs, TF_DataT
9797
throw new NotImplementedException("");
9898
}
9999

100+
public static Tensor elu(Tensor features, string name = null)
101+
=> gen_nn_ops.elu(features, name: name);
102+
100103
public static (Tensor, Tensor) moments(Tensor x,
101104
int[] axes,
102105
string name = null,

src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ public static Tensor bias_add_grad(Tensor out_backprop,
139139
});
140140

141141
return _op.outputs[0];
142+
}
143+
144+
/// <summary>
145+
/// Computes exponential linear: <c>exp(features) - 1</c> if &amp;lt; 0, <c>features</c> otherwise.
146+
/// </summary>
147+
/// <param name="features">
148+
/// </param>
149+
/// <param name="name">
150+
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Elu'.
151+
/// </param>
152+
/// <returns>
153+
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
154+
/// </returns>
155+
/// <remarks>
156+
/// See [Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs)
157+
/// ](http://arxiv.org/abs/1511.07289)
158+
/// </remarks>
159+
public static Tensor elu(Tensor features, string name = "Elu")
160+
{
161+
var op = _op_def_lib._apply_op_helper("Elu", name: name, args: new { features });
162+
return op.output;
142163
}
143164

144165
public static Tensor[] _fused_batch_norm(Tensor x,

test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public bool Run()
199199
RefVariable layer_biases = null;
200200
with(tf.name_scope("biases"), delegate
201201
{
202-
layer_biases = tf.Variable(tf.zeros((class_count)), name: "final_biases");
202+
layer_biases = tf.Variable(tf.zeros(class_count), name: "final_biases");
203203
variable_summaries(layer_biases);
204204
});
205205

0 commit comments

Comments
 (0)