Browse Source

run example easier #290

tags/v0.10
Oceania2018 6 years ago
parent
commit
2a2a1e169a
5 changed files with 23 additions and 25 deletions
  1. +1
    -1
      test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs
  2. +1
    -1
      test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs
  3. +19
    -21
      test/TensorFlowNET.Examples/Program.cs
  4. +1
    -1
      test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs
  5. +1
    -1
      test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs

+ 1
- 1
test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs View File

@@ -34,7 +34,7 @@ namespace TensorFlowNET.Examples
/// </summary> /// </summary>
public class KMeansClustering : IExample public class KMeansClustering : IExample
{ {
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
public string Name => "K-means Clustering"; public string Name => "K-means Clustering";
public bool IsImportingGraph { get; set; } = true; public bool IsImportingGraph { get; set; } = true;




+ 1
- 1
test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs View File

@@ -15,7 +15,7 @@ namespace TensorFlowNET.Examples.ImageProcess
/// </summary> /// </summary>
public class ImageBackgroundRemoval : IExample public class ImageBackgroundRemoval : IExample
{ {
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
public bool IsImportingGraph { get; set; } = true; public bool IsImportingGraph { get; set; } = true;


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


+ 19
- 21
test/TensorFlowNET.Examples/Program.cs View File

@@ -31,55 +31,53 @@ namespace TensorFlowNET.Examples
{ {
var errors = new List<string>(); var errors = new List<string>();
var success = new List<string>(); var success = new List<string>();
var disabled = new List<string>();
var examples = Assembly.GetEntryAssembly().GetTypes() var examples = Assembly.GetEntryAssembly().GetTypes()
.Where(x => x.GetInterfaces().Contains(typeof(IExample))) .Where(x => x.GetInterfaces().Contains(typeof(IExample)))
.Select(x => (IExample)Activator.CreateInstance(x)) .Select(x => (IExample)Activator.CreateInstance(x))
.Where(x => x.Enabled)
.OrderBy(x => x.Name)
.ToArray(); .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); 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(); 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); Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);


try 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 else
{
disabled.Add($"Example: {example.Name} in {sw.ElapsedMilliseconds}ms");
}
errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
} }
catch (Exception ex) catch (Exception ex)
{ {
errors.Add($"Example: {example.Name}"); errors.Add($"Example: {example.Name}");
Console.WriteLine(ex); Console.WriteLine(ex);
} }
Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White); Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
} }


success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green)); 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)); errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));


Console.Write("Please [Enter] to quit.");
Console.ReadLine(); Console.ReadLine();
} }
} }


+ 1
- 1
test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs View File

@@ -17,7 +17,7 @@ namespace TensorFlowNET.Examples
/// </summary> /// </summary>
public class BinaryTextClassification : IExample public class BinaryTextClassification : IExample
{ {
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
public string Name => "Binary Text Classification"; public string Name => "Binary Text Classification";
public bool IsImportingGraph { get; set; } = true; public bool IsImportingGraph { get; set; } = true;




+ 1
- 1
test/TensorFlowNET.Examples/TextProcessing/NER/BiLstmCrfNer.cs View File

@@ -14,7 +14,7 @@ namespace TensorFlowNET.Examples
/// </summary> /// </summary>
public class BiLstmCrfNer : IExample public class BiLstmCrfNer : IExample
{ {
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
public bool IsImportingGraph { get; set; } = false; public bool IsImportingGraph { get; set; } = false;


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


Loading…
Cancel
Save