Skip to content

Commit 2a2a1e1

Browse files
committed
run example easier #290
1 parent a79382b commit 2a2a1e1

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace TensorFlowNET.Examples
3434
/// </summary>
3535
public class KMeansClustering : IExample
3636
{
37-
public bool Enabled { get; set; } = true;
37+
public bool Enabled { get; set; } = false;
3838
public string Name => "K-means Clustering";
3939
public bool IsImportingGraph { get; set; } = true;
4040

test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace TensorFlowNET.Examples.ImageProcess
1515
/// </summary>
1616
public class ImageBackgroundRemoval : IExample
1717
{
18-
public bool Enabled { get; set; } = true;
18+
public bool Enabled { get; set; } = false;
1919
public bool IsImportingGraph { get; set; } = true;
2020

2121
public string Name => "Image Background Removal";

test/TensorFlowNET.Examples/Program.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,53 @@ static void Main(string[] args)
3131
{
3232
var errors = new List<string>();
3333
var success = new List<string>();
34-
var disabled = new List<string>();
3534
var examples = Assembly.GetEntryAssembly().GetTypes()
3635
.Where(x => x.GetInterfaces().Contains(typeof(IExample)))
3736
.Select(x => (IExample)Activator.CreateInstance(x))
37+
.Where(x => x.Enabled)
38+
.OrderBy(x => x.Name)
3839
.ToArray();
3940

40-
Console.WriteLine($"TensorFlow v{tf.VERSION}", Color.Yellow);
41+
Console.WriteLine(Environment.OSVersion.ToString(), Color.Yellow);
42+
Console.WriteLine($"TensorFlow Binary v{tf.VERSION}", Color.Yellow);
4143
Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow);
4244

45+
for (var i = 0; i < examples.Length; i++)
46+
Console.WriteLine($"[{i}]: {examples[i].Name}");
47+
Console.Write($"Choose one example to run, hit [Enter] to run all: ", Color.Yellow);
48+
var key = Console.ReadLine();
49+
4350
var sw = new Stopwatch();
44-
foreach (IExample example in examples)
51+
for (var i = 0; i < examples.Length; i++)
4552
{
46-
if (args.Length > 0 && !args.Contains(example.Name))
47-
continue;
53+
if (i.ToString() != key && key != "") continue;
4854

55+
var example = examples[i];
4956
Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);
5057

5158
try
5259
{
53-
if (example.Enabled || args.Length > 0) // if a specific example was specified run it, regardless of enabled value
54-
{
55-
sw.Restart();
56-
bool isSuccess = example.Run();
57-
sw.Stop();
60+
sw.Restart();
61+
bool isSuccess = example.Run();
62+
sw.Stop();
5863

59-
if (isSuccess)
60-
success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
61-
else
62-
errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
63-
}
64+
if (isSuccess)
65+
success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
6466
else
65-
{
66-
disabled.Add($"Example: {example.Name} in {sw.ElapsedMilliseconds}ms");
67-
}
67+
errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
6868
}
6969
catch (Exception ex)
7070
{
7171
errors.Add($"Example: {example.Name}");
7272
Console.WriteLine(ex);
7373
}
74-
74+
7575
Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
7676
}
7777

7878
success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
79-
disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan));
8079
errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));
8180

82-
Console.Write("Please [Enter] to quit.");
8381
Console.ReadLine();
8482
}
8583
}

test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace TensorFlowNET.Examples
1717
/// </summary>
1818
public class BinaryTextClassification : IExample
1919
{
20-
public bool Enabled { get; set; } = true;
20+
public bool Enabled { get; set; } = false;
2121
public string Name => "Binary Text Classification";
2222
public bool IsImportingGraph { get; set; } = true;
2323

test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace TensorFlowNET.Examples
1414
/// </summary>
1515
public class BiLstmCrfNer : IExample
1616
{
17-
public bool Enabled { get; set; } = true;
17+
public bool Enabled { get; set; } = false;
1818
public bool IsImportingGraph { get; set; } = false;
1919

2020
public string Name => "bi-LSTM + CRF NER";

0 commit comments

Comments
 (0)