From ecc49236284ccf3d41659ee43c66008053c8ecc4 Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Thu, 11 Apr 2019 18:31:33 +0200 Subject: [PATCH] minor changes in examples --- .../KMeansClustering.cs | 11 ++++++----- .../LinearRegression.cs | 6 +++--- .../LogisticRegression.cs | 19 ++++++++++--------- .../ExamplesTests/ExamplesTest.cs | 4 ++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/test/TensorFlowNET.Examples/KMeansClustering.cs b/test/TensorFlowNET.Examples/KMeansClustering.cs index b7c80b89..b09e38fc 100644 --- a/test/TensorFlowNET.Examples/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/KMeansClustering.cs @@ -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; } } diff --git a/test/TensorFlowNET.Examples/LinearRegression.cs b/test/TensorFlowNET.Examples/LinearRegression.cs index 83764f40..a17d6e2b 100644 --- a/test/TensorFlowNET.Examples/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/LinearRegression.cs @@ -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(train_X, train_Y)) { diff --git a/test/TensorFlowNET.Examples/LogisticRegression.cs b/test/TensorFlowNET.Examples/LogisticRegression.cs index 944df714..1646f149 100644 --- a/test/TensorFlowNET.Examples/LogisticRegression.cs +++ b/test/TensorFlowNET.Examples/LogisticRegression.cs @@ -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) diff --git a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs index 5c74320f..df2cf3c8 100644 --- a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs +++ b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs @@ -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]