From 365962f5ca087d849255b6f96792483b5315c32a Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Fri, 19 Apr 2019 15:15:51 +0200 Subject: [PATCH] NN XOR port complete, but fails --- test/TensorFlowNET.Examples/NeuralNetXor.cs | 49 ++++++++++++------- .../ExamplesTests/ExamplesTest.cs | 2 +- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/test/TensorFlowNET.Examples/NeuralNetXor.cs b/test/TensorFlowNET.Examples/NeuralNetXor.cs index eea081e0..42911aad 100644 --- a/test/TensorFlowNET.Examples/NeuralNetXor.cs +++ b/test/TensorFlowNET.Examples/NeuralNetXor.cs @@ -59,29 +59,40 @@ namespace TensorFlowNET.Examples with(tf.Session(graph), sess => { init.run(); - var step = 0; - var xy = np.array(new bool[,] + var step = 0; + //TODO: make the type conversion and jagged array initializer work with numpy + //var xy = np.array(new bool[,] + //{ + // {true, false}, + // {true, true }, + // {false, false }, + // {false, true}, + //}, dtype: np.float32); + var xy = np.array(new float[] { - {true, false}, - {true, true }, - {false, false }, - {false, true}, - }, dtype: np.float32); - - var y_ = np.array(new[] {true, false, false, true}, dtype: np.int32); + 1, 0, + 1, 1, + 0, 0, + 0, 1 + }, np.float32).reshape(4,2); + + + //var y_ = np.array(new[] {true, false, false, true}, dtype: np.int32); + var y_ = np.array(new int[] { 1, 0, 0, 1 }, dtype: np.int32); + NDArray loss_value=null; while (step < num_steps) - { - // original python: - //_, step, loss_value = sess.run( - // [train_op, gs, loss], - // feed_dict={features: xy, labels: y_} + { + // original python: + //_, step, loss_value = sess.run( + // [train_op, gs, loss], + // feed_dict={features: xy, labels: y_} // ) - // TODO: how the hell to port that to c#? - // var ( _, step, loss_value) = sess.run(new object[] {train_op, gs, loss},feed_dict: new {"features": xy, "labels": y_}); + loss_value = sess.run(loss, new FeedItem(features, xy), new FeedItem(labels, y_)); + step++; + if (step%1000==0) + Console.WriteLine($"Step {0} loss: {loss_value[0]}"); } - //tf.logging.info('Final loss is: {}'.format(loss_value)) - //Console.WriteLine($"Final loss is: {loss_value}"); - + Console.WriteLine($"Final loss: {loss_value[0]}"); }); return true; } diff --git a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs index b0af5125..e0174c56 100644 --- a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs +++ b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs @@ -109,7 +109,7 @@ namespace TensorFlowNET.ExamplesTests new TextClassificationWithMovieReviews() { Enabled = true }.Run(); } - [Ignore] + [Ignore("Attempting to use uninitialized value Variable_1")] [TestMethod] public void NeuralNetXor() {