forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (61 loc) · 2.57 KB
/
Program.cs
File metadata and controls
70 lines (61 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using Tensorflow;
using Console = Colorful.Console;
namespace TensorFlowNET.Examples
{
class Program
{
static void Main(string[] args)
{
var errors = new List<string>();
var success = new List<string>();
var disabled = new List<string>();
var examples = Assembly.GetEntryAssembly().GetTypes()
.Where(x => x.GetInterfaces().Contains(typeof(IExample)))
.Select(x => (IExample)Activator.CreateInstance(x))
.ToArray();
Console.WriteLine($"TensorFlow v{tf.VERSION}", Color.Yellow);
Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow);
var sw = new Stopwatch();
foreach (IExample example in examples)
{
if (args.Length > 0 && !args.Contains(example.Name))
continue;
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();
if (isSuccess)
success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
else
errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
}
else
{
disabled.Add($"Example: {example.Name} in {sw.ElapsedMilliseconds}ms");
}
}
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();
}
}
}