From 8f32e831c060832f8990cc1480626554fbc93326 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 28 Aug 2021 08:03:06 -0500 Subject: [PATCH] EagerTensor from EagerTensor --- src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs | 5 +++++ src/TensorFlowNET.Core/Graphs/Graph.cs | 4 ++-- src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs | 8 ++------ src/TensorFlowNET.Core/Numpy/NDArray.cs | 3 --- src/TensorFlowNET.Core/Tensorflow.Binding.csproj | 6 +++--- src/TensorFlowNET.Core/ops.cs | 6 ++++++ src/TensorFlowNET.Keras/Tensorflow.Keras.csproj | 6 +++--- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs b/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs index e23e8aa5..fa7309e3 100644 --- a/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs +++ b/src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs @@ -7,6 +7,11 @@ namespace Tensorflow.Eager { public partial class EagerTensor { + public EagerTensor(SafeTensorHandle handle) + { + NewEagerTensorHandle(handle); + } + public EagerTensor(SafeTensorHandleHandle handle) { _id = ops.uid(); diff --git a/src/TensorFlowNET.Core/Graphs/Graph.cs b/src/TensorFlowNET.Core/Graphs/Graph.cs index ff05aad9..83afaf04 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.cs @@ -127,7 +127,7 @@ namespace Tensorflow _nodes_by_id = new Dictionary(); _nodes_by_name = new Dictionary(); _names_in_use = new Dictionary(); - _graph_key = $"grap-key-{ops.uid()}/"; + _graph_key = $"graph-{ops.GraphUniqueId()}/"; } public Graph(IntPtr handle) @@ -136,7 +136,7 @@ namespace Tensorflow _nodes_by_id = new Dictionary(); _nodes_by_name = new Dictionary(); _names_in_use = new Dictionary(); - _graph_key = $"grap-key-{ops.uid()}/"; + _graph_key = $"grap-{ops.GraphUniqueId()}/"; } public ITensorOrOperation as_graph_element(object obj, bool allow_tensor = true, bool allow_operation = true) diff --git a/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs b/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs index ba61e3a7..1139d42c 100644 --- a/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs +++ b/src/TensorFlowNET.Core/Numpy/NDArray.Creation.cs @@ -56,12 +56,8 @@ namespace Tensorflow.NumPy void NewEagerTensorHandle() { - if(_handle is not null) - { - _id = ops.uid(); - _eagerTensorHandle = c_api.TFE_NewTensorHandle(_handle, tf.Status.Handle); - tf.Status.Check(true); - } + if (_handle is not null) + _eagerTensorHandle = new EagerTensor(_handle).EagerTensorHandle; } } } diff --git a/src/TensorFlowNET.Core/Numpy/NDArray.cs b/src/TensorFlowNET.Core/Numpy/NDArray.cs index 75a5803d..edb4d292 100644 --- a/src/TensorFlowNET.Core/Numpy/NDArray.cs +++ b/src/TensorFlowNET.Core/Numpy/NDArray.cs @@ -28,9 +28,6 @@ namespace Tensorflow.NumPy { public IntPtr data => TensorDataPointer; - public ValueType GetValue(params int[] indices) - => throw new NotImplementedException(""); - [AutoNumPy] public NDArray reshape(Shape newshape) => new NDArray(tf.reshape(this, newshape)); public NDArray astype(TF_DataType dtype) => new NDArray(math_ops.cast(this, dtype)); diff --git a/src/TensorFlowNET.Core/Tensorflow.Binding.csproj b/src/TensorFlowNET.Core/Tensorflow.Binding.csproj index 33d5b287..a1b466cc 100644 --- a/src/TensorFlowNET.Core/Tensorflow.Binding.csproj +++ b/src/TensorFlowNET.Core/Tensorflow.Binding.csproj @@ -5,7 +5,7 @@ TensorFlow.NET Tensorflow 2.2.0 - 0.60.2 + 0.60.3 9.0 enable Haiping Chen, Meinrad Recheis, Eli Belash @@ -20,7 +20,7 @@ Google's TensorFlow full binding in .NET Standard. Building, training and infering deep learning models. https://tensorflownet.readthedocs.io - 0.60.2.0 + 0.60.3.0 tf.net 0.60.x and above are based on tensorflow native 2.6.0 * Eager Mode is added finally. @@ -35,7 +35,7 @@ Keras API is a separate package released as TensorFlow.Keras. tf.net 0.4x.x aligns with TensorFlow v2.4.1 native library. tf.net 0.5x.x aligns with TensorFlow v2.5.x native library. tf.net 0.6x.x aligns with TensorFlow v2.6.x native library. - 0.60.2.0 + 0.60.3.0 LICENSE true true diff --git a/src/TensorFlowNET.Core/ops.cs b/src/TensorFlowNET.Core/ops.cs index 5123477a..20b4f124 100644 --- a/src/TensorFlowNET.Core/ops.cs +++ b/src/TensorFlowNET.Core/ops.cs @@ -366,6 +366,12 @@ namespace Tensorflow return Interlocked.Increment(ref uid_number); } + static int graph_uid_number = -1; + public static int GraphUniqueId() + { + return Interlocked.Increment(ref graph_uid_number); + } + static int uid_number_for_function = 0; public static int uid_function() => Interlocked.Increment(ref uid_number_for_function); diff --git a/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj b/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj index 2f6eb864..54d45461 100644 --- a/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj +++ b/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj @@ -7,7 +7,7 @@ enable Tensorflow.Keras AnyCPU;x64 - 0.6.2 + 0.6.3 Haiping Chen Keras for .NET Apache 2.0, Haiping Chen 2021 @@ -37,8 +37,8 @@ Keras is an API designed for human beings, not machines. Keras follows best prac Git true Open.snk - 0.6.2.0 - 0.6.2.0 + 0.6.3.0 + 0.6.3.0 LICENSE