Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Microsoft.ML.Dnn/DnnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ public Runner AddInput(Tensor value, int index)
return this;
}

public List<Tensor> GetInputValues()
{
return _inputValues;
}

public Runner AddOutputs(string output)
{
_outputs.Add(ParseOutput(output));
Expand Down
13 changes: 12 additions & 1 deletion src/Microsoft.ML.TensorFlow/TensorflowTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ private void Dispose(bool disposing)
{
Session.close(); // invoked Dispose()
}

if (Session != null && Session.graph != IntPtr.Zero)
{
Session.graph.Dispose();
}
}
finally
{
Expand Down Expand Up @@ -645,7 +650,7 @@ private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGe
Runner runner = new Runner(_parent.Session);

// Feed inputs to the graph.
for (int i = 0; i < _parent.Inputs.Length; i++)
for (int i = 0; i < _parent.Inputs.Length; i++)
{
var tensor = srcTensorGetters[i].GetTensor();
runner.AddInput(_parent.Inputs[i], tensor);
Expand All @@ -658,6 +663,12 @@ private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGe
// Execute the graph.
var tensors = runner.Run();

List<Tensor> inputTensors = runner.GetInputValues();
foreach (Tensor inputTensor in inputTensors)
{
inputTensor.Dispose();
}

Contracts.Assert(tensors.Length > 0);

for (int j = 0; j < activeOutputColNames.Length; j++)
Expand Down