Browse Source

add TF_GraphSetOutputHandleShapesAndTypes api.

tags/v0.20
Oceania2018 5 years ago
parent
commit
468cb8e8a6
3 changed files with 22 additions and 6 deletions
  1. +5
    -0
      src/TensorFlowNET.Core/Graphs/Graph.cs
  2. +15
    -0
      src/TensorFlowNET.Core/Graphs/c_api.graph.cs
  3. +2
    -6
      test/TensorFlowNET.UnitTest/MultithreadingTests.cs

+ 5
- 0
src/TensorFlowNET.Core/Graphs/Graph.cs View File

@@ -105,6 +105,9 @@ namespace Tensorflow

public bool building_function;

string _container = "";
public string Container => _container;

int _seed;
public int seed
{
@@ -151,6 +154,8 @@ namespace Tensorflow
{
if (obj is RefVariable var)
return var._as_graph_element();
else if (obj is ResourceVariable resVar)
return resVar.GraphElement;

return null;
}


+ 15
- 0
src/TensorFlowNET.Core/Graphs/c_api.graph.cs View File

@@ -297,6 +297,21 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)]
public static extern SafeImportGraphDefOptionsHandle TF_NewImportGraphDefOptions();

/// <summary>
/// Set the shapes and types of the output's handle.
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="output">TF_Output</param>
/// <param name="num_shapes_and_types">int</param>
/// <param name="shapes">const int64_t**</param>
/// <param name="ranks">const int*</param>
/// <param name="types">const TF_DataType*</param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphSetOutputHandleShapesAndTypes(IntPtr graph, TF_Output output,
int num_shapes_and_types, IntPtr[] shapes, int[] ranks, DataType[] types,
SafeStatusHandle status);

/// <summary>
/// Updates 'dst' to consume 'new_src'.
/// </summary>


+ 2
- 6
test/TensorFlowNET.UnitTest/MultithreadingTests.cs View File

@@ -145,10 +145,9 @@ namespace TensorFlowNET.UnitTest
//tf.Session created an other graph
using (var sess = tf.Session())
{
Tensor t = null;
for (int i = 0; i < 100; i++)
{
t = new Tensor(new int[] {1, 2, 3});
var t = new Tensor(new int[] {1, 2, 3});
}
}
}
@@ -167,12 +166,9 @@ namespace TensorFlowNET.UnitTest
{
using (var sess = tf.Session())
{
#pragma warning disable CS0219 // Variable is assigned but its value is never used
Tensor t = null;
#pragma warning restore CS0219 // Variable is assigned but its value is never used
for (int i = 0; i < 100; i++)
{
var v = (int*) Marshal.AllocHGlobal(sizeof(int));
var v = (int*)Marshal.AllocHGlobal(sizeof(int));
c_api.DeallocatorArgs _deallocatorArgs = new c_api.DeallocatorArgs();
var handle = c_api.TF_NewTensor(typeof(int).as_dtype(), dims: new long[0], num_dims: 0,
data: (IntPtr) v, len: (UIntPtr) sizeof(int),


Loading…
Cancel
Save