Browse Source

minor changes in examples

tags/v0.9
Meinrad Recheis 6 years ago
parent
commit
ecc4923628
4 changed files with 21 additions and 19 deletions
  1. +6
    -5
      test/TensorFlowNET.Examples/KMeansClustering.cs
  2. +3
    -3
      test/TensorFlowNET.Examples/LinearRegression.cs
  3. +10
    -9
      test/TensorFlowNET.Examples/LogisticRegression.cs
  4. +2
    -2
      test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs

+ 6
- 5
test/TensorFlowNET.Examples/KMeansClustering.cs View File

@@ -18,14 +18,15 @@ namespace TensorFlowNET.Examples
public int Priority => 8;
public bool Enabled { get; set; } = true;
public string Name => "K-means Clustering";
public int DataSize = 5000;
public int TestSize = 5000;
public int BatchSize = 100;

public int? train_size = null;
public int validation_size = 5000;
public int? test_size = null;
public int batch_size = 1024; // The number of samples per batch

Datasets mnist;
NDArray full_data_x;
int num_steps = 50; // Total steps to train
int batch_size = 1024; // The number of samples per batch
int k = 25; // The number of clusters
int num_classes = 10; // The 10 digits
int num_features = 784; // Each image is 28x28 pixels
@@ -48,7 +49,7 @@ namespace TensorFlowNET.Examples

public void PrepareData()
{
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, validation_size: DataSize, test_size:TestSize);
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, train_size: train_size, validation_size:validation_size, test_size:test_size);
full_data_x = mnist.train.images;
}
}


+ 3
- 3
test/TensorFlowNET.Examples/LinearRegression.cs View File

@@ -16,13 +16,13 @@ namespace TensorFlowNET.Examples
public bool Enabled { get; set; } = true;
public string Name => "Linear Regression";

NumPyRandom rng = np.random;
public int training_epochs = 1000;

// Parameters
float learning_rate = 0.01f;
public int TrainingEpochs = 1000;
int display_step = 50;

NumPyRandom rng = np.random;
NDArray train_X, train_Y;
int n_samples;

@@ -62,7 +62,7 @@ namespace TensorFlowNET.Examples
sess.run(init);

// Fit all training data
for (int epoch = 0; epoch < TrainingEpochs; epoch++)
for (int epoch = 0; epoch < training_epochs; epoch++)
{
foreach (var (x, y) in zip<float>(train_X, train_Y))
{


+ 10
- 9
test/TensorFlowNET.Examples/LogisticRegression.cs View File

@@ -20,12 +20,13 @@ namespace TensorFlowNET.Examples
public bool Enabled { get; set; } = true;
public string Name => "Logistic Regression";

public int training_epochs = 10;
public int? train_size = null;
public int validation_size = 5000;
public int? test_size = null;
public int batch_size = 100;

private float learning_rate = 0.01f;
public int TrainingEpochs = 10;
public int? TrainSize = null;
public int ValidationSize = 5000;
public int? TestSize = null;
public int BatchSize = 100;
private int display_step = 1;

Datasets mnist;
@@ -60,14 +61,14 @@ namespace TensorFlowNET.Examples
sess.run(init);

// Training cycle
foreach (var epoch in range(TrainingEpochs))
foreach (var epoch in range(training_epochs))
{
var avg_cost = 0.0f;
var total_batch = mnist.train.num_examples / BatchSize;
var total_batch = mnist.train.num_examples / batch_size;
// Loop over all batches
foreach (var i in range(total_batch))
{
var (batch_xs, batch_ys) = mnist.train.next_batch(BatchSize);
var (batch_xs, batch_ys) = mnist.train.next_batch(batch_size);
// Run optimization op (backprop) and cost op (to get loss value)
var result = sess.run(new object[] { optimizer, cost },
new FeedItem(x, batch_xs),
@@ -99,7 +100,7 @@ namespace TensorFlowNET.Examples

public void PrepareData()
{
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, train_size: TrainSize, validation_size: ValidationSize, test_size: TestSize);
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, train_size: train_size, validation_size: validation_size, test_size: test_size);
}

public void SaveModel(Session sess)


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

@@ -39,7 +39,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod]
public void KMeansClustering()
{
new KMeansClustering() { Enabled = true }.Run();
new KMeansClustering() { Enabled = true, train_size = 500, validation_size = 100, test_size = 100, batch_size =100 }.Run();
}
[TestMethod]
@@ -51,7 +51,7 @@ namespace TensorFlowNET.UnitTest.ExamplesTests
[TestMethod]
public void LogisticRegression()
{
new LogisticRegression() { Enabled = true, TrainingEpochs=10, TrainSize = 500, ValidationSize = 100, TestSize = 100 }.Run();
new LogisticRegression() { Enabled = true, training_epochs=10, train_size = 500, validation_size = 100, test_size = 100 }.Run();
}
[Ignore]


Loading…
Cancel
Save