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

6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Reflection;
  6. using Console = Colorful.Console;
  7. namespace TensorFlowNET.Examples
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var assembly = Assembly.GetEntryAssembly();
  14. var errors = new List<string>();
  15. var success = new List<string>();
  16. var disabled = new List<string>();
  17. var examples = assembly.GetTypes()
  18. .Where(x => x.GetInterfaces().Contains(typeof(IExample)))
  19. .Select(x => (IExample)Activator.CreateInstance(x))
  20. .OrderBy(x => x.Priority)
  21. .ToArray();
  22. foreach (IExample example in examples)
  23. {
  24. if (args.Length > 0 && !args.Contains(example.Name))
  25. continue;
  26. Console.WriteLine($"{DateTime.UtcNow} Starting {example.Name}", Color.White);
  27. try
  28. {
  29. if (example.Enabled)
  30. if (example.Run())
  31. success.Add($"Example {example.Priority}: {example.Name}");
  32. else
  33. errors.Add($"Example {example.Priority}: {example.Name}");
  34. else
  35. disabled.Add($"Example {example.Priority}: {example.Name}");
  36. }
  37. catch (Exception ex)
  38. {
  39. errors.Add($"Example {example.Priority}: {example.Name}");
  40. Console.WriteLine(ex);
  41. }
  42. Console.WriteLine($"{DateTime.UtcNow} Completed {example.Name}", Color.White);
  43. }
  44. success.ForEach(x => Console.WriteLine($"{x} is OK!", Color.Green));
  45. disabled.ForEach(x => Console.WriteLine($"{x} is Disabled!", Color.Tan));
  46. errors.ForEach(x => Console.WriteLine($"{x} is Failed!", Color.Red));
  47. Console.ReadLine();
  48. }
  49. }
  50. }

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