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.6 kB

6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. .ToArray();
  22. Console.WriteLine($"TensorFlow v{tf.VERSION}", Color.Yellow);
  23. Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow);
  24. var sw = new Stopwatch();
  25. foreach (IExample example in examples)
  26. {
  27. if (args.Length > 0 && !args.Contains(example.Name))
  28. continue;
  29. Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);
  30. try
  31. {
  32. if (example.Enabled || args.Length > 0) // if a specific example was specified run it, regardless of enabled value
  33. {
  34. sw.Restart();
  35. bool isSuccess = example.Run();
  36. sw.Stop();
  37. if (isSuccess)
  38. success.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  39. else
  40. errors.Add($"Example: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  41. }
  42. else
  43. {
  44. disabled.Add($"Example: {example.Name} in {sw.ElapsedMilliseconds}ms");
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. errors.Add($"Example: {example.Name}");
  50. Console.WriteLine(ex);
  51. }
  52. Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
  53. }
  54. success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
  55. disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan));
  56. errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));
  57. Console.Write("Please [Enter] to quit.");
  58. Console.ReadLine();
  59. }
  60. }
  61. }