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

6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Console = Colorful.Console;
  8. namespace TensorFlowNET.Examples
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var assembly = Assembly.GetEntryAssembly();
  15. var errors = new List<string>();
  16. var success = new List<string>();
  17. var disabled = new List<string>();
  18. var examples = assembly.GetTypes()
  19. .Where(x => x.GetInterfaces().Contains(typeof(IExample)))
  20. .Select(x => (IExample)Activator.CreateInstance(x))
  21. .OrderBy(x => x.Priority)
  22. .ToArray();
  23. var sw = new Stopwatch();
  24. foreach (IExample example in examples)
  25. {
  26. if (args.Length > 0 && !args.Contains(example.Name))
  27. continue;
  28. Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);
  29. try
  30. {
  31. if (example.Enabled)
  32. {
  33. sw.Restart();
  34. bool isSuccess = example.Run();
  35. sw.Stop();
  36. if (isSuccess)
  37. success.Add($"Example {example.Priority}: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  38. else
  39. errors.Add($"Example {example.Priority}: {example.Name} in {sw.Elapsed.TotalSeconds}s");
  40. }
  41. else
  42. {
  43. disabled.Add($"Example {example.Priority}: {example.Name} in {sw.ElapsedMilliseconds}ms");
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. errors.Add($"Example {example.Priority}: {example.Name}");
  49. Console.WriteLine(ex);
  50. }
  51. Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
  52. }
  53. success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
  54. disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan));
  55. errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));
  56. Console.ReadLine();
  57. }
  58. }
  59. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。