Browse Source

fix HelloWorld example exception.

tags/v0.8.0
Oceania2018 6 years ago
parent
commit
f4b6d509ca
3 changed files with 26 additions and 3 deletions
  1. +12
    -1
      src/TensorFlowNET.Core/Python.cs
  2. +2
    -2
      test/TensorFlowNET.Examples/HelloWorld.cs
  3. +12
    -0
      test/TensorFlowNET.Examples/LinearRegression.cs

+ 12
- 1
src/TensorFlowNET.Core/Python.cs View File

@@ -1,4 +1,5 @@
using System;
using NumSharp.Core;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;


@@ -51,6 +52,16 @@ namespace Tensorflow
py.Dispose(); py.Dispose();
} }
} }

public static (T, T) zip<T>(T t1, T t2, int index = 0) where T : IList<T>
{
return (t1[index], t2[index]);
}

public static (T, T) zip<T>(NDArray t1, NDArray t2, int index = 0)
{
return (t1.Data<T>(index), t2.Data<T>(index));
}
} }


public interface IPython : IDisposable public interface IPython : IDisposable


+ 2
- 2
test/TensorFlowNET.Examples/HelloWorld.cs View File

@@ -25,10 +25,10 @@ namespace TensorFlowNET.Examples
{ {
// Run the op // Run the op
var result = sess.run(hello); var result = sess.run(hello);
Console.WriteLine(result);
Console.WriteLine(result.ToString());
if(!result.ToString().Equals("Hello, TensorFlow!")) if(!result.ToString().Equals("Hello, TensorFlow!"))
{ {
throw new Exception("HelloWorld error");
throw new ValueError("HelloWorld");
} }
} }
} }


+ 12
- 0
test/TensorFlowNET.Examples/LinearRegression.cs View File

@@ -59,6 +59,18 @@ namespace TensorFlowNET.Examples
{ {
// Run the initializer // Run the initializer
sess.run(init); sess.run(init);

// Fit all training data
for (int i = 0; i < training_epochs; i++)
{
for(int index = 0; index < train_X.size; index++)
{
(double x, double y) = Python.zip<double>(train_X, train_Y, index);
var feed_dict = new Dictionary<Tensor, NDArray>();

// sess.run(optimizer, feed_dict);
}
}
}); });
} }
} }


Loading…
Cancel
Save