You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.8 kB

6 years ago
6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Reflection;
  7. using Tensorflow;
  8. using Console = Colorful.Console;
  9. namespace TensorFlowNET.Examples
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var errors = new List<string>();
  16. var success = new List<string>();
  17. var disabled = new List<string>();
  18. var examples = Assembly.GetEntryAssembly().GetTypes()
  19. .Where(x => x.GetInterfaces().Contains(typeof(IExample)))
  20. .Select(x => (IExample)Activator.CreateInstance(x))
  21. .OrderBy(x => x.Priority)
  22. .ToArray();
  23. Console.WriteLine($"TensorFlow v{tf.VERSION}", Color.Yellow);
  24. Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow);
  25. var sw = new Stopwatch();
  26. foreach (IExample example in examples)
  27. {
  28. if (args.Length > 0 && !args.Contains(example.Name))
  29. continue;
  30. Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);
  31. try
  32. {
  33. if (example.Enabled || args.Length > 0) // if a specific example was specified run it, regardless of enabled value
  34. {
  35. sw.Restart();
  36. bool isSuccess = example.Run();
  37. sw.Stop();
  38. if (isSuccess)
  39. success.Add($"Example {example.Priority}: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  40. else
  41. errors.Add($"Example {example.Priority}: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  42. }
  43. else
  44. {
  45. disabled.Add($"Example {example.Priority}: {example.Name} in {sw.ElapsedMilliseconds}ms");
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. errors.Add($"Example {example.Priority}: {example.Name}");
  51. Console.WriteLine(ex);
  52. }
  53. Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
  54. }
  55. success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
  56. disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan));
  57. errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));
  58. Console.Write("Please [Enter] to quit.");
  59. Console.ReadLine();
  60. }
  61. }
  62. }