From 3f9f2a3725e59688fd9a12f6695ef94a7afa3f17 Mon Sep 17 00:00:00 2001 From: Kerry Jiang Date: Mon, 6 May 2019 20:47:02 -0700 Subject: [PATCH] changed the class Python to be static --- src/TensorFlowNET.Core/Clustering/KMeans.cs | 3 +- .../_InitializeClustersOpFactory.cs | 3 +- .../Framework/importer.py.cs | 3 +- .../Gradients/gradients_impl.py.cs | 3 +- src/TensorFlowNET.Core/Gradients/math_grad.cs | 3 +- .../Operations/ControlFlows/CondContext.cs | 221 +++++++++--------- .../ControlFlows/ControlFlowContext.cs | 107 ++++----- .../Distributions/distribution.py.cs | 4 +- .../Operations/Distributions/normal.py.cs | 1 + .../Operations/Losses/losses_impl.py.cs | 3 +- .../Operations/NnOps/MaxPoolFunction.cs | 3 +- .../Operations/OpDefLibrary.cs | 3 +- .../Operations/array_ops.py.cs | 3 +- .../Operations/check_ops.cs | 3 +- .../Operations/control_flow_ops.py.cs | 51 ++-- .../Operations/embedding_ops.cs | 3 +- .../Operations/gen_control_flow_ops.py.cs | 7 +- src/TensorFlowNET.Core/Operations/math_ops.cs | 3 +- .../Operations/nn_impl.py.cs | 3 +- .../Operations/random_ops.py.cs | 3 +- src/TensorFlowNET.Core/Python.cs | 22 +- .../Tensors/Tensor.Operators.cs | 1 + src/TensorFlowNET.Core/Tensors/Tensor.cs | 3 +- src/TensorFlowNET.Core/Train/Optimizer.cs | 7 +- .../Train/Saving/BaseSaverBuilder.cs | 3 +- .../Variables/RefVariable.Operators.cs | 1 + .../Variables/RefVariable.cs | 1 + .../Variables/VariableScope.cs | 3 +- .../Variables/VariableV1.cs | 3 +- src/TensorFlowNET.Core/ops.py.cs | 21 +- .../TensorFlowNET.Examples/BasicOperations.cs | 3 +- test/TensorFlowNET.Examples/HelloWorld.cs | 3 +- .../ImageRecognitionInception.cs | 3 +- .../InceptionArchGoogLeNet.cs | 3 +- .../KMeansClustering.cs | 3 +- .../LinearRegression.cs | 3 +- .../LogisticRegression.cs | 3 +- test/TensorFlowNET.Examples/MetaGraph.cs | 3 +- .../NaiveBayesClassifier.cs | 3 +- .../NamedEntityRecognition.cs | 3 +- .../TensorFlowNET.Examples/NearestNeighbor.cs | 3 +- test/TensorFlowNET.Examples/NeuralNetXor.cs | 3 +- .../TensorFlowNET.Examples/ObjectDetection.cs | 3 +- .../Text/BinaryTextClassification.cs | 3 +- .../Text/NER/BiLstmCrfNer.cs | 3 +- .../Text/TextClassificationTrain.cs | 37 +-- test/TensorFlowNET.Examples/Text/Word2Vec.cs | 3 +- .../Text/cnn_models/VdCnn.cs | 3 +- test/TensorFlowNET.UnitTest/CApiTest.cs | 3 +- test/TensorFlowNET.UnitTest/ConstantTest.cs | 3 +- test/TensorFlowNET.UnitTest/NameScopeTest.cs | 3 +- .../TensorFlowNET.UnitTest/PlaceholderTest.cs | 3 +- .../TensorFlowNET.UnitTest/PythonBaseTests.cs | 1 + test/TensorFlowNET.UnitTest/PythonTest.cs | 3 +- test/TensorFlowNET.UnitTest/SessionTest.cs | 1 + test/TensorFlowNET.UnitTest/TrainSaverTest.cs | 3 +- test/TensorFlowNET.UnitTest/VariableTest.cs | 3 +- .../control_flow_ops_test/CondTestCases.cs | 1 + .../WhileContextTestCase.cs | 1 + .../gradients_test/GradientsTest.cs | 1 + .../nest_test/NestTest.cs | 1 + .../nn_test/ZeroFractionTest.cs | 1 + .../ops_test/ControlDependenciesTest.cs | 1 + .../ops_test/CreateOpFromTfOperationTest.cs | 1 + 64 files changed, 339 insertions(+), 277 deletions(-) diff --git a/src/TensorFlowNET.Core/Clustering/KMeans.cs b/src/TensorFlowNET.Core/Clustering/KMeans.cs index 32a2abaa..07c69a63 100644 --- a/src/TensorFlowNET.Core/Clustering/KMeans.cs +++ b/src/TensorFlowNET.Core/Clustering/KMeans.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow.Clustering { /// /// Creates the graph for k-means clustering. /// - public class KMeans : Python + public class KMeans { public const string CLUSTERS_VAR_NAME = "clusters"; diff --git a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs index 91a2acfa..1b985bf9 100644 --- a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs +++ b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using static Tensorflow.Python; namespace Tensorflow.Clustering { /// /// Internal class to create the op to initialize the clusters. /// - public class _InitializeClustersOpFactory : Python + public class _InitializeClustersOpFactory { Tensor[] _inputs; Tensor _num_clusters; diff --git a/src/TensorFlowNET.Core/Framework/importer.py.cs b/src/TensorFlowNET.Core/Framework/importer.py.cs index 2b9dd6a4..ee2ce305 100644 --- a/src/TensorFlowNET.Core/Framework/importer.py.cs +++ b/src/TensorFlowNET.Core/Framework/importer.py.cs @@ -4,10 +4,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using static Tensorflow.OpDef.Types; +using static Tensorflow.Python; namespace Tensorflow { - public class importer : Python + public class importer { public static ITensorOrOperation[] import_graph_def(GraphDef graph_def, Dictionary input_map = null, diff --git a/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs index 0c7f528e..3c6dac91 100644 --- a/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs +++ b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs @@ -4,10 +4,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; +using static Tensorflow.Python; namespace Tensorflow { - public class gradients_impl : Python + public class gradients_impl { public static Tensor[] gradients(Tensor[] ys, Tensor[] xs, diff --git a/src/TensorFlowNET.Core/Gradients/math_grad.cs b/src/TensorFlowNET.Core/Gradients/math_grad.cs index 69c0e7a7..b63ea061 100644 --- a/src/TensorFlowNET.Core/Gradients/math_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/math_grad.cs @@ -3,13 +3,14 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using static Tensorflow.Python; namespace Tensorflow.Gradients { /// /// Gradients for operators defined in math_ops.py. /// - public class math_grad : Python + public class math_grad { public static Tensor[] _AddGrad(Operation op, Tensor[] grads) { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs index 40238dce..13f065ab 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Tensorflow.Operations.ControlFlows; +using static Tensorflow.Python; namespace Tensorflow.Operations { @@ -46,9 +47,9 @@ namespace Tensorflow.Operations if (pred == null && context_def == null) return; _name = ops.get_default_graph().unique_name(name); - if (context_def != null) - { - _init_from_proto(context_def, import_scope: import_scope); + if (context_def != null) + { + _init_from_proto(context_def, import_scope: import_scope); } else { @@ -66,16 +67,16 @@ namespace Tensorflow.Operations } } - private void _init_from_proto(CondContextDef context_def, string import_scope = null) - { - var g = ops.get_default_graph(); - _name = ops.prepend_name_scope(context_def.ContextName, import_scope); - var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); - _pred = g.as_graph_element(p1) as Tensor; - var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); - _pivot = g.as_graph_element(p2) as Tensor; - _branch = context_def.Branch; - __init__(values_def: context_def.ValuesDef, import_scope: import_scope); + private void _init_from_proto(CondContextDef context_def, string import_scope = null) + { + var g = ops.get_default_graph(); + _name = ops.prepend_name_scope(context_def.ContextName, import_scope); + var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); + _pred = g.as_graph_element(p1) as Tensor; + var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); + _pivot = g.as_graph_element(p2) as Tensor; + _branch = context_def.Branch; + __init__(values_def: context_def.ValuesDef, import_scope: import_scope); } /// @@ -90,8 +91,8 @@ namespace Tensorflow.Operations // Use the real value if it comes from outer context. This is needed in // particular for nested conds. if (_external_values.ContainsKey(val.name)) - result = _external_values[val.name]; - + result = _external_values[val.name]; + result = result == null ? val : result; } else @@ -107,10 +108,10 @@ namespace Tensorflow.Operations } with(ops.control_dependencies(null), ctrl => - { - var results = control_flow_ops._SwitchRefOrTensor(result, _pred); - result = results[_branch]; - if (_outer_context != null) + { + var results = control_flow_ops._SwitchRefOrTensor(result, _pred); + result = results[_branch]; + if (_outer_context != null) _outer_context.AddInnerOp(result.op); }); @@ -127,87 +128,87 @@ namespace Tensorflow.Operations } _external_values[val.name] = result; } - return result; - } - + return result; + } + /// /// Add the subgraph defined by fn() to the graph. /// - public (T, Tensor) BuildCondBranch(Func fn) - { - // Add the subgraph defined by fn() to the graph. - var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); - var original_result = fn(); - var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); - - //TODO: port this chunck of missing code: - /* - if len(post_summaries) > len(pre_summaries): - new_summaries = post_summaries[len(pre_summaries):] - summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access - summary_ref[:] = pre_summaries - with ops.control_dependencies(new_summaries): - if original_result is None: - return no_op(), None - else: - original_result = nest.map_structure(array_ops.identity, - original_result) - */ - if (original_result == null) - return (original_result, null); - - switch (original_result) - { - case Tensor result: - return (original_result, _BuildCondTensor(result)); - case Operation op: - return (original_result, _BuildCondTensor(op)); + public (T, Tensor) BuildCondBranch(Func fn) + { + // Add the subgraph defined by fn() to the graph. + var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); + var original_result = fn(); + var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); + + //TODO: port this chunck of missing code: + /* + if len(post_summaries) > len(pre_summaries): + new_summaries = post_summaries[len(pre_summaries):] + summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access + summary_ref[:] = pre_summaries + with ops.control_dependencies(new_summaries): + if original_result is None: + return no_op(), None + else: + original_result = nest.map_structure(array_ops.identity, + original_result) + */ + if (original_result == null) + return (original_result, null); + + switch (original_result) + { + case Tensor result: + return (original_result, _BuildCondTensor(result)); + case Operation op: + return (original_result, _BuildCondTensor(op)); case float[] fv: { var result = ops.convert_to_tensor(fv[0]); return (original_result, _BuildCondTensor(result)); - } - default: - return (original_result, null); - } - } - - public (T[], Tensor[]) BuildCondBranch(Func fn) - { - // Add the subgraph defined by fn() to the graph. - var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); - var original_result = fn(); - var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); - - switch (original_result) - { - case Tensor[] results: - return (original_result, results.Select(_BuildCondTensor).ToArray()); - case Operation[] results: - return (original_result, results.Select(_BuildCondTensor).ToArray()); - case float[] fv: - var result = ops.convert_to_tensor(fv[0]); - return (original_result, new Tensor[] { result }); - default: - return (original_result, new Tensor[0]); - } - } - - private Tensor _BuildCondTensor(ITensorOrOperation v) - { - switch (v) - { - case Operation op: - // Use pivot as the proxy for this op. - return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); - case Tensor t: - return _ProcessOutputTensor(t); - default: - return _ProcessOutputTensor(ops.convert_to_tensor(v)); - - } - } - + } + default: + return (original_result, null); + } + } + + public (T[], Tensor[]) BuildCondBranch(Func fn) + { + // Add the subgraph defined by fn() to the graph. + var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); + var original_result = fn(); + var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); + + switch (original_result) + { + case Tensor[] results: + return (original_result, results.Select(_BuildCondTensor).ToArray()); + case Operation[] results: + return (original_result, results.Select(_BuildCondTensor).ToArray()); + case float[] fv: + var result = ops.convert_to_tensor(fv[0]); + return (original_result, new Tensor[] { result }); + default: + return (original_result, new Tensor[0]); + } + } + + private Tensor _BuildCondTensor(ITensorOrOperation v) + { + switch (v) + { + case Operation op: + // Use pivot as the proxy for this op. + return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); + case Tensor t: + return _ProcessOutputTensor(t); + default: + return _ProcessOutputTensor(ops.convert_to_tensor(v)); + + } + } + /// /// Process an output tensor of a conditional branch. /// @@ -238,7 +239,7 @@ namespace Tensorflow.Operations } return real_val; } - + protected override void _AddOpInternal(Operation op) { if (op.inputs.Length == 0) @@ -324,20 +325,20 @@ namespace Tensorflow.Operations } } - public CondContextDef to_proto(string export_scope) - { - throw new NotImplementedException(); - } - - public CondContext from_proto(CondContextDef proto, string import_scope) - { - var ret = new CondContext(context_def: proto, import_scope: import_scope); - - ret.Enter(); - foreach (var nested_def in proto.NestedContexts) - from_control_flow_context_def(nested_def, import_scope: import_scope); - ret.Exit(); - return ret; - } - } + public CondContextDef to_proto(string export_scope) + { + throw new NotImplementedException(); + } + + public CondContext from_proto(CondContextDef proto, string import_scope) + { + var ret = new CondContext(context_def: proto, import_scope: import_scope); + + ret.Enter(); + foreach (var nested_def in proto.NestedContexts) + from_control_flow_context_def(nested_def, import_scope: import_scope); + ret.Exit(); + return ret; + } + } } \ No newline at end of file diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs index a36602f7..21201179 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Tensorflow.Operations.ControlFlows; -using static Tensorflow.ControlFlowContextDef; - +using static Tensorflow.ControlFlowContextDef; +using static Tensorflow.Python; + namespace Tensorflow.Operations -{ +{ /// /// The base class for control flow context. /// @@ -24,7 +25,7 @@ namespace Tensorflow.Operations /// 4. A ControlFlowContext has _context_stack. /// Pushed and popped by ctxt.Enter() and ctxt.Exit() /// - public abstract class ControlFlowContext : Python, IPython + public abstract class ControlFlowContext : IPython { /// /// The predicate tensor in this branch @@ -59,38 +60,38 @@ namespace Tensorflow.Operations { } - /// - /// Initializes values and external_values from `ValuesDef` protocol buffer. - /// - /// + /// + /// Initializes values and external_values from `ValuesDef` protocol buffer. + /// + /// /// - protected void _init_values_from_proto(ValuesDef values_def, string import_scope = null) - { - _external_values = new Dictionary(); - foreach (var value in values_def.Values) - _values.Add(value); - var g = ops.get_default_graph(); - foreach(var value in values_def.ExternalValues) - { - var k = ops.prepend_name_scope(value.Key, import_scope); - var v = value.Value; - _external_values[k] = g.as_graph_element(ops.prepend_name_scope(v, import_scope)); - } - - var op_names = _values.Where(x => !_external_values.ContainsKey(x)) - .Select(x => x.Split(':')[0]) - .ToArray(); - - foreach (var op in op_names) - (g.as_graph_element(op) as Operation)._set_control_flow_context(this); + protected void _init_values_from_proto(ValuesDef values_def, string import_scope = null) + { + _external_values = new Dictionary(); + foreach (var value in values_def.Values) + _values.Add(value); + var g = ops.get_default_graph(); + foreach(var value in values_def.ExternalValues) + { + var k = ops.prepend_name_scope(value.Key, import_scope); + var v = value.Value; + _external_values[k] = g.as_graph_element(ops.prepend_name_scope(v, import_scope)); + } + + var op_names = _values.Where(x => !_external_values.ContainsKey(x)) + .Select(x => x.Split(':')[0]) + .ToArray(); + + foreach (var op in op_names) + (g.as_graph_element(op) as Operation)._set_control_flow_context(this); } public void __exit__() { } - /// - /// Enter this control flow context. + /// + /// Enter this control flow context. /// public virtual void Enter() { @@ -127,7 +128,7 @@ namespace Tensorflow.Operations public virtual Tensor AddValue(Tensor val) { // to be overridden - return null; + return null; } /// @@ -148,17 +149,17 @@ namespace Tensorflow.Operations protected virtual void _AddOpInternal(Operation op) { - } - + } + protected bool OpInContext(Operation op) { return IsContainingContext(op._get_control_flow_context(), this); - } - - /// - /// Returns true if `maybe_containing_ctxt` is or contains `ctxt`. - /// - public static bool IsContainingContext(ControlFlowContext ctxt, ControlFlowContext maybe_containing_ctxt) + } + + /// + /// Returns true if `maybe_containing_ctxt` is or contains `ctxt`. + /// + public static bool IsContainingContext(ControlFlowContext ctxt, ControlFlowContext maybe_containing_ctxt) { while (ctxt != maybe_containing_ctxt) { @@ -167,7 +168,7 @@ namespace Tensorflow.Operations ctxt = ctxt.outer_context; } return true; - } + } protected virtual void _RemoveExternalControlEdges(Operation op) @@ -185,21 +186,21 @@ namespace Tensorflow.Operations return null; } - /// - /// Deserializes `context_def` into the appropriate ControlFlowContext. - /// - /// ControlFlowContextDef proto - /// Name scope to add + /// + /// Deserializes `context_def` into the appropriate ControlFlowContext. + /// + /// ControlFlowContextDef proto + /// Name scope to add /// A ControlFlowContext subclass - protected ControlFlowContext from_control_flow_context_def(ControlFlowContextDef context_def, string import_scope = "") - { - switch (context_def.CtxtCase) - { - case CtxtOneofCase.CondCtxt: - return new CondContext().from_proto(context_def.CondCtxt, import_scope: import_scope); - } - - throw new NotImplementedException($"Unknown ControlFlowContextDef field: {context_def.CtxtCase}"); + protected ControlFlowContext from_control_flow_context_def(ControlFlowContextDef context_def, string import_scope = "") + { + switch (context_def.CtxtCase) + { + case CtxtOneofCase.CondCtxt: + return new CondContext().from_proto(context_def.CondCtxt, import_scope: import_scope); + } + + throw new NotImplementedException($"Unknown ControlFlowContextDef field: {context_def.CtxtCase}"); } public object to_proto() diff --git a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs index 029b35bf..7d25e05b 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs @@ -2,12 +2,12 @@ using System; using System.Collections.Generic; using System.Text; - +using static Tensorflow.Python; namespace Tensorflow { - public class _BaseDistribution : Python + public class _BaseDistribution { // Abstract base class needed for resolving subclass hierarchy. } diff --git a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs index 773bdd6b..4c69faba 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Tensorflow; +using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs b/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs index ecfd0984..ced44b78 100644 --- a/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class LossesImpl : Python + public class LossesImpl { public Tensor sparse_softmax_cross_entropy(Tensor labels, Tensor logits, diff --git a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs index 5f15706e..94833236 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow.Operations { - public class MaxPoolFunction : Python, IPoolFunction + public class MaxPoolFunction : IPoolFunction { public Tensor Apply(Tensor value, int[] ksize, diff --git a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs index 1c67e0a8..00be4db8 100644 --- a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs +++ b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs @@ -7,10 +7,11 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using static Tensorflow.OpDef.Types; +using static Tensorflow.Python; namespace Tensorflow { - public class OpDefLibrary : Python + public class OpDefLibrary { public Operation _apply_op_helper(string op_type_name, string name = null, object args = null) => _apply_op_helper(op_type_name, name: name, keywords: ConvertToDict(args)); diff --git a/src/TensorFlowNET.Core/Operations/array_ops.py.cs b/src/TensorFlowNET.Core/Operations/array_ops.py.cs index ad3fc705..8cde60cc 100644 --- a/src/TensorFlowNET.Core/Operations/array_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/array_ops.py.cs @@ -2,10 +2,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class array_ops : Python + public class array_ops { public static Tensor placeholder_with_default(T input, int[] shape, string name = null) => gen_array_ops.placeholder_with_default(input, shape, name); diff --git a/src/TensorFlowNET.Core/Operations/check_ops.cs b/src/TensorFlowNET.Core/Operations/check_ops.cs index 87e26f7b..8c2e335d 100644 --- a/src/TensorFlowNET.Core/Operations/check_ops.cs +++ b/src/TensorFlowNET.Core/Operations/check_ops.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class check_ops : Python + public class check_ops { /// /// Assert the condition `x == y` holds element-wise. diff --git a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs index 08b8c8b5..259fee26 100644 --- a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs @@ -5,10 +5,11 @@ using System.Text; using Tensorflow.Operations; using Tensorflow.Operations.ControlFlows; using util = Tensorflow.control_flow_util; +using static Tensorflow.Python; namespace Tensorflow { - public class control_flow_ops : Python + public class control_flow_ops { public static Operation Assert(Tensor condition, object[] data, int? summarize = null, string name = null) { @@ -143,8 +144,8 @@ namespace Tensorflow return tpl.ToArray(); }); - } - + } + /// /// Produces the content of `output_tensor` only after `dependencies`. /// @@ -155,11 +156,11 @@ namespace Tensorflow /// no guarantee that `output_tensor` will be evaluated after any `dependencies` /// have run. /// - /// See also `tf.tuple` and `tf.group`. - /// - /// Iterable of operations to run before this op finishes. - /// A `Tensor` or `IndexedSlices` that will be returned. - /// (Optional) A name for this operation. + /// See also `tf.tuple` and `tf.group`. + /// + /// Iterable of operations to run before this op finishes. + /// A `Tensor` or `IndexedSlices` that will be returned. + /// (Optional) A name for this operation. /// Same as `output_tensor`. public static Tensor with_dependencies(Operation[] dependencies, Tensor output_tensor, string name = null) { @@ -210,23 +211,23 @@ namespace Tensorflow /// public static Tensor[] _SwitchRefOrTensor(Tensor data, Tensor pred, string name = "Switch") { - data = ops.convert_to_tensor_or_indexed_slices(data, name: "data"); - // NOTE(vrv): ops.colocate_with(data, ignore_existing=True) below - // addresses the following scenario. - // - // Assume you execute Optimizer.apply_gradients() in a branch of a cond(). - // - // 1. The update op is created inside a `with ops.colocate(var):` block - // - // 2. Some tensor `data` is captured and a switch is created in a - // `with ops.colocate_with(data):` block. - // - // with ops.colocate_with(var): - // with ops.colocate_with(data): - // op = ... - // - // var and data may be pinned to different devices, so we want to ops - // created within ops.colocate_with(data) to ignore the existing stack. + data = ops.convert_to_tensor_or_indexed_slices(data, name: "data"); + // NOTE(vrv): ops.colocate_with(data, ignore_existing=True) below + // addresses the following scenario. + // + // Assume you execute Optimizer.apply_gradients() in a branch of a cond(). + // + // 1. The update op is created inside a `with ops.colocate(var):` block + // + // 2. Some tensor `data` is captured and a switch is created in a + // `with ops.colocate_with(data):` block. + // + // with ops.colocate_with(var): + // with ops.colocate_with(data): + // op = ... + // + // var and data may be pinned to different devices, so we want to ops + // created within ops.colocate_with(data) to ignore the existing stack. ops.colocate_with(data, ignore_existing: true); { if (data is Tensor) diff --git a/src/TensorFlowNET.Core/Operations/embedding_ops.cs b/src/TensorFlowNET.Core/Operations/embedding_ops.cs index 664cdd51..5e7e9906 100644 --- a/src/TensorFlowNET.Core/Operations/embedding_ops.cs +++ b/src/TensorFlowNET.Core/Operations/embedding_ops.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class embedding_ops : Python + public class embedding_ops { /// /// Helper function for embedding_lookup and _compute_sampled_logits. diff --git a/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs index 78e70053..5cb34c59 100644 --- a/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_control_flow_ops.py.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class gen_control_flow_ops : Python + public class gen_control_flow_ops { public static OpDefLibrary _op_def_lib = new OpDefLibrary(); @@ -13,8 +14,8 @@ namespace Tensorflow var _op = _op_def_lib._apply_op_helper("NoOp", name, null); return _op; - } - + } + /// /// Forwards `data` to the output port determined by `pred`. /// diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index f4c28fba..ce91dbe9 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -3,13 +3,14 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow.Framework; +using static Tensorflow.Python; namespace Tensorflow { /// /// python\ops\math_ops.py /// - public class math_ops : Python + public class math_ops { public static Tensor abs(Tensor x, string name = null) { diff --git a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs index 84e5321d..ecbb8958 100644 --- a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs @@ -2,10 +2,11 @@ using System.Collections.Generic; using System.Text; using Tensorflow.Operations; +using static Tensorflow.Python; namespace Tensorflow { - public class nn_impl : Python + public class nn_impl { /// /// Normalizes along dimension `axis` using an L2 norm. diff --git a/src/TensorFlowNET.Core/Operations/random_ops.py.cs b/src/TensorFlowNET.Core/Operations/random_ops.py.cs index cbbafba0..54e9cd28 100644 --- a/src/TensorFlowNET.Core/Operations/random_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/random_ops.py.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { - public class random_ops : Python + public class random_ops { /// /// diff --git a/src/TensorFlowNET.Core/Python.cs b/src/TensorFlowNET.Core/Python.cs index bf13c452..bd1b7d83 100644 --- a/src/TensorFlowNET.Core/Python.cs +++ b/src/TensorFlowNET.Core/Python.cs @@ -12,9 +12,9 @@ namespace Tensorflow /// /// Mapping C# functions to Python /// - public class Python + public static class Python { - protected void print(object obj) + public static void print(object obj) { Console.WriteLine(obj.ToString()); } @@ -22,9 +22,9 @@ namespace Tensorflow //protected int len(IEnumerable a) // => a.Count(); - protected int len(object a) + public static int len(object a) { - switch (a) + switch (a) { case Array arr: return arr.Length; @@ -35,17 +35,17 @@ namespace Tensorflow case NDArray ndArray: return ndArray.len; case IEnumerable enumerable: - return enumerable.OfType().Count(); - } - throw new NotImplementedException("len() not implemented for type: " + a.GetType()); + return enumerable.OfType().Count(); + } + throw new NotImplementedException("len() not implemented for type: " + a.GetType()); } - protected IEnumerable range(int end) + public static IEnumerable range(int end) { return Enumerable.Range(0, end); } - protected IEnumerable range(int start, int end) + public static IEnumerable range(int start, int end) { return Enumerable.Range(start, end - start); } @@ -170,8 +170,8 @@ namespace Tensorflow dictionary.Add(name, obj); } return dictionary; - } - + } + public static bool hasattr(object obj, string key) { var __type__ = (obj).GetType(); diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs index bd4479fe..e15e0d57 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index 46a0e264..a4cc1769 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using static Tensorflow.c_api; +using static Tensorflow.Python; namespace Tensorflow { @@ -13,7 +14,7 @@ namespace Tensorflow /// A tensor is a generalization of vectors and matrices to potentially higher dimensions. /// Internally, TensorFlow represents tensors as n-dimensional arrays of base datatypes. /// - public partial class Tensor : Python, IDisposable, ITensorOrOperation + public partial class Tensor : IDisposable, ITensorOrOperation { private readonly IntPtr _handle; diff --git a/src/TensorFlowNET.Core/Train/Optimizer.cs b/src/TensorFlowNET.Core/Train/Optimizer.cs index 2e8125f2..541ba8e7 100644 --- a/src/TensorFlowNET.Core/Train/Optimizer.cs +++ b/src/TensorFlowNET.Core/Train/Optimizer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using distribute_lib = Tensorflow.Distribute; +using static Tensorflow.Python; namespace Tensorflow { @@ -12,7 +13,7 @@ namespace Tensorflow /// class directly, but instead instantiate one of its subclasses such as /// `GradientDescentOptimizer`, `AdagradOptimizer`, or `MomentumOptimizer`. /// - public abstract class Optimizer : Python + public abstract class Optimizer { // Values for gate_gradients. public static int GATE_NONE = 0; @@ -89,8 +90,8 @@ namespace Tensorflow $" that do not support gradients, between variables {string.Join(",", vars_with_grad.Select(x => x.name))} and loss {loss}."); return apply_gradients(grads_and_vars, global_step:global_step, name:name); - } - + } + /// /// Apply gradients to variables. /// diff --git a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs index 6b58c184..57519487 100644 --- a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs +++ b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Tensorflow.Operations; +using static Tensorflow.Python; namespace Tensorflow { - public class BaseSaverBuilder : Python + public class BaseSaverBuilder { protected SaverDef.Types.CheckpointFormatVersion _write_version; diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs index 0d27227a..cd5b8680 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.cs b/src/TensorFlowNET.Core/Variables/RefVariable.cs index 95d5520d..376e4a9f 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/VariableScope.cs b/src/TensorFlowNET.Core/Variables/VariableScope.cs index 7a2ef841..e20622cd 100644 --- a/src/TensorFlowNET.Core/Variables/VariableScope.cs +++ b/src/TensorFlowNET.Core/Variables/VariableScope.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { /// /// Variable scope object to carry defaults to provide to `get_variable` /// - public class VariableScope : Python + public class VariableScope { public bool use_resource { get; set; } private _ReuseMode _reuse; diff --git a/src/TensorFlowNET.Core/Variables/VariableV1.cs b/src/TensorFlowNET.Core/Variables/VariableV1.cs index 27297a26..8d5a5fc8 100644 --- a/src/TensorFlowNET.Core/Variables/VariableV1.cs +++ b/src/TensorFlowNET.Core/Variables/VariableV1.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using static Tensorflow.Python; namespace Tensorflow { @@ -14,7 +15,7 @@ namespace Tensorflow /// the variable are fixed. The value can be changed using one of the assign methods. /// https://tensorflow.org/guide/variables /// - public class VariableV1 : Python + public class VariableV1 { public VariableV1(object initial_value = null, bool trainable = true, diff --git a/src/TensorFlowNET.Core/ops.py.cs b/src/TensorFlowNET.Core/ops.py.cs index 63a2868a..08a7dc97 100644 --- a/src/TensorFlowNET.Core/ops.py.cs +++ b/src/TensorFlowNET.Core/ops.py.cs @@ -8,10 +8,11 @@ using Google.Protobuf; using System.Linq; using NumSharp; using System.ComponentModel; +using static Tensorflow.Python; namespace Tensorflow { - public partial class ops : Python + public partial class ops { public static void add_to_collection(string name, T value) { @@ -49,7 +50,7 @@ namespace Tensorflow return get_default_graph().get_collection_ref(key); } - private static Graph default_graph; + private static Graph default_graph; /// /// Returns the default graph for the current thread. /// @@ -60,8 +61,8 @@ namespace Tensorflow /// NOTE: The default graph is a property of the current thread.If you /// create a new thread, and wish to use the default graph in that /// thread, you must explicitly add a `with g.as_default():` in that - /// thread's function. - /// + /// thread's function. + /// /// public static Graph get_default_graph() { @@ -76,8 +77,8 @@ namespace Tensorflow //TODO: original source does not have a 'set_default_graph' and indicates there should be a _default_graph_stack! default_graph = graph; return default_graph; - } - + } + /// /// Clears the default graph stack and resets the global default graph. /// @@ -85,8 +86,8 @@ namespace Tensorflow /// function applies only to the current thread.Calling this function while /// a `tf.Session` or `tf.InteractiveSession` is active will result in undefined /// behavior. Using any previously created `tf.Operation` or `tf.Tensor` objects - /// after calling this function will result in undefined behavior. - /// + /// after calling this function will result in undefined behavior. + /// /// public static void reset_default_graph() { @@ -138,8 +139,8 @@ namespace Tensorflow public static Tensor internal_convert_to_tensor_or_composite(Tensor value, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool as_ref = false) { return internal_convert_to_tensor(value, dtype: dtype, name: name, as_ref: as_ref); - } - + } + /// /// Wrapper for `Graph.control_dependencies()` using the default graph. /// diff --git a/test/TensorFlowNET.Examples/BasicOperations.cs b/test/TensorFlowNET.Examples/BasicOperations.cs index c8abadf3..b2051cf9 100644 --- a/test/TensorFlowNET.Examples/BasicOperations.cs +++ b/test/TensorFlowNET.Examples/BasicOperations.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples /// Basic Operations example using TensorFlow library. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_operations.py /// - public class BasicOperations : Python, IExample + public class BasicOperations : IExample { public bool Enabled { get; set; } = true; public int Priority => 2; diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs index a7f47211..f2d9681f 100644 --- a/test/TensorFlowNET.Examples/HelloWorld.cs +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -9,7 +10,7 @@ namespace TensorFlowNET.Examples /// Simple hello world using TensorFlow /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py /// - public class HelloWorld : Python, IExample + public class HelloWorld : IExample { public int Priority => 1; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/ImageRecognitionInception.cs b/test/TensorFlowNET.Examples/ImageRecognitionInception.cs index 05fe1928..d2d42288 100644 --- a/test/TensorFlowNET.Examples/ImageRecognitionInception.cs +++ b/test/TensorFlowNET.Examples/ImageRecognitionInception.cs @@ -9,6 +9,7 @@ using System.Net; using System.Text; using Tensorflow; using System.Drawing; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -17,7 +18,7 @@ namespace TensorFlowNET.Examples /// that has been shown to attain greater than 78.1% accuracy on the ImageNet dataset. /// The model is the culmination of many ideas developed by multiple researchers over the years. /// - public class ImageRecognitionInception : Python, IExample + public class ImageRecognitionInception : IExample { public int Priority => 7; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs b/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs index 579311ff..e4d1cf2f 100644 --- a/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs +++ b/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -17,7 +18,7 @@ namespace TensorFlowNET.Examples /// Inception Architecture for Computer Vision /// Port from tensorflow\examples\label_image\label_image.py /// - public class InceptionArchGoogLeNet : Python, IExample + public class InceptionArchGoogLeNet : IExample { public bool Enabled { get; set; } = false; public int Priority => 100; diff --git a/test/TensorFlowNET.Examples/KMeansClustering.cs b/test/TensorFlowNET.Examples/KMeansClustering.cs index e12623cc..2b216439 100644 --- a/test/TensorFlowNET.Examples/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/KMeansClustering.cs @@ -7,6 +7,7 @@ using System.Text; using Tensorflow; using Tensorflow.Clustering; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -15,7 +16,7 @@ namespace TensorFlowNET.Examples /// handwritten digit images. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/kmeans.py /// - public class KMeansClustering : Python, IExample + public class KMeansClustering : IExample { public int Priority => 8; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/LinearRegression.cs b/test/TensorFlowNET.Examples/LinearRegression.cs index 448a0d1c..c5021da1 100644 --- a/test/TensorFlowNET.Examples/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/LinearRegression.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples /// A linear regression learning algorithm example using TensorFlow library. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/linear_regression.py /// - public class LinearRegression : Python, IExample + public class LinearRegression : IExample { public int Priority => 3; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/LogisticRegression.cs b/test/TensorFlowNET.Examples/LogisticRegression.cs index 2568890c..8e7779de 100644 --- a/test/TensorFlowNET.Examples/LogisticRegression.cs +++ b/test/TensorFlowNET.Examples/LogisticRegression.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -15,7 +16,7 @@ namespace TensorFlowNET.Examples /// This example is using the MNIST database of handwritten digits /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/logistic_regression.py /// - public class LogisticRegression : Python, IExample + public class LogisticRegression : IExample { public int Priority => 4; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/MetaGraph.cs b/test/TensorFlowNET.Examples/MetaGraph.cs index 09563e1e..b449ceca 100644 --- a/test/TensorFlowNET.Examples/MetaGraph.cs +++ b/test/TensorFlowNET.Examples/MetaGraph.cs @@ -4,10 +4,11 @@ using System.IO; using System.Runtime.InteropServices; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { - public class MetaGraph : Python, IExample + public class MetaGraph : IExample { public int Priority => 100; public bool Enabled { get; set; } = false; diff --git a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs index c520d51a..36935ccb 100644 --- a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs @@ -4,13 +4,14 @@ using System.Text; using Tensorflow; using NumSharp; using System.Linq; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { /// /// https://github.com/nicolov/naive_bayes_tensorflow /// - public class NaiveBayesClassifier : Python, IExample + public class NaiveBayesClassifier : IExample { public int Priority => 6; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/NamedEntityRecognition.cs b/test/TensorFlowNET.Examples/NamedEntityRecognition.cs index a85b41e5..7e229551 100644 --- a/test/TensorFlowNET.Examples/NamedEntityRecognition.cs +++ b/test/TensorFlowNET.Examples/NamedEntityRecognition.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { /// /// https://github.com/guillaumegenthial/tf_ner /// - public class NamedEntityRecognition : Python, IExample + public class NamedEntityRecognition : IExample { public int Priority => 100; public bool Enabled { get; set; } = false; diff --git a/test/TensorFlowNET.Examples/NearestNeighbor.cs b/test/TensorFlowNET.Examples/NearestNeighbor.cs index cc670314..0c99d84e 100644 --- a/test/TensorFlowNET.Examples/NearestNeighbor.cs +++ b/test/TensorFlowNET.Examples/NearestNeighbor.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -12,7 +13,7 @@ namespace TensorFlowNET.Examples /// This example is using the MNIST database of handwritten digits /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/nearest_neighbor.py /// - public class NearestNeighbor : Python, IExample + public class NearestNeighbor : IExample { public int Priority => 5; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/NeuralNetXor.cs b/test/TensorFlowNET.Examples/NeuralNetXor.cs index 404bb542..6593b4a4 100644 --- a/test/TensorFlowNET.Examples/NeuralNetXor.cs +++ b/test/TensorFlowNET.Examples/NeuralNetXor.cs @@ -4,6 +4,7 @@ using System.Text; using NumSharp; using Tensorflow; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -11,7 +12,7 @@ namespace TensorFlowNET.Examples /// Simple vanilla neural net solving the famous XOR problem /// https://github.com/amygdala/tensorflow-workshop/blob/master/workshop_sections/getting_started/xor/README.md /// - public class NeuralNetXor : Python, IExample + public class NeuralNetXor : IExample { public int Priority => 10; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/ObjectDetection.cs b/test/TensorFlowNET.Examples/ObjectDetection.cs index 1345503b..27b232b2 100644 --- a/test/TensorFlowNET.Examples/ObjectDetection.cs +++ b/test/TensorFlowNET.Examples/ObjectDetection.cs @@ -9,11 +9,12 @@ using TensorFlowNET.Examples.Utility; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { - public class ObjectDetection : Python, IExample + public class ObjectDetection : IExample { public int Priority => 11; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/Text/BinaryTextClassification.cs b/test/TensorFlowNET.Examples/Text/BinaryTextClassification.cs index c9a1c95a..7f7cc13d 100644 --- a/test/TensorFlowNET.Examples/Text/BinaryTextClassification.cs +++ b/test/TensorFlowNET.Examples/Text/BinaryTextClassification.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using System.Linq; using System.Text.RegularExpressions; using NumSharp; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -14,7 +15,7 @@ namespace TensorFlowNET.Examples /// This is a binary—or two-class—classification, an important and widely applicable kind of machine learning problem. /// https://github.com/tensorflow/docs/blob/master/site/en/tutorials/keras/basic_text_classification.ipynb /// - public class BinaryTextClassification : Python, IExample + public class BinaryTextClassification : IExample { public int Priority => 9; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/Text/NER/BiLstmCrfNer.cs b/test/TensorFlowNET.Examples/Text/NER/BiLstmCrfNer.cs index 6a7cf55b..19207f6a 100644 --- a/test/TensorFlowNET.Examples/Text/NER/BiLstmCrfNer.cs +++ b/test/TensorFlowNET.Examples/Text/NER/BiLstmCrfNer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples /// Bidirectional LSTM-CRF Models for Sequence Tagging /// https://github.com/guillaumegenthial/tf_ner/tree/master/models/lstm_crf /// - public class BiLstmCrfNer : Python, IExample + public class BiLstmCrfNer : IExample { public int Priority => 13; diff --git a/test/TensorFlowNET.Examples/Text/TextClassificationTrain.cs b/test/TensorFlowNET.Examples/Text/TextClassificationTrain.cs index 0e2caa17..94f990cf 100644 --- a/test/TensorFlowNET.Examples/Text/TextClassificationTrain.cs +++ b/test/TensorFlowNET.Examples/Text/TextClassificationTrain.cs @@ -10,13 +10,14 @@ using Tensorflow.Keras.Engine; using TensorFlowNET.Examples.Text.cnn_models; using TensorFlowNET.Examples.TextClassification; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples.CnnTextClassification { /// /// https://github.com/dongjun-Lee/text-classification-models-tf /// - public class TextClassificationTrain : Python, IExample + public class TextClassificationTrain : IExample { public int Priority => 100; public bool Enabled { get; set; } = false; @@ -53,8 +54,8 @@ namespace TensorFlowNET.Examples.CnnTextClassification Console.WriteLine("Building dataset..."); var (x, y, alphabet_size) = DataHelpers.build_char_dataset("train", model_name, CHAR_MAX_LEN, DataLimit); - var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); - + var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); + var meta_file = model_name + "_untrained.meta"; tf.train.import_meta_graph(Path.Join("graph", meta_file)); @@ -92,22 +93,22 @@ namespace TensorFlowNET.Examples.CnnTextClassification var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); - ITextClassificationModel model = null; - switch (model_name) // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn - { - case "word_cnn": - case "char_cnn": - case "word_rnn": - case "att_rnn": - case "rcnn": - throw new NotImplementedException(); - break; + ITextClassificationModel model = null; + switch (model_name) // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn + { + case "word_cnn": + case "char_cnn": + case "word_rnn": + case "att_rnn": + case "rcnn": + throw new NotImplementedException(); + break; case "vd_cnn": - model=new VdCnn(alphabet_size, CHAR_MAX_LEN, NUM_CLASS); - break; - } - // todo train the model - return false; + model=new VdCnn(alphabet_size, CHAR_MAX_LEN, NUM_CLASS); + break; + } + // todo train the model + return false; } private (int[][], int[][], int[], int[]) train_test_split(int[][] x, int[] y, float test_size = 0.3f) diff --git a/test/TensorFlowNET.Examples/Text/Word2Vec.cs b/test/TensorFlowNET.Examples/Text/Word2Vec.cs index 552d5a6d..b4110cc6 100644 --- a/test/TensorFlowNET.Examples/Text/Word2Vec.cs +++ b/test/TensorFlowNET.Examples/Text/Word2Vec.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using Tensorflow; using TensorFlowNET.Examples.Utility; +using static Tensorflow.Python; namespace TensorFlowNET.Examples { @@ -13,7 +14,7 @@ namespace TensorFlowNET.Examples /// Implement Word2Vec algorithm to compute vector representations of words. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/word2vec.py /// - public class Word2Vec : Python, IExample + public class Word2Vec : IExample { public int Priority => 12; public bool Enabled { get; set; } = true; diff --git a/test/TensorFlowNET.Examples/Text/cnn_models/VdCnn.cs b/test/TensorFlowNET.Examples/Text/cnn_models/VdCnn.cs index ddcf16f1..fdba49ec 100644 --- a/test/TensorFlowNET.Examples/Text/cnn_models/VdCnn.cs +++ b/test/TensorFlowNET.Examples/Text/cnn_models/VdCnn.cs @@ -4,10 +4,11 @@ using System.Linq; using System.Text; using Tensorflow; using TensorFlowNET.Examples.Text.cnn_models; +using static Tensorflow.Python; namespace TensorFlowNET.Examples.TextClassification { - public class VdCnn : Python, ITextClassificationModel + public class VdCnn : ITextClassificationModel { private int embedding_size; private int[] filter_sizes; diff --git a/test/TensorFlowNET.UnitTest/CApiTest.cs b/test/TensorFlowNET.UnitTest/CApiTest.cs index 4f0be55d..2f2888b2 100644 --- a/test/TensorFlowNET.UnitTest/CApiTest.cs +++ b/test/TensorFlowNET.UnitTest/CApiTest.cs @@ -3,10 +3,11 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { - public class CApiTest : Python + public class CApiTest { protected TF_Code TF_OK = TF_Code.TF_OK; protected TF_DataType TF_FLOAT = TF_DataType.TF_FLOAT; diff --git a/test/TensorFlowNET.UnitTest/ConstantTest.cs b/test/TensorFlowNET.UnitTest/ConstantTest.cs index 81e7fb23..9052b1b4 100644 --- a/test/TensorFlowNET.UnitTest/ConstantTest.cs +++ b/test/TensorFlowNET.UnitTest/ConstantTest.cs @@ -6,11 +6,12 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { [TestClass] - public class ConstantTest : Python + public class ConstantTest { Status status = new Status(); diff --git a/test/TensorFlowNET.UnitTest/NameScopeTest.cs b/test/TensorFlowNET.UnitTest/NameScopeTest.cs index 003b5810..c25007c3 100644 --- a/test/TensorFlowNET.UnitTest/NameScopeTest.cs +++ b/test/TensorFlowNET.UnitTest/NameScopeTest.cs @@ -3,11 +3,12 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { [TestClass] - public class NameScopeTest : Python + public class NameScopeTest { Graph g = ops.get_default_graph(); string name = ""; diff --git a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs index 189a9c69..9f96f19b 100644 --- a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs +++ b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs @@ -3,11 +3,12 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { [TestClass] - public class PlaceholderTest : Python + public class PlaceholderTest { [TestMethod] public void placeholder() diff --git a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs index 2a9c6af6..765a71c2 100644 --- a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs +++ b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/PythonTest.cs b/test/TensorFlowNET.UnitTest/PythonTest.cs index ee7e4764..7fb54127 100644 --- a/test/TensorFlowNET.UnitTest/PythonTest.cs +++ b/test/TensorFlowNET.UnitTest/PythonTest.cs @@ -8,13 +8,14 @@ using Newtonsoft.Json.Linq; using NumSharp; using Tensorflow; using Tensorflow.Util; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { /// /// Use as base class for test classes to get additional assertions /// - public class PythonTest : Python + public class PythonTest { #region python compatibility layer protected PythonTest self { get => this; } diff --git a/test/TensorFlowNET.UnitTest/SessionTest.cs b/test/TensorFlowNET.UnitTest/SessionTest.cs index e24da442..c8aaa582 100644 --- a/test/TensorFlowNET.UnitTest/SessionTest.cs +++ b/test/TensorFlowNET.UnitTest/SessionTest.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs index 3ea4dfc8..e02273b4 100644 --- a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs +++ b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs @@ -4,11 +4,12 @@ using System.Collections.Generic; using System.IO; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { [TestClass] - public class TrainSaverTest : Python + public class TrainSaverTest { public void ExportGraph() { diff --git a/test/TensorFlowNET.UnitTest/VariableTest.cs b/test/TensorFlowNET.UnitTest/VariableTest.cs index 43bb4934..d46ac903 100644 --- a/test/TensorFlowNET.UnitTest/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/VariableTest.cs @@ -3,11 +3,12 @@ using System; using System.Collections.Generic; using System.Text; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest { [TestClass] - public class VariableTest : Python + public class VariableTest { [TestMethod] public void Initializer() diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs index 14b6d686..4476018a 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using System; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.control_flow_ops_test { diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs index cbe88e7a..c86fabde 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs @@ -5,6 +5,7 @@ using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Operations; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.control_flow_ops_test { diff --git a/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs b/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs index 8fbed063..13182a68 100644 --- a/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs +++ b/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.gradients_test { diff --git a/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs b/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs index 1a243ac8..16026ac0 100644 --- a/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs +++ b/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using NumSharp; using Tensorflow; using Tensorflow.Util; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.nest_test { diff --git a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs index d9b8341c..50cceddb 100644 --- a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs +++ b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs @@ -5,6 +5,7 @@ using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.nn_test { diff --git a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs index 25610d50..3a806516 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs @@ -5,6 +5,7 @@ using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Eager; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.ops_test { diff --git a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs index 0d0adba2..25533c24 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs @@ -5,6 +5,7 @@ using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Operations; +using static Tensorflow.Python; namespace TensorFlowNET.UnitTest.ops_test {