Browse Source

Merge pull request #233 from henon/master

NN XOR port complete, but still fails
tags/v0.9
Haiping GitHub 6 years ago
parent
commit
4a799e5176
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 20 deletions
  1. +30
    -19
      test/TensorFlowNET.Examples/NeuralNetXor.cs
  2. +1
    -1
      test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs

+ 30
- 19
test/TensorFlowNET.Examples/NeuralNetXor.cs View File

@@ -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;
}


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

@@ -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()
{


Loading…
Cancel
Save