| @@ -1,6 +1,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using Tensorflow; | |||||
| namespace TensorFlowNET.Core | namespace TensorFlowNET.Core | ||||
| { | { | ||||
| @@ -34,6 +35,26 @@ namespace TensorFlowNET.Core | |||||
| public virtual byte[] run(Tensor fetches) | 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; | return null; | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,4 +1,5 @@ | |||||
| using Google.Protobuf.Collections; | using Google.Protobuf.Collections; | ||||
| using NumSharp.Core; | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| @@ -7,11 +8,9 @@ using tensor_shape_pb2 = Tensorflow; | |||||
| namespace TensorFlowNET.Core | namespace TensorFlowNET.Core | ||||
| { | { | ||||
| public class TensorShape | |||||
| public class TensorShape : Shape | |||||
| { | { | ||||
| private int[] _dims; | |||||
| public TensorShape() | |||||
| public TensorShape(params int[] shape) : base(shape) | |||||
| { | { | ||||
| } | } | ||||
| @@ -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; | |||||
| } | |||||
| } | |||||
| @@ -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 | |||||
| { | |||||
| } | |||||
| } | |||||
| @@ -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; | |||||
| } | |||||
| } | |||||
| @@ -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; | |||||
| } | |||||
| } | |||||
| @@ -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; | |||||
| } | |||||
| } | |||||
| @@ -5,7 +5,6 @@ using System.Text; | |||||
| using size_t = System.UIntPtr; | using size_t = System.UIntPtr; | ||||
| using TF_Graph = System.IntPtr; | using TF_Graph = System.IntPtr; | ||||
| using TF_OperationDescription = System.IntPtr; | |||||
| using TF_Operation = System.IntPtr; | using TF_Operation = System.IntPtr; | ||||
| using TF_Status = System.IntPtr; | using TF_Status = System.IntPtr; | ||||
| using TF_Tensor = System.IntPtr; | using TF_Tensor = System.IntPtr; | ||||
| @@ -14,7 +13,7 @@ using TF_SessionOptions = System.IntPtr; | |||||
| using TF_DataType = Tensorflow.DataType; | using TF_DataType = Tensorflow.DataType; | ||||
| using Tensorflow; | using Tensorflow; | ||||
| using static TensorFlowNET.Core.Tensorflow; | |||||
| using static TensorFlowNET.Core.tf; | |||||
| namespace TensorFlowNET.Core | namespace TensorFlowNET.Core | ||||
| { | { | ||||
| @@ -55,6 +54,14 @@ namespace TensorFlowNET.Core | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe void TF_SetAttrTensor(TF_OperationDescription desc, string attr_name, TF_Tensor value, TF_Status status); | 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)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value); | public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value); | ||||
| @@ -0,0 +1,10 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace TensorFlowNET.Core | |||||
| { | |||||
| public static class gen_array_ops | |||||
| { | |||||
| } | |||||
| } | |||||
| @@ -4,8 +4,7 @@ using System.Runtime.InteropServices; | |||||
| using System.Text; | using System.Text; | ||||
| using System.Threading; | using System.Threading; | ||||
| using Tensorflow; | using Tensorflow; | ||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| using TF_DataType = Tensorflow.DataType; | |||||
| using tf = TensorFlowNET.Core.tf; | |||||
| using node_def_pb2 = Tensorflow; | using node_def_pb2 = Tensorflow; | ||||
| using Google.Protobuf; | using Google.Protobuf; | ||||
| @@ -8,10 +8,18 @@ using Tensorflow; | |||||
| namespace TensorFlowNET.Core | 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 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) | public static unsafe Tensor constant(object value) | ||||
| { | { | ||||
| var g = ops.get_default_graph(); | var g = ops.get_default_graph(); | ||||
| @@ -1,7 +1,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| using tf = TensorFlowNET.Core.tf; | |||||
| namespace TensorFlowNET.Examples | namespace TensorFlowNET.Examples | ||||
| { | { | ||||
| @@ -2,7 +2,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| using TensorFlowNET.Core; | |||||
| namespace TensorFlowNET.UnitTest | namespace TensorFlowNET.UnitTest | ||||
| { | { | ||||
| @@ -2,7 +2,7 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| using TensorFlowNET.Core; | |||||
| namespace TensorFlowNET.UnitTest | namespace TensorFlowNET.UnitTest | ||||
| { | { | ||||
| @@ -14,5 +14,11 @@ namespace TensorFlowNET.UnitTest | |||||
| { | { | ||||
| tf.constant(4.0); | tf.constant(4.0); | ||||
| } | } | ||||
| [TestMethod] | |||||
| public void placeholder() | |||||
| { | |||||
| var x = tf.placeholder(tf.float32, shape: new TensorShape(1024, 1024)); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -3,7 +3,6 @@ using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using TensorFlowNET.Core; | using TensorFlowNET.Core; | ||||
| using tf = TensorFlowNET.Core.Tensorflow; | |||||
| namespace TensorFlowNET.UnitTest | namespace TensorFlowNET.UnitTest | ||||
| { | { | ||||