Browse Source

TF_Input, TF_Output

tags/v0.1.0-Tensor
Oceania2018 7 years ago
parent
commit
28732a13b1
15 changed files with 133 additions and 13 deletions
  1. +21
    -0
      src/TensorFlowNET.Core/BaseSession.cs
  2. +3
    -4
      src/TensorFlowNET.Core/TensorShape.cs
  3. +16
    -0
      src/TensorFlowNET.Core/Tensorflow/TF_Buffer.cs
  4. +13
    -0
      src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs
  5. +14
    -0
      src/TensorFlowNET.Core/Tensorflow/TF_Input.cs
  6. +14
    -0
      src/TensorFlowNET.Core/Tensorflow/TF_OperationDescription.cs
  7. +14
    -0
      src/TensorFlowNET.Core/Tensorflow/TF_Output.cs
  8. +9
    -2
      src/TensorFlowNET.Core/c_api.cs
  9. +10
    -0
      src/TensorFlowNET.Core/gen_array_ops.cs
  10. +1
    -2
      src/TensorFlowNET.Core/ops.cs
  11. +9
    -1
      src/TensorFlowNET.Core/tf.cs
  12. +1
    -1
      test/TensorFlowNET.Examples/HelloWorld.cs
  13. +1
    -1
      test/TensorFlowNET.UnitTest/GraphTest.cs
  14. +7
    -1
      test/TensorFlowNET.UnitTest/OperationsTest.cs
  15. +0
    -1
      test/TensorFlowNET.UnitTest/VersionTest.cs

+ 21
- 0
src/TensorFlowNET.Core/BaseSession.cs View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow;

namespace TensorFlowNET.Core
{
@@ -34,6 +35,26 @@ namespace TensorFlowNET.Core

public virtual byte[] run(Tensor fetches)
{
return _run(fetches);
}

private unsafe byte[] _run(Tensor fetches)
{
var status = new Status();

c_api.TF_SessionRun(_session,
run_options: null,
inputs: new TF_Input[] { },
input_values: new IntPtr[] { },
ninputs: 1,
outputs: new TF_Output[] { },
output_values: new IntPtr[] { },
noutputs: 1,
target_opers: new IntPtr[] { },
ntargets: 1,
run_metadata: null,
status: status.Handle);

return null;
}
}


+ 3
- 4
src/TensorFlowNET.Core/TensorShape.cs View File

@@ -1,4 +1,5 @@
using Google.Protobuf.Collections;
using NumSharp.Core;
using System;
using System.Collections.Generic;
using System.Text;
@@ -7,11 +8,9 @@ using tensor_shape_pb2 = Tensorflow;

