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.

SavedModelCleanup.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using BenchmarkDotNet.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Tensorflow.NumPy;
  10. using static Tensorflow.Binding;
  11. namespace Tensorflow.Benchmark.Leak
  12. {
  13. /// <summary>
  14. /// https://github.com/SciSharp/TensorFlow.NET/issues/418
  15. /// </summary>
  16. public class SavedModelCleanup
  17. {
  18. [Benchmark]
  19. public void Run()
  20. {
  21. var modelDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  22. var ClassifierModelPath = Path.Combine(modelDir, "Leak", "TestModel", "saved_model");
  23. for (var i = 0; i < 1024; i++)
  24. {
  25. var sess = Session.LoadFromSavedModel(ClassifierModelPath);
  26. var g = sess.graph.as_default();
  27. var inputOp = g.OperationByName("inference_input");
  28. var outputOp = g.OperationByName("StatefulPartitionedCall");
  29. var inp = np.zeros(new Shape(new int[] { 1, 2, 96 }), TF_DataType.TF_FLOAT);
  30. sess.run(outputOp.outputs[0], new FeedItem(inputOp.outputs[0], inp));
  31. }
  32. }
  33. }
  34. }