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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using Tensorflow.Keras;
  3. using static Tensorflow.Binding;
  4. namespace Tensorflow
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var diag = new Diagnostician();
  11. // diag.Diagnose(@"D:\memory.txt");
  12. var rnn = new SimpleRnnTest();
  13. rnn.Run();
  14. // this class is used explor new features.
  15. var exploring = new Exploring();
  16. // exploring.Run();
  17. // boot .net core 10.5M.
  18. var mm = new MemoryMonitor();
  19. // warm up tensorflow.net 37.3M.
  20. mm.WarmUp();
  21. BasicTest(mm);
  22. KerasTest(mm);
  23. FuncGraph(mm);
  24. // 65M
  25. Console.WriteLine("Finished.");
  26. Console.ReadLine();
  27. }
  28. static void BasicTest(MemoryMonitor mm)
  29. {
  30. int batchSize = 1000;
  31. var basic = new MemoryBasicTest();
  32. // 1 million placeholder
  33. /*tf.compat.v1.disable_eager_execution();
  34. mm.Execute(10, 100 * batchSize, basic.Placeholder);
  35. tf.enable_eager_execution();*/
  36. // 1 million tensor
  37. mm.Execute(10, 100 * batchSize, basic.Constant);
  38. // explaination of constant
  39. mm.Execute(10, 100 * batchSize, basic.Constant2x3);
  40. mm.Execute(10, batchSize, basic.ConstantString);
  41. // 100K float variable.
  42. mm.Execute(10, batchSize, basic.Variable);
  43. mm.Execute(10, batchSize, basic.VariableRead);
  44. mm.Execute(10, batchSize, basic.VariableAssign);
  45. // 1 million math.
  46. mm.Execute(10, 100 * batchSize, basic.MathAdd);
  47. // Conv2d in constant tensor
  48. mm.Execute(10, batchSize, basic.Conv2DWithTensor);
  49. // Conv2d in variable
  50. mm.Execute(10, batchSize, basic.Conv2DWithVariable);
  51. // 100K gradient 44M.
  52. mm.Execute(10, 10 * batchSize, basic.Gradient);
  53. // memory leak when increasing the epoch
  54. mm.Execute(10, 10, basic.Dataset);
  55. }
  56. static void KerasTest(MemoryMonitor mm)
  57. {
  58. var keras = new MemoryKerasTest();
  59. // +1M (10,50)
  60. mm.Execute(10, 1, keras.Conv2DLayer);
  61. mm.Execute(10, 50, keras.InputLayer);
  62. mm.Execute(10, 10, keras.Prediction);
  63. }
  64. static void FuncGraph(MemoryMonitor mm)
  65. {
  66. var func = new MemoryFuncGraphTest();
  67. mm.Execute(10, 100, func.ConcreteFunction);
  68. }
  69. }
  70. }