namespace TensorFlowNET.Core
{
public class TensorShape
public class TensorShape : Shape
{
private int[] _dims;

public TensorShape()
public TensorShape(params int[] shape) : base(shape)
{

}


+ 16
- 0
src/TensorFlowNET.Core/Tensorflow/TF_Buffer.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using size_t = System.IntPtr;

namespace Tensorflow
{
[StructLayout(LayoutKind.Sequential)]
public struct TF_Buffer
{
public IntPtr data;
public size_t length;
public IntPtr data_deallocator;
}
}

+ 13
- 0
src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Tensorflow
{
[StructLayout(LayoutKind.Sequential)]
public struct TF_Graph
{

}
}

+ 14
- 0
src/TensorFlowNET.Core/Tensorflow/TF_Input.cs View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Tensorflow
{
[StructLayout(LayoutKind.Sequential)]
public struct TF_Input
{
public IntPtr oper;
public int index;
}
}

+ 14
- 0
src/TensorFlowNET.Core/Tensorflow/TF_OperationDescription.cs View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Tensorflow
{
[StructLayout(LayoutKind.Sequential)]
public struct TF_OperationDescription
{
public IntPtr node_builder;
//public TF_Graph graph;
}
}

+ 14
- 0
src/TensorFlowNET.Core/Tensorflow/TF_Output.cs View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Tensorflow
{
[StructLayout(LayoutKind.Sequential)]
public struct TF_Output
{
public IntPtr oper;
public int index;
}
}

+ 9
- 2
src/TensorFlowNET.Core/c_api.cs View File

@@ -5,7 +5,6 @@ using System.Text;

using size_t = System.UIntPtr;
using TF_Graph = System.IntPtr;
using TF_OperationDescription = System.IntPtr;
using TF_Operation = System.IntPtr;
using TF_Status = System.IntPtr;
using TF_Tensor = System.IntPtr;
@@ -14,7 +13,7 @@ using TF_SessionOptions = System.IntPtr;

using TF_DataType = Tensorflow.DataType;
using Tensorflow;
using static TensorFlowNET.Core.Tensorflow;
using static TensorFlowNET.Core.tf;

namespace TensorFlowNET.Core
{
@@ -55,6 +54,14 @@ namespace TensorFlowNET.Core
[DllImport(TensorFlowLibName)]
public static extern unsafe void TF_SetAttrTensor(TF_OperationDescription desc, string attr_name, TF_Tensor value, TF_Status status);

[DllImport(TensorFlowLibName)]
public static extern unsafe void TF_SessionRun(TF_Session session, TF_Buffer* run_options,
TF_Input[] inputs, TF_Tensor[] input_values,
int ninputs, TF_Output[] outputs,
TF_Tensor[] output_values, int noutputs,
TF_Operation[] target_opers, int ntargets,
TF_Buffer* run_metadata, TF_Status status);

[DllImport(TensorFlowLibName)]
public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value);



+ 10
- 0
src/TensorFlowNET.Core/gen_array_ops.cs View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace TensorFlowNET.Core
{
public static class gen_array_ops
{
}
}

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

@@ -4,8 +4,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Tensorflow;
using tf = TensorFlowNET.Core.Tensorflow;
using TF_DataType = Tensorflow.DataType;
using tf = TensorFlowNET.Core.tf;
using node_def_pb2 = Tensorflow;
using Google.Protobuf;



src/TensorFlowNET.Core/Tensorflow.cs → src/TensorFlowNET.Core/tf.cs View File

@@ -8,10 +8,18 @@ using Tensorflow;

namespace TensorFlowNET.Core
{
public static class Tensorflow
public static class tf
{
public static Type float32 = typeof(float);

public delegate void Deallocator(IntPtr data, IntPtr size, IntPtr deallocatorData);

public static unsafe Tensor placeholder(Type dtype, TensorShape shape = null)
{

return null;
}

public static unsafe Tensor constant(object value)
{
var g = ops.get_default_graph();

+ 1
- 1
test/TensorFlowNET.Examples/HelloWorld.cs View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using tf = TensorFlowNET.Core.Tensorflow;
using tf = TensorFlowNET.Core.tf;

namespace TensorFlowNET.Examples
{


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

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using tf = TensorFlowNET.Core.Tensorflow;
using TensorFlowNET.Core;

namespace TensorFlowNET.UnitTest
{


+ 7
- 1
test/TensorFlowNET.UnitTest/OperationsTest.cs View File

@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using tf = TensorFlowNET.Core.Tensorflow;
using TensorFlowNET.Core;

namespace TensorFlowNET.UnitTest
{
@@ -14,5 +14,11 @@ namespace TensorFlowNET.UnitTest
{
tf.constant(4.0);
}

[TestMethod]
public void placeholder()
{
var x = tf.placeholder(tf.float32, shape: new TensorShape(1024, 1024));
}
}
}

+ 0
- 1
test/TensorFlowNET.UnitTest/VersionTest.cs View File

@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Text;
using TensorFlowNET.Core;
using tf = TensorFlowNET.Core.Tensorflow;

namespace TensorFlowNET.UnitTest
{


Loading…
Cancel
Save