From 2a2a1e169aa0f857d1bb543c8965707dbbc83ab7 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 13 Jul 2019 15:10:27 -0500 Subject: [PATCH] run example easier #290 --- .../BasicModels/KMeansClustering.cs | 2 +- .../ImageProcessing/ImageBackgroundRemoval.cs | 2 +- test/TensorFlowNET.Examples/Program.cs | 40 +++++++++---------- .../BinaryTextClassification.cs | 2 +- .../TextProcessing/NER/BiLstmCrfNer.cs | 2 +- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs index d60b0f8e..085a92e0 100644 --- a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs @@ -34,7 +34,7 @@ namespace TensorFlowNET.Examples /// public class KMeansClustering : IExample { - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; public string Name => "K-means Clustering"; public bool IsImportingGraph { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs index 12fd526f..46f6b6bf 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs @@ -15,7 +15,7 @@ namespace TensorFlowNET.Examples.ImageProcess /// public class ImageBackgroundRemoval : IExample { - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; public bool IsImportingGraph { get; set; } = true; public string Name => "Image Background Removal"; diff --git a/test/TensorFlowNET.Examples/Program.cs b/test/TensorFlowNET.Examples/Program.cs index 1e001b0c..b0e56c4c 100644 --- a/test/TensorFlowNET.Examples/Program.cs +++ b/test/TensorFlowNET.Examples/Program.cs @@ -31,55 +31,53 @@ namespace TensorFlowNET.Examples { var errors = new List(); var success = new List(); - var disabled = new List(); var examples = Assembly.GetEntryAssembly().GetTypes() .Where(x => x.GetInterfaces().Contains(typeof(IExample))) .Select(x => (IExample)Activator.CreateInstance(x)) + .Where(x => x.Enabled) + .OrderBy(x => x.Name) .ToArray(); - Console.WriteLine($"TensorFlow v{tf.VERSION}", Color.Yellow); + Console.WriteLine(Environment.OSVersion.ToString(), Color.Yellow); + Console.WriteLine($"TensorFlow Binary v{tf.VERSION}", Color.Yellow); Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow); + for (var i = 0; i < examples.Length; i++) + Console.WriteLine($"[{i}]: {examples[i].Name}"); + Console.Write($"Choose one example to run, hit [Enter] to run all: ", Color.Yellow); + var key = Console.ReadLine(); + var sw = new Stopwatch(); - foreach (IExample example in examples) + for (var i = 0; i < examples.Length; i++) { - if (args.Length > 0 && !args.Contains(example.Name)) - continue; + if (i.ToString() != key && key != "") continue; + var example = examples[i]; Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White); try { - if (example.Enabled || args.Length > 0) // if a specific example was specified run it, regardless of enabled value - { - sw.Restart(); - bool isSuccess = example.Run(); - sw.Stop(); + sw.Restart(); + bool isSuccess = example.Run(); + sw.Stop(); - if (isSuccess) - success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s"); - else - errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s"); - } + if (isSuccess) + success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s"); else - { - disabled.Add($"Example: {example.Name} in {sw.ElapsedMilliseconds}ms"); - } + errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s"); } catch (Exception ex) { errors.Add($"Example: {example.Name}"); Console.WriteLine(ex); } - + Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White); } success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green)); - disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan)); errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red)); - Console.Write("Please [Enter] to quit."); Console.ReadLine(); } } diff --git a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs index 5f81e12d..791c17b8 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs @@ -17,7 +17,7 @@ namespace TensorFlowNET.Examples /// public class BinaryTextClassification : IExample { - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; public string Name => "Binary Text Classification"; public bool IsImportingGraph { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs b/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs index cb3aa30e..1a96d24c 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs @@ -14,7 +14,7 @@ namespace TensorFlowNET.Examples /// public class BiLstmCrfNer : IExample { - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = false; public bool IsImportingGraph { get; set; } = false; public string Name => "bi-LSTM + CRF NER";