From 91f42b3e3e798cd1248309bae38edc11cbd9e17b Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Tue, 18 Dec 2018 21:37:27 -0600 Subject: [PATCH] restructure dir and namespace --- src/TensorFlowNET.Core/BaseSession.cs | 3 +-- src/TensorFlowNET.Core/Buffer.cs | 3 +-- src/TensorFlowNET.Core/Eager/Context.cs | 2 +- src/TensorFlowNET.Core/Graph.cs | 3 +-- .../MonoPInvokeCallbackAttribute.cs | 2 +- src/TensorFlowNET.Core/OpDefLibrary.cs | 9 +++++---- src/TensorFlowNET.Core/Operation.cs | 3 +-- src/TensorFlowNET.Core/Session.cs | 2 +- src/TensorFlowNET.Core/Status.cs | 3 +-- src/TensorFlowNET.Core/Tensor.cs | 3 +-- src/TensorFlowNET.Core/TensorFlowNET.Core.csproj | 2 ++ src/TensorFlowNET.Core/TensorShape.cs | 4 +--- src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs | 13 ------------- src/TensorFlowNET.Core/c_api.cs | 8 +++----- src/TensorFlowNET.Core/ops.cs | 3 +-- src/TensorFlowNET.Core/{ => ops}/gen_array_ops.cs | 5 +++-- src/TensorFlowNET.Core/ops/gen_math_ops.cs | 15 +++++++++++++++ src/TensorFlowNET.Core/tensor_util.cs | 5 ++--- src/TensorFlowNET.Core/tf.cs | 13 +++++++------ test/TensorFlowNET.Examples/HelloWorld.cs | 2 +- test/TensorFlowNET.UnitTest/GraphTest.cs | 2 +- test/TensorFlowNET.UnitTest/OperationsTest.cs | 2 +- test/TensorFlowNET.UnitTest/VersionTest.cs | 4 ++-- 23 files changed, 53 insertions(+), 58 deletions(-) delete mode 100644 src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs rename src/TensorFlowNET.Core/{ => ops}/gen_array_ops.cs (91%) create mode 100644 src/TensorFlowNET.Core/ops/gen_math_ops.cs diff --git a/src/TensorFlowNET.Core/BaseSession.cs b/src/TensorFlowNET.Core/BaseSession.cs index 2ba1fc02..3be70a9d 100644 --- a/src/TensorFlowNET.Core/BaseSession.cs +++ b/src/TensorFlowNET.Core/BaseSession.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public class BaseSession { diff --git a/src/TensorFlowNET.Core/Buffer.cs b/src/TensorFlowNET.Core/Buffer.cs index 26965dbb..bf2799cb 100644 --- a/src/TensorFlowNET.Core/Buffer.cs +++ b/src/TensorFlowNET.Core/Buffer.cs @@ -2,9 +2,8 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; -using Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public class Buffer { diff --git a/src/TensorFlowNET.Core/Eager/Context.cs b/src/TensorFlowNET.Core/Eager/Context.cs index b922c6ae..3d9c875d 100644 --- a/src/TensorFlowNET.Core/Eager/Context.cs +++ b/src/TensorFlowNET.Core/Eager/Context.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace TensorFlowNET.Core.Eager +namespace Tensorflow.Eager { public class Context { diff --git a/src/TensorFlowNET.Core/Graph.cs b/src/TensorFlowNET.Core/Graph.cs index 8ed9ceec..93180a61 100644 --- a/src/TensorFlowNET.Core/Graph.cs +++ b/src/TensorFlowNET.Core/Graph.cs @@ -3,10 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using Tensorflow; using TF_DataType = Tensorflow.DataType; -namespace TensorFlowNET.Core +namespace Tensorflow { /// /// TensorFlow uses a dataflow graph to represent your computation in terms of the dependencies between individual operations. diff --git a/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs b/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs index a2c579a6..201e92c8 100644 --- a/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs +++ b/src/TensorFlowNET.Core/MonoPInvokeCallbackAttribute.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace TensorFlowNET.Core +namespace Tensorflow { public sealed class MonoPInvokeCallbackAttribute : Attribute { diff --git a/src/TensorFlowNET.Core/OpDefLibrary.cs b/src/TensorFlowNET.Core/OpDefLibrary.cs index bcca3284..e891e58b 100644 --- a/src/TensorFlowNET.Core/OpDefLibrary.cs +++ b/src/TensorFlowNET.Core/OpDefLibrary.cs @@ -3,10 +3,9 @@ using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Text; -using Tensorflow; using static Tensorflow.OpDef.Types; -namespace TensorFlowNET.Core +namespace Tensorflow { public class OpDefLibrary { @@ -39,7 +38,9 @@ namespace TensorFlowNET.Core name = op_type_name; } - foreach(var attr_def in op_def.Attr) + string scope = g.unique_name(name) + "/"; + + foreach (var attr_def in op_def.Attr) { if (attr_def.Type != "type") continue; var key = attr_def.Name; @@ -84,7 +85,7 @@ namespace TensorFlowNET.Core } var op = g.create_op(op_type_name, null, output_types.ToArray(), - name: "Placeholder_1/", + name: scope, input_types: new DataType[] { }, attrs: attr_protos, op_def: op_def); diff --git a/src/TensorFlowNET.Core/Operation.cs b/src/TensorFlowNET.Core/Operation.cs index 76d3c815..2d416944 100644 --- a/src/TensorFlowNET.Core/Operation.cs +++ b/src/TensorFlowNET.Core/Operation.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; using System.Text; -using Tensorflow; using TF_DataType = Tensorflow.DataType; -namespace TensorFlowNET.Core +namespace Tensorflow { public class Operation { diff --git a/src/TensorFlowNET.Core/Session.cs b/src/TensorFlowNET.Core/Session.cs index 0755539f..4d0b9ba9 100644 --- a/src/TensorFlowNET.Core/Session.cs +++ b/src/TensorFlowNET.Core/Session.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace TensorFlowNET.Core +namespace Tensorflow { public class Session : BaseSession { diff --git a/src/TensorFlowNET.Core/Status.cs b/src/TensorFlowNET.Core/Status.cs index c6a5091f..02e0bc72 100644 --- a/src/TensorFlowNET.Core/Status.cs +++ b/src/TensorFlowNET.Core/Status.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public class Status { diff --git a/src/TensorFlowNET.Core/Tensor.cs b/src/TensorFlowNET.Core/Tensor.cs index ec10fcb9..0d16fb41 100644 --- a/src/TensorFlowNET.Core/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensor.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public class Tensor { diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index a5b40af6..6f976409 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -2,6 +2,8 @@ netstandard2.0 + TensorFlow.NET + Tensorflow diff --git a/src/TensorFlowNET.Core/TensorShape.cs b/src/TensorFlowNET.Core/TensorShape.cs index 7e6c7dd7..5c3cf87b 100644 --- a/src/TensorFlowNET.Core/TensorShape.cs +++ b/src/TensorFlowNET.Core/TensorShape.cs @@ -3,10 +3,8 @@ using NumSharp.Core; using System; using System.Collections.Generic; using System.Text; -using Tensorflow; -using tensor_shape_pb2 = Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public class TensorShape : Shape { diff --git a/src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs b/src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs deleted file mode 100644 index bc71def4..00000000 --- a/src/TensorFlowNET.Core/Tensorflow/TF_Graph.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; - -namespace Tensorflow -{ - [StructLayout(LayoutKind.Sequential)] - public struct TF_Graph - { - - } -} diff --git a/src/TensorFlowNET.Core/c_api.cs b/src/TensorFlowNET.Core/c_api.cs index 347d27cd..b9834340 100644 --- a/src/TensorFlowNET.Core/c_api.cs +++ b/src/TensorFlowNET.Core/c_api.cs @@ -12,10 +12,8 @@ using TF_Session = System.IntPtr; using TF_SessionOptions = System.IntPtr; using TF_DataType = Tensorflow.DataType; -using Tensorflow; -using static TensorFlowNET.Core.tf; -namespace TensorFlowNET.Core +namespace Tensorflow { public static class c_api { @@ -40,7 +38,7 @@ namespace TensorFlowNET.Core public static extern unsafe string TF_Message(TF_Status s); [DllImport(TensorFlowLibName)] - public static unsafe extern IntPtr TF_NewGraph(); + public static unsafe extern TF_Graph TF_NewGraph(); [DllImport(TensorFlowLibName)] public static unsafe extern TF_OperationDescription TF_NewOperation(TF_Graph graph, string opType, string oper_name); @@ -49,7 +47,7 @@ namespace TensorFlowNET.Core public static unsafe extern TF_Status TF_NewStatus(); [DllImport(TensorFlowLibName)] - public static extern unsafe TF_Tensor TF_NewTensor(TF_DataType dataType, Int64 dims, int num_dims, IntPtr data, size_t len, Deallocator deallocator, IntPtr deallocator_arg); + public static extern unsafe TF_Tensor TF_NewTensor(TF_DataType dataType, Int64 dims, int num_dims, IntPtr data, size_t len, tf.Deallocator deallocator, IntPtr deallocator_arg); [DllImport(TensorFlowLibName)] public static extern unsafe int TF_OperationNumOutputs(TF_Operation oper); diff --git a/src/TensorFlowNET.Core/ops.cs b/src/TensorFlowNET.Core/ops.cs index bbe51251..c24ed135 100644 --- a/src/TensorFlowNET.Core/ops.cs +++ b/src/TensorFlowNET.Core/ops.cs @@ -4,11 +4,10 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using Tensorflow; -using tf = TensorFlowNET.Core.tf; using node_def_pb2 = Tensorflow; using Google.Protobuf; -namespace TensorFlowNET.Core +namespace Tensorflow { public static class ops { diff --git a/src/TensorFlowNET.Core/gen_array_ops.cs b/src/TensorFlowNET.Core/ops/gen_array_ops.cs similarity index 91% rename from src/TensorFlowNET.Core/gen_array_ops.cs rename to src/TensorFlowNET.Core/ops/gen_array_ops.cs index bf18f7b1..7719fbf1 100644 --- a/src/TensorFlowNET.Core/gen_array_ops.cs +++ b/src/TensorFlowNET.Core/ops/gen_array_ops.cs @@ -4,7 +4,7 @@ using System.IO; using System.Text; using Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public static class gen_array_ops { @@ -20,7 +20,8 @@ namespace TensorFlowNET.Core _attrs["dtype"] = _op.get_attr("dtype"); _attrs["shape"] = _op.get_attr("shape"); - return null; + var tensor = new Tensor(_op, 0, dtype); + return tensor; } private static OpDefLibrary _InitOpDefLibrary() diff --git a/src/TensorFlowNET.Core/ops/gen_math_ops.cs b/src/TensorFlowNET.Core/ops/gen_math_ops.cs new file mode 100644 index 00000000..c48f4737 --- /dev/null +++ b/src/TensorFlowNET.Core/ops/gen_math_ops.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public static class gen_math_ops + { + public static Tensor add(Tensor a, Tensor b, string name = "") + { + + return null; + } + } +} diff --git a/src/TensorFlowNET.Core/tensor_util.cs b/src/TensorFlowNET.Core/tensor_util.cs index cad0eb6c..ec9b23bb 100644 --- a/src/TensorFlowNET.Core/tensor_util.cs +++ b/src/TensorFlowNET.Core/tensor_util.cs @@ -2,10 +2,9 @@ using System; using System.Collections.Generic; using System.Text; -using Tensorflow; using tensor_pb2 = Tensorflow; -namespace TensorFlowNET.Core +namespace Tensorflow { public static class tensor_util { @@ -13,7 +12,7 @@ namespace TensorFlowNET.Core { NDArray nparray; TensorProto tensor_proto = null; - TensorShape tensor_shape = new TensorShape(); + TensorShape tensor_shape = new TensorShape(0); switch (values) { diff --git a/src/TensorFlowNET.Core/tf.cs b/src/TensorFlowNET.Core/tf.cs index 60307d04..582f7b5a 100644 --- a/src/TensorFlowNET.Core/tf.cs +++ b/src/TensorFlowNET.Core/tf.cs @@ -4,10 +4,9 @@ using System.Runtime.InteropServices; using System.Text; using TF_DataType = Tensorflow.DataType; using attr_value_pb2 = Tensorflow; -using Tensorflow; -using TensorFlowNET.Core.Eager; +using Tensorflow.Eager; -namespace TensorFlowNET.Core +namespace Tensorflow { public static class tf { @@ -26,12 +25,14 @@ namespace TensorFlowNET.Core public static unsafe Tensor placeholder(DataType dtype, TensorShape shape = null) { - var g = ops.get_default_graph(); + /*var g = ops.get_default_graph(); var op = new Operation(g, "Placeholder", "feed"); var tensor = new Tensor(op, 0, dtype); - //return gen_array_ops.placeholder(dtype, shape); - return tensor; + + return tensor;*/ + + return gen_array_ops.placeholder(dtype, shape); } public static unsafe Tensor constant(object value) diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs index 06d67a40..2913c6b6 100644 --- a/test/TensorFlowNET.Examples/HelloWorld.cs +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Text; -using tf = TensorFlowNET.Core.tf; +using Tensorflow; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.UnitTest/GraphTest.cs b/test/TensorFlowNET.UnitTest/GraphTest.cs index bfffddda..1864fede 100644 --- a/test/TensorFlowNET.UnitTest/GraphTest.cs +++ b/test/TensorFlowNET.UnitTest/GraphTest.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -using TensorFlowNET.Core; +using Tensorflow; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs index cb6f3ddd..40e902a0 100644 --- a/test/TensorFlowNET.UnitTest/OperationsTest.cs +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -using TensorFlowNET.Core; +using Tensorflow; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/VersionTest.cs b/test/TensorFlowNET.UnitTest/VersionTest.cs index 18d3ecec..2e47f32a 100644 --- a/test/TensorFlowNET.UnitTest/VersionTest.cs +++ b/test/TensorFlowNET.UnitTest/VersionTest.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Text; -using TensorFlowNET.Core; +using Tensorflow; namespace TensorFlowNET.UnitTest { @@ -13,7 +13,7 @@ namespace TensorFlowNET.UnitTest public void GetVersion() { var ver = tf.VERSION; - Assert.IsTrue(ver.Contains(".")); + Assert.IsTrue(ver.StartsWith("1.")); } } }