diff --git a/src/TensorFlowNET.Core/Eager/EagerTensor.cs b/src/TensorFlowNET.Core/Eager/EagerTensor.cs index 5761ce6e..bddd8188 100644 --- a/src/TensorFlowNET.Core/Eager/EagerTensor.cs +++ b/src/TensorFlowNET.Core/Eager/EagerTensor.cs @@ -1,15 +1,21 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; +using Tensorflow.Util; using static Tensorflow.Binding; namespace Tensorflow.Eager { public partial class EagerTensor : Tensor { - public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); + public override string Device + { + get + { + using var _ = EagerTensorHandle.Lease(); + return c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); + } + } public override int rank => c_api.TFE_TensorHandleNumDims(EagerTensorHandle, tf.status.Handle); diff --git a/src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs b/src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs index b2ba7f28..db6bcb85 100644 --- a/src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs +++ b/src/TensorFlowNET.Core/Tensors/EagerTensorV2.cs @@ -1,11 +1,8 @@ using NumSharp; using System; -using System.Collections.Generic; using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; using Tensorflow.Eager; +using Tensorflow.Util; using static Tensorflow.Binding; namespace Tensorflow @@ -13,7 +10,14 @@ namespace Tensorflow public class EagerTensorV2 : DisposableObject, ITensor { SafeTensorHandleHandle EagerTensorHandle; - public string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); + public string Device + { + get + { + using var _ = EagerTensorHandle.Lease(); + return c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(EagerTensorHandle, tf.status.Handle)); + } + } public EagerTensorV2(IntPtr handle) {