Browse Source

fixed #108

tags/v0.1.0-Tensor
haiping008 6 years ago
parent
commit
43273b37d5
5 changed files with 13 additions and 9 deletions
  1. +1
    -6
      src/TensorFlowNET.Core/Graphs/Graph.cs
  2. +2
    -0
      src/TensorFlowNET.Core/Variables/RefVariable.cs
  3. +8
    -1
      src/TensorFlowNET.Core/ops.py.cs
  4. +1
    -1
      src/TensorFlowNET.Core/tf.cs
  5. +1
    -1
      test/TensorFlowNET.UnitTest/VariableTest.cs

+ 1
- 6
src/TensorFlowNET.Core/Graphs/Graph.cs View File

@@ -37,15 +37,10 @@ namespace Tensorflow
{
_handle = c_api.TF_NewGraph();
Status = new Status();
}

public Graph(IntPtr graph)
{
_handle = graph;
Status = new Status();
_nodes_by_id = new Dictionary<int, Operation>();
_nodes_by_name = new Dictionary<string, Operation>();
_names_in_use = new Dictionary<string, int>();
_graph_key = $"grap-key-{ops.uid()}/";
}

public T as_graph_element<T>(T obj, bool allow_tensor = true, bool allow_operation = true)


+ 2
- 0
src/TensorFlowNET.Core/Variables/RefVariable.cs View File

@@ -28,6 +28,8 @@ namespace Tensorflow
TF_DataType dtype = TF_DataType.DtInvalid) :
base(initial_value, trainable, collections, validate_shape, caching_device, name, dtype)
{
_in_graph_mode = true;

_init_from_args(initial_value, trainable, collections, validate_shape, caching_device, name, dtype);
}



+ 8
- 1
src/TensorFlowNET.Core/ops.py.cs View File

@@ -174,9 +174,16 @@ namespace Tensorflow
// outer_device_stack = None
}

private static int uid_number = 0;

/// <summary>
/// A unique (within this program execution) integer.
/// Not thread safe
/// </summary>
/// <returns></returns>
public static int uid()
{
return 1;
return uid_number++;
}
}
}

+ 1
- 1
src/TensorFlowNET.Core/tf.cs View File

@@ -15,7 +15,7 @@ namespace Tensorflow

public static Context context;

public static Graph g = new Graph(c_api.TF_NewGraph());
public static Graph g = new Graph();

public static RefVariable Variable<T>(T data, string name = "", TF_DataType dtype = TF_DataType.DtInvalid)
{


+ 1
- 1
test/TensorFlowNET.UnitTest/VariableTest.cs View File

@@ -35,7 +35,7 @@ namespace TensorFlowNET.UnitTest

using (var session = tf.Session())
{
session.run(model);
var sm = session.run(model);
for(int i = 0; i < 5; i++)
{
var x1 = x + 1;


Loading…
Cancel
Save