From 784b1ebee9bbced565e1b8729e110451c30f8bc4 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sun, 31 May 2020 06:55:52 -0500 Subject: [PATCH] remove output for assign_add_variable_op. --- src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs | 3 ++- .../Operations/gen_resource_variable_ops.cs | 8 +++----- src/TensorFlowNET.Core/System/GarbageCollector.cs | 10 +++++----- .../{gen_training_ops.py.cs => gen_training_ops.cs} | 5 ++--- 4 files changed, 12 insertions(+), 14 deletions(-) rename src/TensorFlowNET.Core/Training/{gen_training_ops.py.cs => gen_training_ops.cs} (94%) diff --git a/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs b/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs index e3c018e6..062391c1 100644 --- a/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs +++ b/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs @@ -62,7 +62,8 @@ namespace Tensorflow.Eager GarbageCollector.Decrease(tfe_tensor_handle); GarbageCollector.Decrease(EagerTensorHandle); - /*c_api.TF_DeleteTensor(_handle); + /*print($"deleting DeleteTensorHandle {Id} {_handle.ToString("x16")}"); + c_api.TF_DeleteTensor(_handle); print($"deleting DeleteTensorHandle {Id} {tfe_tensor_handle.ToString("x16")}"); c_api.TFE_DeleteTensorHandle(tfe_tensor_handle); print($"deleting DeleteEagerTensor {Id} {EagerTensorHandle.ToString("x16")}"); diff --git a/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs b/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs index 37e78188..cccf05bc 100644 --- a/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs @@ -56,7 +56,6 @@ namespace Tensorflow { if (tf.context.executing_eagerly()) { - var results = new[] { new EagerTensor() }; Status status = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name, "AssignAddVariableOp", name, new IntPtr[] @@ -64,9 +63,9 @@ namespace Tensorflow resource as EagerTensor, value as EagerTensor }, 2, null, - results.Select(x => x.EagerTensorHandle).ToArray(), results.Length); + null, 0); status.Check(true); - return results[0].Resolve(); + return null; } return null; @@ -76,7 +75,6 @@ namespace Tensorflow { if (tf.context.executing_eagerly()) { - var results = new EagerTensor[0]; Status status = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name, "AssignVariableOp", name, new IntPtr[] @@ -84,7 +82,7 @@ namespace Tensorflow resource as EagerTensor, value as EagerTensor }, 2, null, - results.Select(x => x.EagerTensorHandle).ToArray(), results.Length); + null, 0); status.Check(true); return null; } diff --git a/src/TensorFlowNET.Core/System/GarbageCollector.cs b/src/TensorFlowNET.Core/System/GarbageCollector.cs index cb50b999..32c78d29 100644 --- a/src/TensorFlowNET.Core/System/GarbageCollector.cs +++ b/src/TensorFlowNET.Core/System/GarbageCollector.cs @@ -29,6 +29,9 @@ namespace Tensorflow public static void Increase(IntPtr handle, GCItemType type) { + if (handle == IntPtr.Zero) + return; + if (container.ContainsKey(handle)) { container[handle].RefCounter++; @@ -51,11 +54,8 @@ namespace Tensorflow public static void Decrease(IntPtr handle) { - lock (locker) - { - if (container.ContainsKey(handle)) - container[handle].RefCounter--; - } + if (handle != IntPtr.Zero && container.ContainsKey(handle)) + container[handle].RefCounter--; } private static void Recycle() diff --git a/src/TensorFlowNET.Core/Training/gen_training_ops.py.cs b/src/TensorFlowNET.Core/Training/gen_training_ops.cs similarity index 94% rename from src/TensorFlowNET.Core/Training/gen_training_ops.py.cs rename to src/TensorFlowNET.Core/Training/gen_training_ops.cs index e9d4e854..3a8af24e 100644 --- a/src/TensorFlowNET.Core/Training/gen_training_ops.py.cs +++ b/src/TensorFlowNET.Core/Training/gen_training_ops.cs @@ -65,7 +65,6 @@ namespace Tensorflow { if (tf.context.executing_eagerly()) { - var results = new[] { new EagerTensor() }; Status status = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name, "ResourceApplyGradientDescent", name, new IntPtr[] { @@ -74,9 +73,9 @@ namespace Tensorflow delta }, 3, op => wrap_tfe_src.SetOpAttrs(op, "use_locking", use_locking), - results.Select(x => x.EagerTensorHandle).ToArray(), results.Length); + null, 0); status.Check(true); - return results[0].Resolve(); + return null; } var _op = _op_def_lib._apply_op_helper("ResourceApplyGradientDescent", name, new