Skip to content

Commit 0513d98

Browse files
authored
Merge pull request SciSharp#224 from henon/master
unit test suite: added lightweight version of all examples
2 parents 98c7dbf + abc9908 commit 0513d98

20 files changed

+163
-46
lines changed

src/TensorFlowNET.Core/Python.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void with(IPython py, Action<IPython> action)
4646
catch (Exception ex)
4747
{
4848
Console.WriteLine(ex.ToString());
49-
throw ex;
49+
throw;
5050
}
5151
finally
5252
{
@@ -65,7 +65,7 @@ public static void with<T>(T py, Action<T> action) where T : IPython
6565
catch (Exception ex)
6666
{
6767
Console.WriteLine(ex.ToString());
68-
throw ex;
68+
throw;
6969
}
7070
finally
7171
{
@@ -83,10 +83,8 @@ public static TOut with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn : I
8383
}
8484
catch (Exception ex)
8585
{
86-
Console.WriteLine(ex.ToString());
87-
#if DEBUG
88-
Debugger.Break();
89-
#endif
86+
Console.WriteLine(ex.ToString());
87+
throw;
9088
return default(TOut);
9189
}
9290
finally

test/TensorFlowNET.Examples/BasicEagerApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples
1212
public class BasicEagerApi : IExample
1313
{
1414
public int Priority => 100;
15-
public bool Enabled => false;
15+
public bool Enabled { get; set; } = false;
1616
public string Name => "Basic Eager";
1717

1818
private Tensor a, b, c, d;

test/TensorFlowNET.Examples/BasicOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples
1212
/// </summary>
1313
public class BasicOperations : Python, IExample
1414
{
15-
public bool Enabled => true;
15+
public bool Enabled { get; set; } = true;
1616
public int Priority => 2;
1717
public string Name => "Basic Operations";
1818

test/TensorFlowNET.Examples/HelloWorld.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples
1212
public class HelloWorld : Python, IExample
1313
{
1414
public int Priority => 1;
15-
public bool Enabled => true;
15+
public bool Enabled { get; set; } = true;
1616
public string Name => "Hello World";
1717

1818
public bool Run()

test/TensorFlowNET.Examples/IExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IExample
1717
/// <summary>
1818
/// True to run example
1919
/// </summary>
20-
bool Enabled { get; }
20+
bool Enabled { get; set; }
2121

2222
string Name { get; }
2323

test/TensorFlowNET.Examples/ImageRecognition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace TensorFlowNET.Examples
1313
public class ImageRecognition : Python, IExample
1414
{
1515
public int Priority => 7;
16-
public bool Enabled => true;
16+
public bool Enabled { get; set; } = true;
1717
public string Name => "Image Recognition";
1818

1919
string dir = "ImageRecognition";

test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace TensorFlowNET.Examples
1919
/// </summary>
2020
public class InceptionArchGoogLeNet : Python, IExample
2121
{
22-
public bool Enabled => false;
22+
public bool Enabled { get; set; } = false;
2323
public int Priority => 100;
2424
public string Name => "Inception Arch GoogLeNet";
2525

test/TensorFlowNET.Examples/KMeansClustering.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ namespace TensorFlowNET.Examples
1616
public class KMeansClustering : Python, IExample
1717
{
1818
public int Priority => 8;
19-
public bool Enabled => true;
19+
public bool Enabled { get; set; } = true;
2020
public string Name => "K-means Clustering";
2121

22+
public int? train_size = null;
23+
public int validation_size = 5000;
24+
public int? test_size = null;
25+
public int batch_size = 1024; // The number of samples per batch
26+
2227
Datasets mnist;
2328
NDArray full_data_x;
2429
int num_steps = 50; // Total steps to train
25-
int batch_size = 1024; // The number of samples per batch
2630
int k = 25; // The number of clusters
2731
int num_classes = 10; // The 10 digits
2832
int num_features = 784; // Each image is 28x28 pixels
@@ -45,7 +49,7 @@ public bool Run()
4549

4650
public void PrepareData()
4751
{
48-
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true);
52+
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, train_size: train_size, validation_size:validation_size, test_size:test_size);
4953
full_data_x = mnist.train.images;
5054
}
5155
}

test/TensorFlowNET.Examples/LinearRegression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ namespace TensorFlowNET.Examples
1313
public class LinearRegression : Python, IExample
1414
{
1515
public int Priority => 3;
16-
public bool Enabled => true;
16+
public bool Enabled { get; set; } = true;
1717
public string Name => "Linear Regression";
1818

19-
NumPyRandom rng = np.random;
19+
public int training_epochs = 1000;
2020

2121
// Parameters
2222
float learning_rate = 0.01f;
23-
int training_epochs = 1000;
2423
int display_step = 50;
2524

25+
NumPyRandom rng = np.random;
2626
NDArray train_X, train_Y;
2727
int n_samples;
2828

test/TensorFlowNET.Examples/LogisticRegression.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ namespace TensorFlowNET.Examples
1717
public class LogisticRegression : Python, IExample
1818
{
1919
public int Priority => 4;
20-
public bool Enabled => true;
20+
public bool Enabled { get; set; } = true;
2121
public string Name => "Logistic Regression";
2222

23+
public int training_epochs = 10;
24+
public int? train_size = null;
25+
public int validation_size = 5000;
26+
public int? test_size = null;
27+
public int batch_size = 100;
28+
2329
private float learning_rate = 0.01f;
24-
private int training_epochs = 10;
25-
private int batch_size = 100;
2630
private int display_step = 1;
2731

2832
Datasets mnist;
@@ -96,7 +100,7 @@ public bool Run()
96100

97101
public void PrepareData()
98102
{
99-
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true);
103+
mnist = MnistDataSet.read_data_sets("mnist", one_hot: true, train_size: train_size, validation_size: validation_size, test_size: test_size);
100104
}
101105

102106
public void SaveModel(Session sess)
@@ -139,7 +143,7 @@ public void Predict()
139143
if (results.argmax() == (batch_ys[0] as NDArray).argmax())
140144
print("predicted OK!");
141145
else
142-
throw new ValueError("predict error, maybe 90% accuracy");
146+
throw new ValueError("predict error, should be 90% accuracy");
143147
});
144148
}
145149
}

0 commit comments

Comments
 (0)