| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 28732a1 commit b58cf9a
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ TensorFlow.NET is a member project of SciSharp stack. | |||
| 8 | 8 | ||
| 9 | 9 | ### How to use | |
| 10 | 10 | ```cs | |
| 11 | - using tf = TensorFlowNET.Core.Tensorflow; | ||
| 11 | + using TensorFlowNET.Core; | ||
| 12 | 12 | ||
| 13 | 13 | namespace TensorFlowNET.Examples | |
| 14 | 14 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Runtime.InteropServices; | ||
| 4 | + using System.Text; | ||
| 5 | + using Tensorflow; | ||
| 6 | + | ||
| 7 | + namespace TensorFlowNET.Core | ||
| 8 | + { | ||
| 9 | + public class Buffer | ||
| 10 | + { | ||
| 11 | + private IntPtr _handle; | ||
| 12 | + public IntPtr Handle => _handle; | ||
| 13 | + //public TF_Buffer buffer => Marshal.PtrToStructure<TF_Buffer>(_handle); | ||
| 14 | + | ||
| 15 | + public unsafe Buffer() | ||
| 16 | + { | ||
| 17 | + _handle = Marshal.AllocHGlobal(sizeof(TF_Buffer)); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + public byte[] GetBuffer() | ||
| 21 | + { | ||
| 22 | + var buffer = Marshal.PtrToStructure<TF_Buffer>(_handle); | ||
| 23 | + | ||
| 24 | + var data = Marshal.AllocHGlobal(buffer.length); | ||
| 25 | + //var bytes = c_api.TF_GetBuffer(buffer.data); | ||
| 26 | + | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,9 @@ public Graph(IntPtr graph) | |||
| 32 | 32 | _names_in_use = new Dictionary<string, int>(); | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | - public unsafe Operation create_op(string op_type, object inputs, TF_DataType[] dtypes, TF_DataType[] input_types = null, Dictionary<string, AttrValue> attrs = null, string name = "Const") | ||
| 35 | + public unsafe Operation create_op(string op_type, object inputs, TF_DataType[] dtypes, | ||
| 36 | + TF_DataType[] input_types = null, string name = "", | ||
| 37 | + Dictionary<string, AttrValue> attrs = null, OpDef op_def = null) | ||
| 36 | 38 | { | |
| 37 | 39 | if (String.IsNullOrEmpty(name)) | |
| 38 | 40 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,95 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.IO; | ||
| 4 | + using System.Runtime.InteropServices; | ||
| 5 | + using System.Text; | ||
| 6 | + using Tensorflow; | ||
| 7 | + using static Tensorflow.OpDef.Types; | ||
| 8 | + | ||
| 9 | + namespace TensorFlowNET.Core | ||
| 10 | + { | ||
| 11 | + public class OpDefLibrary | ||
| 12 | + { | ||
| 13 | + public Dictionary<string, OpDef> _ops = new Dictionary<string, OpDef>(); | ||
| 14 | + | ||
| 15 | + public void add_op_list(OpList op_list) | ||
| 16 | + { | ||
| 17 | + foreach(var op_def in op_list.Op) | ||
| 18 | + { | ||
| 19 | + add_op(op_def); | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void add_op(OpDef op_def) | ||
| 24 | + { | ||
| 25 | + _ops[op_def.Name] = op_def; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public unsafe Operation _apply_op_helper(string op_type_name, string name = "", DataType? dtype = null, TensorShape shape = null) | ||
| 29 | + { | ||
| 30 | + var op_def = _ops[op_type_name]; | ||
| 31 | + | ||
| 32 | + var status = new Status(); | ||
| 33 | + var buffer = new Buffer(); | ||
| 34 | + | ||
| 35 | + var g = ops.get_default_graph(); | ||
| 36 | + | ||
| 37 | + if (String.IsNullOrEmpty(name)) | ||
| 38 | + { | ||
| 39 | + name = op_type_name; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + foreach(var attr_def in op_def.Attr) | ||
| 43 | + { | ||
| 44 | + if (attr_def.Type != "type") continue; | ||
| 45 | + var key = attr_def.Name; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + foreach(var input_arg in op_def.InputArg) | ||
| 49 | + { | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + var attr_protos = new Dictionary<string, AttrValue>(); | ||
| 54 | + foreach (var attr_def in op_def.Attr) | ||
| 55 | + { | ||
| 56 | + var key = attr_def.Name; | ||
| 57 | + var attr_value = new AttrValue(); | ||
| 58 | + | ||
| 59 | + switch (attr_def.Type) | ||
| 60 | + { | ||
| 61 | + case "type": | ||
| 62 | + attr_value.Type = dtype.Value; | ||
| 63 | + break; | ||
| 64 | + case "shape": | ||
| 65 | + attr_value.Shape = new TensorShapeProto(); | ||
| 66 | + break; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + attr_protos[key] = attr_value; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + var output_types = new List<DataType>(); | ||
| 73 | + | ||
| 74 | + foreach (var arg in op_def.OutputArg) | ||
| 75 | + { | ||
| 76 | + if (!String.IsNullOrEmpty(arg.NumberAttr)) | ||
| 77 | + { | ||
| 78 | + | ||
| 79 | + } | ||
| 80 | + else if (!String.IsNullOrEmpty(arg.TypeAttr)) | ||
| 81 | + { | ||
| 82 | + output_types.Add(attr_protos[arg.TypeAttr].Type); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + var op = g.create_op(op_type_name, null, output_types.ToArray(), | ||
| 87 | + name: "Placeholder_1/", | ||
| 88 | + input_types: new DataType[] { }, | ||
| 89 | + attrs: null, | ||
| 90 | + op_def: null); | ||
| 91 | + | ||
| 92 | + return op; | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,9 @@ | |||
| 25 | 25 | <None Update="tensorflow.dll"> | |
| 26 | 26 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |
| 27 | 27 | </None> | |
| 28 | + <None Update="Tensorflow\op_list_proto_bytes.bin"> | ||
| 29 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| 30 | + </None> | ||
| 28 | 31 | </ItemGroup> | |
| 29 | 32 | ||
| 30 | 33 | </Project> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments