Browse Source

run LinearRegression but failed.

docs updated.
tags/v0.8.0
Oceania2018 6 years ago
parent
commit
1ddc9b6e78
3 changed files with 27 additions and 4 deletions
  1. +5
    -0
      docs/source/Train.md
  2. +1
    -0
      docs/source/index.rst
  3. +21
    -4
      test/TensorFlowNET.Examples/LinearRegression.cs

+ 5
- 0
docs/source/Train.md View File

@@ -0,0 +1,5 @@
# Chapter. Trainer

### Saver

The `tf.train.saver` class provides methods to save and restore models.

+ 1
- 0
docs/source/index.rst View File

@@ -26,4 +26,5 @@ Welcome to TensorFlow.NET's documentation!
NameScope
ControlDependency
Gradient
Train
EagerMode

+ 21
- 4
test/TensorFlowNET.Examples/LinearRegression.cs View File

@@ -61,15 +61,32 @@ namespace TensorFlowNET.Examples
sess.run(init);

// Fit all training data
for (int i = 0; i < training_epochs; i++)
for (int epoch = 0; epoch < training_epochs; epoch++)
{
foreach(var (x, y) in Python.zip<double>(train_X, train_Y))
foreach (var (x, y) in Python.zip<double>(train_X, train_Y))
{
var feed_dict = new Dictionary<Tensor, NDArray>();
sess.run(optimizer, feed_dict: new FeedItem[]
{
new FeedItem(X, x),
new FeedItem(Y, y)
});
}

// Display logs per epoch step
if ((epoch + 1) % display_step == 0)
{
var c = sess.run(cost, feed_dict: new FeedItem[]
{
new FeedItem(X, train_X),
new FeedItem(Y, train_Y)
});

// sess.run(optimizer, feed_dict);
Console.WriteLine($"Epoch: {epoch + 1} cost={c} " +
$"W={sess.run(W)} b={sess.run(b)}");
}
}

Console.WriteLine("Optimization Finished!");
});
}
}


Loading…
Cancel
Save