Skip to content

Commit 3feff99

Browse files
Extending test to use model and demonstrate memory leak (#858)
* adding saved model cleanup benchmark * less loops so it doesnt waste so much time * testing with a running model * actually calling the model * stopping test from running immediately
1 parent 1460ec8 commit 3feff99

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/TensorFlowNet.Benchmarks/Leak/SavedModelCleanup.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using Tensorflow.NumPy;
910
using static Tensorflow.Binding;
1011

1112
namespace Tensorflow.Benchmark.Leak
@@ -23,9 +24,15 @@ public void Run()
2324

2425
for (var i = 0; i < 1024; i++)
2526
{
26-
using var sess = Session.LoadFromSavedModel(ClassifierModelPath);
27-
// destory graph
28-
using var g = sess.graph;
27+
using (var sess = Session.LoadFromSavedModel(ClassifierModelPath)) {
28+
using (var g = sess.graph.as_default()) {
29+
var inputOp = g.OperationByName("inference_input");
30+
var outputOp = g.OperationByName("StatefulPartitionedCall");
31+
32+
var inp = np.zeros(new Shape(new int[] { 1, 2, 96 }), TF_DataType.TF_FLOAT);
33+
sess.run(outputOp.outputs[0], new FeedItem(inputOp.outputs[0], inp));
34+
}
35+
}
2936
}
3037
}
3138
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy