Browse Source

add tf.nn.l2_loss

tags/TimeSeries
Oceania2018 3 years ago
parent
commit
7cc6319b97
4 changed files with 25 additions and 1 deletions
  1. +3
    -0
      src/TensorFlowNET.Core/APIs/tf.nn.cs
  2. +3
    -0
      src/TensorFlowNET.Core/Operations/nn_ops.cs
  3. +1
    -1
      test/TensorFlowNET.UnitTest/ManagedAPI/ActivationFunctionTest.cs
  4. +18
    -0
      test/TensorFlowNET.UnitTest/ManagedAPI/NeuralNetworkTest.cs

+ 3
- 0
src/TensorFlowNET.Core/APIs/tf.nn.cs View File

@@ -157,6 +157,9 @@ namespace Tensorflow
}); });
} }


public Tensor l2_loss(Tensor t, string name = null)
=> nn_ops.l2_loss(t, name: name);

/// <summary> /// <summary>
/// Local Response Normalization. /// Local Response Normalization.
/// </summary> /// </summary>


+ 3
- 0
src/TensorFlowNET.Core/Operations/nn_ops.cs View File

@@ -128,6 +128,9 @@ namespace Tensorflow
return _softmax(logits, gen_nn_ops.softmax, axis, name); return _softmax(logits, gen_nn_ops.softmax, axis, name);
} }


public static Tensor l2_loss(Tensor t, string name = null)
=> tf.Context.ExecuteOp("L2Loss", name, new ExecuteOpArgs(t));

public static Tensor leaky_relu(Tensor features, float alpha = 0.2f, string name = null) public static Tensor leaky_relu(Tensor features, float alpha = 0.2f, string name = null)
{ {
return tf_with(ops.name_scope(name, "LeakyRelu", new { features, alpha }), scope => return tf_with(ops.name_scope(name, "LeakyRelu", new { features, alpha }), scope =>


+ 1
- 1
test/TensorFlowNET.UnitTest/ManagedAPI/ActivationFunctionTest.cs View File

@@ -2,7 +2,7 @@
using Tensorflow; using Tensorflow;
using static Tensorflow.Binding; using static Tensorflow.Binding;


namespace TensorFlowNET.UnitTest.nn_test
namespace TensorFlowNET.UnitTest.NenuralNetwork
{ {
[TestClass] [TestClass]
public class ActivationFunctionTest : EagerModeTestBase public class ActivationFunctionTest : EagerModeTestBase


+ 18
- 0
test/TensorFlowNET.UnitTest/ManagedAPI/NeuralNetworkTest.cs View File

@@ -0,0 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Tensorflow.Binding;
using Tensorflow.NumPy;

namespace TensorFlowNET.UnitTest.NenuralNetwork
{
[TestClass]
public class NeuralNetworkTest : EagerModeTestBase
{
[TestMethod]
public void l2_loss()
{
var x = tf.Variable(np.array(new[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } }), dtype: tf.float32);
var l2 = tf.nn.l2_loss(x);
Assert.AreEqual(l2.numpy(), 102f);
}
}
}

Loading…
Cancel
Save