Browse Source

fix unit test by new a graph.

tags/v0.9
Oceania2018 6 years ago
parent
commit
1c8aa4a93e
4 changed files with 29 additions and 10 deletions
  1. +17
    -3
      test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs
  2. +2
    -0
      test/TensorFlowNET.UnitTest/VariableTest.cs
  3. +5
    -7
      test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs
  4. +5
    -0
      test/TensorFlowNET.UnitTest/nest_test/NestTest.cs

+ 17
- 3
test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs View File

@@ -2,10 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tensorflow;
using TensorFlowNET.Examples; using TensorFlowNET.Examples;
using TensorFlowNET.Examples.CnnTextClassification; using TensorFlowNET.Examples.CnnTextClassification;
namespace TensorFlowNET.UnitTest.ExamplesTests
namespace TensorFlowNET.ExamplesTests
{ {
[TestClass] [TestClass]
public class ExamplesTest public class ExamplesTest
@@ -13,18 +14,21 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void BasicOperations() public void BasicOperations()
{ {
tf.Graph().as_default();
new BasicOperations() { Enabled = true }.Run(); new BasicOperations() { Enabled = true }.Run();
} }
[TestMethod] [TestMethod]
public void HelloWorld() public void HelloWorld()
{ {
tf.Graph().as_default();
new HelloWorld() { Enabled = true }.Run(); new HelloWorld() { Enabled = true }.Run();
} }
[TestMethod] [TestMethod]
public void ImageRecognition() public void ImageRecognition()
{ {
tf.Graph().as_default();
new HelloWorld() { Enabled = true }.Run(); new HelloWorld() { Enabled = true }.Run();
} }
@@ -32,6 +36,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void InceptionArchGoogLeNet() public void InceptionArchGoogLeNet()
{ {
tf.Graph().as_default();
new InceptionArchGoogLeNet() { Enabled = true }.Run(); new InceptionArchGoogLeNet() { Enabled = true }.Run();
} }
@@ -39,18 +44,21 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void KMeansClustering() public void KMeansClustering()
{ {
new KMeansClustering() { Enabled = true, train_size = 500, validation_size = 100, test_size = 100, batch_size =100 }.Run();
tf.Graph().as_default();
new KMeansClustering() { Enabled = false, train_size = 500, validation_size = 100, test_size = 100, batch_size =100 }.Run();
} }
[TestMethod] [TestMethod]
public void LinearRegression() public void LinearRegression()
{ {
tf.Graph().as_default();
new LinearRegression() { Enabled = true }.Run(); new LinearRegression() { Enabled = true }.Run();
} }
[TestMethod] [TestMethod]
public void LogisticRegression() public void LogisticRegression()
{ {
tf.Graph().as_default();
new LogisticRegression() { Enabled = true, training_epochs=10, train_size = 500, validation_size = 100, test_size = 100 }.Run(); new LogisticRegression() { Enabled = true, training_epochs=10, train_size = 500, validation_size = 100, test_size = 100 }.Run();
} }
@@ -58,6 +66,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void MetaGraph() public void MetaGraph()
{ {
tf.Graph().as_default();
new MetaGraph() { Enabled = true }.Run(); new MetaGraph() { Enabled = true }.Run();
} }
@@ -65,19 +74,22 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void NaiveBayesClassifier() public void NaiveBayesClassifier()
{ {
new NaiveBayesClassifier() { Enabled = true }.Run();
tf.Graph().as_default();
new NaiveBayesClassifier() { Enabled = false }.Run();
} }
[Ignore] [Ignore]
[TestMethod] [TestMethod]
public void NamedEntityRecognition() public void NamedEntityRecognition()
{ {
tf.Graph().as_default();
new NamedEntityRecognition() { Enabled = true }.Run(); new NamedEntityRecognition() { Enabled = true }.Run();
} }
[TestMethod] [TestMethod]
public void NearestNeighbor() public void NearestNeighbor()
{ {
tf.Graph().as_default();
new NearestNeighbor() { Enabled = true, TrainSize = 500, ValidationSize = 100, TestSize = 100 }.Run(); new NearestNeighbor() { Enabled = true, TrainSize = 500, ValidationSize = 100, TestSize = 100 }.Run();
} }
@@ -85,6 +97,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void TextClassificationTrain() public void TextClassificationTrain()
{ {
tf.Graph().as_default();
new TextClassificationTrain() { Enabled = true, DataLimit=100 }.Run(); new TextClassificationTrain() { Enabled = true, DataLimit=100 }.Run();
} }
@@ -92,6 +105,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod] [TestMethod]
public void TextClassificationWithMovieReviews() public void TextClassificationWithMovieReviews()
{ {
tf.Graph().as_default();
new TextClassificationWithMovieReviews() { Enabled = true }.Run(); new TextClassificationWithMovieReviews() { Enabled = true }.Run();
} }


+ 2
- 0
test/TensorFlowNET.UnitTest/VariableTest.cs View File

@@ -36,6 +36,7 @@ namespace TensorFlowNET.UnitTest
[TestMethod] [TestMethod]
public void VarCreation() public void VarCreation()
{ {
tf.Graph().as_default();
with(tf.variable_scope("foo"), delegate with(tf.variable_scope("foo"), delegate
{ {
with(tf.variable_scope("bar"), delegate with(tf.variable_scope("bar"), delegate
@@ -52,6 +53,7 @@ namespace TensorFlowNET.UnitTest
[TestMethod] [TestMethod]
public void ReenterVariableScope() public void ReenterVariableScope()
{ {
tf.Graph().as_default();
variable_scope vs = null; variable_scope vs = null;
with(tf.variable_scope("foo"), v => vs = v); with(tf.variable_scope("foo"), v => vs = v);




+ 5
- 7
test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs View File

@@ -9,26 +9,24 @@ namespace TensorFlowNET.UnitTest.gradients_test
[TestClass] [TestClass]
public class GradientsTest : PythonTest public class GradientsTest : PythonTest
{ {
//[Ignore("TODO")]
[Ignore("TODO")]
[TestMethod] [TestMethod]
public void testGradients() public void testGradients()
{ {
with(tf.Graph().as_default(), g => with(tf.Graph().as_default(), g =>
{ {
var inp = tf.constant(1.0, shape: new[]{32, 100}, name:"in");
var w = tf.constant(1.0, shape: new[] { 100, 10}, name:"w");
var b = tf.constant(1.0, shape: new[] { 10}, name:"b");
var inp = tf.constant(1.0, shape: new[] { 32, 100 }, name: "in");
var w = tf.constant(1.0, shape: new[] { 100, 10 }, name: "w");
var b = tf.constant(1.0, shape: new[] { 10 }, name: "b");
var xw = math_ops.matmul(inp, w, name: "xw"); var xw = math_ops.matmul(inp, w, name: "xw");
var h = nn_ops.bias_add(xw, b, name: "h"); var h = nn_ops.bias_add(xw, b, name: "h");
var w_grad = gradients_impl.gradients(new []{h}, new[] { w})[0];
var w_grad = gradients_impl.gradients(new[] { h }, new[] { w })[0];
self.assertEquals("MatMul", w_grad.op.type); self.assertEquals("MatMul", w_grad.op.type);
// TODO: Operation._original_op // TODO: Operation._original_op
//self.assertEquals(w_grad.op._original_op, xw.op); //self.assertEquals(w_grad.op._original_op, xw.op);
self.assertTrue((bool)w_grad.op.get_attr("transpose_a")); self.assertTrue((bool)w_grad.op.get_attr("transpose_a"));
self.assertFalse((bool)w_grad.op.get_attr("transpose_b")); self.assertFalse((bool)w_grad.op.get_attr("transpose_b"));
}); });
} }
[Ignore("TODO")] [Ignore("TODO")]


+ 5
- 0
test/TensorFlowNET.UnitTest/nest_test/NestTest.cs View File

@@ -15,6 +15,11 @@ namespace TensorFlowNET.UnitTest.nest_test
[TestClass] [TestClass]
public class NestTest : PythonTest public class NestTest : PythonTest
{ {
[TestInitialize]
public void TestInitialize()
{
tf.Graph().as_default();
}
//public class PointXY //public class PointXY
//{ //{


Loading…
Cancel
Save