diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..ee3236a4 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +# You can find more information about CODEOWNERS here: https://help.github.com/en/articles/about-code-owners +# These owners will be the default owners for everything in the repo. +* @Oceania2018 \ No newline at end of file diff --git a/src/KerasNET.Core/Core.cs b/src/KerasNET.Core/Core.cs index 4be5a48e..d2e77c0e 100644 --- a/src/KerasNET.Core/Core.cs +++ b/src/KerasNET.Core/Core.cs @@ -1,4 +1,5 @@ using Tensorflow; +using static Tensorflow.Binding; namespace Keras { diff --git a/src/KerasNET.Core/Layers/Dense.cs b/src/KerasNET.Core/Layers/Dense.cs index 8938d05f..893dbc10 100644 --- a/src/KerasNET.Core/Layers/Dense.cs +++ b/src/KerasNET.Core/Layers/Dense.cs @@ -19,6 +19,7 @@ using Tensorflow; using static Keras.Keras; using NumSharp; using Tensorflow.Operations.Activation; +using static Tensorflow.Binding; namespace Keras.Layers { diff --git a/src/KerasNET.Core/Model.cs b/src/KerasNET.Core/Model.cs index d1d05159..034c7f64 100644 --- a/src/KerasNET.Core/Model.cs +++ b/src/KerasNET.Core/Model.cs @@ -19,7 +19,7 @@ using NumSharp; using System; using System.Collections.Generic; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Keras { diff --git a/src/TensorFlowNET.Core/APIs/tf.array.cs b/src/TensorFlowNET.Core/APIs/tf.array.cs index 48f16b2b..06d48555 100644 --- a/src/TensorFlowNET.Core/APIs/tf.array.cs +++ b/src/TensorFlowNET.Core/APIs/tf.array.cs @@ -20,7 +20,7 @@ using System.Linq; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { /// /// Concatenates tensors along one dimension. @@ -29,7 +29,7 @@ namespace Tensorflow /// /// /// A `Tensor` resulting from concatenation of the input tensors. - public static Tensor concat(IList values, int axis, string name = "concat") + public Tensor concat(IList values, int axis, string name = "concat") { if (values.Count == 1) throw new NotImplementedException("tf.concat length is 1"); @@ -48,7 +48,7 @@ namespace Tensorflow /// A `Tensor` with the same data as `input`, but its shape has an additional /// dimension of size 1 added. /// - public static Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1) + public Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1) => array_ops.expand_dims(input, axis, name, dim); /// @@ -58,14 +58,14 @@ namespace Tensorflow /// /// /// - public static Tensor fill(Tensor dims, T value, string name = null) + public Tensor fill(Tensor dims, T value, string name = null) => gen_array_ops.fill(dims, value, name: name); /// /// Return the elements, either from `x` or `y`, depending on the `condition`. /// /// - public static Tensor where(Tensor condition, Tx x, Ty y, string name = null) + public Tensor where(Tensor condition, Tx x, Ty y, string name = null) => array_ops.where(condition, x, y, name); /// @@ -76,10 +76,10 @@ namespace Tensorflow /// /// /// - public static Tensor transpose(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false) + public Tensor transpose(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false) => array_ops.transpose(a, perm, name, conjugate); - public static Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1) + public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1) => gen_array_ops.squeeze(input, axis, name); /// @@ -89,10 +89,10 @@ namespace Tensorflow /// /// /// - public static Tensor stack(object values, int axis = 0, string name = "stack") + public Tensor stack(object values, int axis = 0, string name = "stack") => array_ops.stack(values, axis, name: name); - public static Tensor one_hot(Tensor indices, int depth, + public Tensor one_hot(Tensor indices, int depth, Tensor on_value = null, Tensor off_value = null, TF_DataType dtype = TF_DataType.DtInvalid, @@ -110,7 +110,7 @@ namespace Tensorflow /// /// A name for the operation (optional). /// A `Tensor`. Has the same type as `input`. - public static Tensor placeholder_with_default(T input, int[] shape, string name = null) + public Tensor placeholder_with_default(T input, int[] shape, string name = null) => gen_array_ops.placeholder_with_default(input, shape, name: name); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.control.cs b/src/TensorFlowNET.Core/APIs/tf.control.cs index d744a141..dcccb6fe 100644 --- a/src/TensorFlowNET.Core/APIs/tf.control.cs +++ b/src/TensorFlowNET.Core/APIs/tf.control.cs @@ -18,9 +18,9 @@ using System; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor while_loop(Func cond, Func body, Tensor[] loop_vars, + public Tensor while_loop(Func cond, Func body, Tensor[] loop_vars, TensorShape shape_invariants = null, int parallel_iterations = 10, bool back_prop = true, @@ -37,7 +37,7 @@ namespace Tensorflow maximum_iterations: maximum_iterations, return_same_structure: return_same_structure); - public static _ControlDependenciesController control_dependencies(Operation[] control_inputs) + public _ControlDependenciesController control_dependencies(Operation[] control_inputs) => ops.control_dependencies(control_inputs); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.distributions.cs b/src/TensorFlowNET.Core/APIs/tf.distributions.cs index dbf2478c..c9ccad91 100644 --- a/src/TensorFlowNET.Core/APIs/tf.distributions.cs +++ b/src/TensorFlowNET.Core/APIs/tf.distributions.cs @@ -16,11 +16,13 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static class distributions + public distributions_internal distributions { get; } = new distributions_internal(); + + public class distributions_internal { - public static Normal Normal(Tensor loc, + public Normal Normal(Tensor loc, Tensor scale, bool validate_args = false, bool allow_nan_stats = true, diff --git a/src/TensorFlowNET.Core/APIs/tf.exp.cs b/src/TensorFlowNET.Core/APIs/tf.exp.cs index 8caeb12e..56ea1898 100644 --- a/src/TensorFlowNET.Core/APIs/tf.exp.cs +++ b/src/TensorFlowNET.Core/APIs/tf.exp.cs @@ -16,9 +16,9 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor exp(Tensor x, + public Tensor exp(Tensor x, string name = null) => gen_math_ops.exp(x, name); } diff --git a/src/TensorFlowNET.Core/APIs/tf.gradients.cs b/src/TensorFlowNET.Core/APIs/tf.gradients.cs index dcdca7a3..b8931b15 100644 --- a/src/TensorFlowNET.Core/APIs/tf.gradients.cs +++ b/src/TensorFlowNET.Core/APIs/tf.gradients.cs @@ -16,9 +16,9 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor[] gradients(Tensor[] ys, + public Tensor[] gradients(Tensor[] ys, Tensor[] xs, Tensor[] grad_ys = null, string name = "gradients", @@ -36,7 +36,7 @@ namespace Tensorflow stop_gradients: stop_gradients); } - public static Tensor[] gradients(Tensor ys, + public Tensor[] gradients(Tensor ys, Tensor[] xs, Tensor[] grad_ys = null, string name = "gradients", @@ -54,7 +54,7 @@ namespace Tensorflow stop_gradients: stop_gradients); } - public static Tensor[] gradients(Tensor ys, + public Tensor[] gradients(Tensor ys, Tensor xs, Tensor[] grad_ys = null, string name = "gradients", diff --git a/src/TensorFlowNET.Core/APIs/tf.graph.cs b/src/TensorFlowNET.Core/APIs/tf.graph.cs index 402ffca1..a60c0413 100644 --- a/src/TensorFlowNET.Core/APIs/tf.graph.cs +++ b/src/TensorFlowNET.Core/APIs/tf.graph.cs @@ -16,15 +16,15 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static graph_util_impl graph_util => new graph_util_impl(); - public static Graph get_default_graph() + public graph_util_impl graph_util => new graph_util_impl(); + public Graph get_default_graph() { return ops.get_default_graph(); } - public static Graph Graph() + public Graph Graph() => new Graph(); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.init.cs b/src/TensorFlowNET.Core/APIs/tf.init.cs index 6809b344..f6fa380c 100644 --- a/src/TensorFlowNET.Core/APIs/tf.init.cs +++ b/src/TensorFlowNET.Core/APIs/tf.init.cs @@ -18,14 +18,14 @@ using Tensorflow.Operations.Initializers; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static IInitializer zeros_initializer => new Zeros(); - public static IInitializer ones_initializer => new Ones(); - public static IInitializer glorot_uniform_initializer => new GlorotUniform(); - public static IInitializer uniform_initializer => new RandomUniform(); + public IInitializer zeros_initializer => new Zeros(); + public IInitializer ones_initializer => new Ones(); + public IInitializer glorot_uniform_initializer => new GlorotUniform(); + public IInitializer uniform_initializer => new RandomUniform(); - public static variable_scope variable_scope(string name, + public variable_scope variable_scope(string name, string default_name = null, Tensor[] values = null, bool? reuse = null, @@ -35,7 +35,7 @@ namespace Tensorflow reuse: reuse, auxiliary_name_scope: auxiliary_name_scope); - public static variable_scope variable_scope(VariableScope scope, + public variable_scope variable_scope(VariableScope scope, string default_name = null, Tensor[] values = null, bool? reuse = null, @@ -45,7 +45,7 @@ namespace Tensorflow reuse: reuse, auxiliary_name_scope: auxiliary_name_scope); - public static IInitializer truncated_normal_initializer(float mean = 0.0f, + public IInitializer truncated_normal_initializer(float mean = 0.0f, float stddev = 1.0f, int? seed = null, TF_DataType dtype = TF_DataType.DtInvalid) => new TruncatedNormal(mean: mean, diff --git a/src/TensorFlowNET.Core/APIs/tf.io.cs b/src/TensorFlowNET.Core/APIs/tf.io.cs index 618b1ea5..5980cf81 100644 --- a/src/TensorFlowNET.Core/APIs/tf.io.cs +++ b/src/TensorFlowNET.Core/APIs/tf.io.cs @@ -19,14 +19,14 @@ using Tensorflow.IO; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static GFile gfile = new GFile(); - public static Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name); + public GFile gfile = new GFile(); + public Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name); - public static gen_image_ops image => new gen_image_ops(); + public gen_image_ops image => new gen_image_ops(); - public static void import_graph_def(GraphDef graph_def, + public void import_graph_def(GraphDef graph_def, Dictionary input_map = null, string[] return_elements = null, string name = null, diff --git a/src/TensorFlowNET.Core/APIs/tf.layers.cs b/src/TensorFlowNET.Core/APIs/tf.layers.cs index a832adab..53ddcf13 100644 --- a/src/TensorFlowNET.Core/APIs/tf.layers.cs +++ b/src/TensorFlowNET.Core/APIs/tf.layers.cs @@ -16,14 +16,17 @@ using Tensorflow.Keras.Layers; using Tensorflow.Operations.Activation; +using static Tensorflow.Binding; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static class layers + public layers_internal layers { get; } = new layers_internal(); + + public class layers_internal { - public static Tensor conv2d(Tensor inputs, + public Tensor conv2d(Tensor inputs, int filters, int[] kernel_size, int[] strides = null, @@ -80,7 +83,7 @@ namespace Tensorflow /// /// /// - public static Tensor batch_normalization(Tensor inputs, + public Tensor batch_normalization(Tensor inputs, int axis = -1, float momentum = 0.99f, float epsilon = 0.001f, @@ -124,7 +127,7 @@ namespace Tensorflow /// /// /// - public static Tensor max_pooling2d(Tensor inputs, + public Tensor max_pooling2d(Tensor inputs, int[] pool_size, int[] strides, string padding = "valid", @@ -140,7 +143,7 @@ namespace Tensorflow return layer.apply(inputs); } - public static Tensor dense(Tensor inputs, + public Tensor dense(Tensor inputs, int units, IActivation activation = null, bool use_bias = true, diff --git a/src/TensorFlowNET.Core/APIs/tf.linalg.cs b/src/TensorFlowNET.Core/APIs/tf.linalg.cs index 76a6123a..b4141460 100644 --- a/src/TensorFlowNET.Core/APIs/tf.linalg.cs +++ b/src/TensorFlowNET.Core/APIs/tf.linalg.cs @@ -16,15 +16,15 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor diag(Tensor diagonal, string name = null) + public Tensor diag(Tensor diagonal, string name = null) => gen_array_ops.diag(diagonal, name: name); - public static Tensor matmul(Tensor a, Tensor b) + public Tensor matmul(Tensor a, Tensor b) => gen_math_ops.mat_mul(a, b); - public static Tensor batch_matmul(Tensor x, Tensor y) + public Tensor batch_matmul(Tensor x, Tensor y) => gen_math_ops.batch_mat_mul(x, y); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.loss.cs b/src/TensorFlowNET.Core/APIs/tf.loss.cs index 1b1b4445..48ed0150 100644 --- a/src/TensorFlowNET.Core/APIs/tf.loss.cs +++ b/src/TensorFlowNET.Core/APIs/tf.loss.cs @@ -16,8 +16,8 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static LossesImpl losses => new LossesImpl(); + public LossesImpl losses => new LossesImpl(); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index c2686812..ddfa71ec 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -16,9 +16,9 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor abs(Tensor x, string name = null) + public Tensor abs(Tensor x, string name = null) => math_ops.abs(x, name); /// @@ -27,7 +27,7 @@ namespace Tensorflow /// /// /// - public static Tensor acos(Tensor x, string name = null) + public Tensor acos(Tensor x, string name = null) => gen_math_ops.acos(x, name); /// @@ -36,10 +36,10 @@ namespace Tensorflow /// /// /// - public static Tensor asin(Tensor x, string name = null) + public Tensor asin(Tensor x, string name = null) => gen_math_ops.asin(x, name); - public static Tensor add(Tx a, Ty b, string name = null) + public Tensor add(Tx a, Ty b, string name = null) => gen_math_ops.add(a, b, name: name); /// @@ -48,19 +48,19 @@ namespace Tensorflow /// /// /// - public static Tensor atan(Tensor x, string name = null) + public Tensor atan(Tensor x, string name = null) => gen_math_ops.atan(x, name); - public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) + public Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) => gen_math_ops.arg_max(input, dimension, output_type: output_type, name: name); - public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) + public Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) => gen_math_ops.arg_min(input, dimension, output_type: output_type, name: name); - public static Tensor is_finite(Tensor input, string name = null) + public Tensor is_finite(Tensor input, string name = null) => gen_math_ops.is_finite(input, name); - public static Tensor is_nan(Tensor input, string name = null) + public Tensor is_nan(Tensor input, string name = null) => gen_math_ops.is_nan(input, name); /// @@ -69,7 +69,7 @@ namespace Tensorflow /// /// /// - public static Tensor ceil(Tensor x, string name = null) + public Tensor ceil(Tensor x, string name = null) => gen_math_ops.ceil(x, name); /// @@ -78,7 +78,7 @@ namespace Tensorflow /// /// /// - public static Tensor sin(Tensor x, string name = null) + public Tensor sin(Tensor x, string name = null) => gen_math_ops.sin(x, name); /// @@ -87,7 +87,7 @@ namespace Tensorflow /// /// /// - public static Tensor sinh(Tensor x, string name = null) + public Tensor sinh(Tensor x, string name = null) => gen_math_ops.sinh(x, name); /// @@ -96,7 +96,7 @@ namespace Tensorflow /// /// /// - public static Tensor cos(Tensor x, string name = null) + public Tensor cos(Tensor x, string name = null) => gen_math_ops.cos(x, name); /// @@ -105,13 +105,13 @@ namespace Tensorflow /// /// /// - public static Tensor cosh(Tensor x, string name = null) + public Tensor cosh(Tensor x, string name = null) => gen_math_ops.cosh(x, name); - public static Tensor tan(Tensor x, string name = null) + public Tensor tan(Tensor x, string name = null) => gen_math_ops.tan(x, name); - public static Tensor tanh(Tensor x, string name = null) + public Tensor tanh(Tensor x, string name = null) => gen_math_ops.tanh(x, name); /// @@ -120,7 +120,7 @@ namespace Tensorflow /// /// /// - public static Tensor floor(Tensor x, string name = null) + public Tensor floor(Tensor x, string name = null) => gen_math_ops.floor(x, name); /// @@ -132,7 +132,7 @@ namespace Tensorflow /// /// /// - public static Tensor greater(Tx x, Ty y, string name = null) + public Tensor greater(Tx x, Ty y, string name = null) => gen_math_ops.greater(x, y, name); /// @@ -144,7 +144,7 @@ namespace Tensorflow /// /// /// - public static Tensor greater_equal(Tx x, Ty y, string name = null) + public Tensor greater_equal(Tx x, Ty y, string name = null) => gen_math_ops.greater_equal(x, y, name); /// @@ -156,7 +156,7 @@ namespace Tensorflow /// /// /// - public static Tensor less(Tx x, Ty y, string name = null) + public Tensor less(Tx x, Ty y, string name = null) => gen_math_ops.less(x, y, name); /// @@ -165,7 +165,7 @@ namespace Tensorflow /// A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`. /// A name for the operation (optional). /// A `Tensor`. Has the same type as `x`. - public static Tensor lgamma(Tensor x, string name = null) + public Tensor lgamma(Tensor x, string name = null) => gen_math_ops.lgamma(x, name: name); /// @@ -177,7 +177,7 @@ namespace Tensorflow /// /// /// - public static Tensor less_equal(Tx x, Ty y, string name = null) + public Tensor less_equal(Tx x, Ty y, string name = null) => gen_math_ops.less_equal(x, y, name); /// @@ -186,19 +186,19 @@ namespace Tensorflow /// /// /// - public static Tensor log1p(Tensor x, string name = null) + public Tensor log1p(Tensor x, string name = null) => gen_math_ops.log1p(x, name); - public static Tensor logical_and(Tensor x, Tensor y, string name = null) + public Tensor logical_and(Tensor x, Tensor y, string name = null) => gen_math_ops.logical_and(x, y, name); - public static Tensor logical_not(Tensor x, string name = null) + public Tensor logical_not(Tensor x, string name = null) => gen_math_ops.logical_not(x, name); - public static Tensor logical_or(Tensor x, Tensor y, string name = null) + public Tensor logical_or(Tensor x, Tensor y, string name = null) => gen_math_ops.logical_or(x, y, name); - public static Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor") + public Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor") => gen_math_ops.logical_xor(x, y, name); /// @@ -209,28 +209,28 @@ namespace Tensorflow /// /// /// - public static Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null) + public Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null) => gen_math_ops._clip_by_value(t, clip_value_min, clip_value_max); - public static Tensor sub(Tensor a, Tensor b) + public Tensor sub(Tensor a, Tensor b) => gen_math_ops.sub(a, b); - public static Tensor divide(Tensor a, Tensor b) + public Tensor divide(Tensor a, Tensor b) => gen_math_ops.real_div(a, b); - public static Tensor sqrt(Tensor a, string name = null) + public Tensor sqrt(Tensor a, string name = null) => gen_math_ops.sqrt(a, name); - public static Tensor sign(Tensor a, string name = null) + public Tensor sign(Tensor a, string name = null) => gen_math_ops.sign(a, name); - public static Tensor subtract(Tensor x, T[] y, string name = null) where T : struct + public Tensor subtract(Tensor x, T[] y, string name = null) where T : struct => gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name); - public static Tensor log(Tensor x, string name = null) + public Tensor log(Tensor x, string name = null) => gen_math_ops.log(x, name); - public static Tensor equal(Tensor x, Tensor y, string name = null) + public Tensor equal(Tensor x, Tensor y, string name = null) => gen_math_ops.equal(x, y, name); /// @@ -240,7 +240,7 @@ namespace Tensorflow /// /// /// - public static Tensor atan2(Tensor y, Tensor x, string name = null) + public Tensor atan2(Tensor y, Tensor x, string name = null) => gen_math_ops.atan2(y, x, name); /// @@ -253,7 +253,7 @@ namespace Tensorflow /// /// /// - public static Tensor max(Tx input, Ty axis, bool keep_dims = false, string name = null) + public Tensor max(Tx input, Ty axis, bool keep_dims = false, string name = null) => gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name); /// @@ -266,7 +266,7 @@ namespace Tensorflow /// /// /// - public static Tensor min(Tx input, Ty axis, bool keep_dims = false, string name = null) + public Tensor min(Tx input, Ty axis, bool keep_dims = false, string name = null) => gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name); /// @@ -278,7 +278,7 @@ namespace Tensorflow /// /// /// - public static Tensor maximum(T1 x, T2 y, string name = null) + public Tensor maximum(T1 x, T2 y, string name = null) => gen_math_ops.maximum(x, y, name: name); /// @@ -290,13 +290,13 @@ namespace Tensorflow /// /// /// - public static Tensor minimum(T1 x, T2 y, string name = null) + public Tensor minimum(T1 x, T2 y, string name = null) => gen_math_ops.minimum(x, y, name: name); - public static Tensor multiply(Tx x, Ty y) + public Tensor multiply(Tx x, Ty y) => gen_math_ops.mul(x, y); - public static Tensor negative(Tensor x, string name = null) + public Tensor negative(Tensor x, string name = null) => gen_math_ops.neg(x, name); /// @@ -306,13 +306,13 @@ namespace Tensorflow /// /// /// - public static Tensor div(Tensor x, Tensor y, string name = null) + public Tensor div(Tensor x, Tensor y, string name = null) => math_ops.div(x, y, name: name); - public static Tensor divide(Tensor x, T[] y, string name = null) where T : struct + public Tensor divide(Tensor x, T[] y, string name = null) where T : struct => x / ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"); - public static Tensor pow(T1 x, T2 y) + public Tensor pow(T1 x, T2 y) => gen_math_ops.pow(x, y); /// @@ -321,14 +321,14 @@ namespace Tensorflow /// /// /// - public static Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null) + public Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null) { if(!axis.HasValue && reduction_indices.HasValue) return math_ops.reduce_sum(input, reduction_indices.Value); return math_ops.reduce_sum(input); } - public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null) + public Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null) => math_ops.reduce_sum(input, axis); /// @@ -339,34 +339,34 @@ namespace Tensorflow /// /// /// - public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) + public Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) => math_ops.reduce_max(input_tensor, axis, keepdims, name); - public static Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) + public Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) => math_ops.reduce_min(input_tensor, axis, keepdims, name); - public static Tensor sigmoid(T x, string name = null) + public Tensor sigmoid(T x, string name = null) => math_ops.sigmoid(x, name: name); - public static Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null) + public Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null) => gen_math_ops._sum(input, axis, keep_dims: keep_dims, name: name); - public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null) + public Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null) => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices); - public static Tensor round(Tensor x, string name = null) + public Tensor round(Tensor x, string name = null) => gen_math_ops.round(x, name: name); - public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null) + public Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null) => math_ops.cast(x, dtype, name); - public static Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null) + public Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null) => math_ops.cumsum(x, axis: axis, exclusive: exclusive, reverse: reverse, name: name); - public static Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64) + public Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64) => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type); - public static Tensor square(Tensor x, string name = null) + public Tensor square(Tensor x, string name = null) => gen_math_ops.square(x, name: name); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.nn.cs b/src/TensorFlowNET.Core/APIs/tf.nn.cs index 8a631c05..e5ecb908 100644 --- a/src/TensorFlowNET.Core/APIs/tf.nn.cs +++ b/src/TensorFlowNET.Core/APIs/tf.nn.cs @@ -16,15 +16,17 @@ using Tensorflow.Operations; using Tensorflow.Operations.Activation; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static class nn + public nn_internal nn { get; } = new nn_internal(); + + public class nn_internal { - public static Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true, + public Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true, string data_format= "NHWC", int[] dilations= null, string name = null) { var parameters = new Conv2dParams @@ -54,7 +56,7 @@ namespace Tensorflow /// /// A scalar `Tensor` with the same type as `x`. /// A Tensor of the same shape of `x`. - public static Tensor dropout(Tensor x, Tensor keep_prob = null, Tensor noise_shape = null, int? seed = null, string name = null, + public Tensor dropout(Tensor x, Tensor keep_prob = null, Tensor noise_shape = null, int? seed = null, string name = null, float? rate = null) { Tensor keep = null; @@ -74,17 +76,17 @@ namespace Tensorflow /// /// /// A pair (outputs, state) - public static (Tensor, Tensor) dynamic_rnn(RNNCell cell, Tensor inputs, + public (Tensor, Tensor) dynamic_rnn(RNNCell cell, Tensor inputs, Tensor sequence_length = null, TF_DataType dtype = TF_DataType.DtInvalid, int? parallel_iterations = null, bool swap_memory = false, bool time_major = false) => rnn.dynamic_rnn(cell, inputs, sequence_length: sequence_length, dtype: dtype, parallel_iterations: parallel_iterations, swap_memory: swap_memory, time_major: time_major); - public static Tensor elu(Tensor features, string name = null) + public Tensor elu(Tensor features, string name = null) => gen_nn_ops.elu(features, name: name); - public static (Tensor, Tensor) moments(Tensor x, + public (Tensor, Tensor) moments(Tensor x, int[] axes, string name = null, bool keep_dims = false) => nn_impl.moments(x, @@ -92,7 +94,7 @@ namespace Tensorflow name: name, keep_dims: keep_dims); - public static Tensor embedding_lookup(RefVariable @params, + public Tensor embedding_lookup(RefVariable @params, Tensor ids, string partition_strategy = "mod", string name = null) => embedding_ops._embedding_lookup_and_transform(@params, @@ -100,7 +102,7 @@ namespace Tensorflow partition_strategy: partition_strategy, name: name); - public static Tensor embedding_lookup(Tensor @params, + public Tensor embedding_lookup(Tensor @params, Tensor ids, string partition_strategy = "mod", string name = null) => embedding_ops._embedding_lookup_and_transform(new Tensor[] { @params }, @@ -108,11 +110,11 @@ namespace Tensorflow partition_strategy: partition_strategy, name: name); - public static IActivation relu() => new relu(); + public IActivation relu() => new relu(); - public static Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name); + public Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name); - public static Tensor[] fused_batch_norm(Tensor x, + public Tensor[] fused_batch_norm(Tensor x, RefVariable scale, RefVariable offset, Tensor mean = null, @@ -126,29 +128,29 @@ namespace Tensorflow is_training: is_training, name: name); - public static IPoolFunction max_pool_fn => new MaxPoolFunction(); + public IPoolFunction max_pool_fn => new MaxPoolFunction(); - public static Tensor max_pool(Tensor value, int[] ksize, int[] strides, string padding, string data_format = "NHWC", string name = null) + public Tensor max_pool(Tensor value, int[] ksize, int[] strides, string padding, string data_format = "NHWC", string name = null) => nn_ops.max_pool(value, ksize, strides, padding, data_format: data_format, name: name); - public static Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = "InTopK") + public Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = "InTopK") => gen_ops.in_top_k(predictions, targets, k, name); - public static Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = null) + public Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = null) => gen_nn_ops.top_kv2(input, k: k, sorted: sorted, name: name); - public static Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null) + public Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null) { - return Python.tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => + return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => { name = scope; return gen_nn_ops.bias_add(value, bias, data_format: data_format, name: name); }); } - public static rnn_cell_impl rnn_cell => new rnn_cell_impl(); + public rnn_cell_impl rnn_cell => new rnn_cell_impl(); - public static Tensor softmax(Tensor logits, int axis = -1, string name = null) + public Tensor softmax(Tensor logits, int axis = -1, string name = null) => gen_nn_ops.softmax(logits, name); /// @@ -158,7 +160,7 @@ namespace Tensorflow /// /// /// - public static Tensor sparse_softmax_cross_entropy_with_logits(Tensor labels = null, + public Tensor sparse_softmax_cross_entropy_with_logits(Tensor labels = null, Tensor logits = null, string name = null) => nn_ops.sparse_softmax_cross_entropy_with_logits(labels: labels, logits: logits, name: name); @@ -170,7 +172,7 @@ namespace Tensorflow /// /// /// - public static Tensor softmax_cross_entropy_with_logits(Tensor labels, Tensor logits, int dim = -1, string name = null) + public Tensor softmax_cross_entropy_with_logits(Tensor labels, Tensor logits, int dim = -1, string name = null) { tf_with(ops.name_scope(name, "softmax_cross_entropy_with_logits_sg", new { logits, labels }), scope => { @@ -181,7 +183,7 @@ namespace Tensorflow return softmax_cross_entropy_with_logits_v2(labels, logits, axis: dim, name: name); } - public static Tensor softmax_cross_entropy_with_logits_v2(Tensor labels, Tensor logits, int axis = -1, string name = null) + public Tensor softmax_cross_entropy_with_logits_v2(Tensor labels, Tensor logits, int axis = -1, string name = null) => nn_ops.softmax_cross_entropy_with_logits_v2_helper(labels, logits, axis: axis, name: name); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.ops.cs b/src/TensorFlowNET.Core/APIs/tf.ops.cs index dbd1b246..ba678327 100644 --- a/src/TensorFlowNET.Core/APIs/tf.ops.cs +++ b/src/TensorFlowNET.Core/APIs/tf.ops.cs @@ -16,12 +16,12 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor assign(Tensor @ref, object value, bool validate_shape = true, bool use_locking = true, string name = null) + public Tensor assign(Tensor @ref, object value, bool validate_shape = true, bool use_locking = true, string name = null) => state_ops.assign(@ref, value, validate_shape, use_locking, name); - public static object get_collection(string key, string scope = "") + public object get_collection(string key, string scope = "") => get_default_graph().get_collection(key, scope: scope); /// @@ -31,7 +31,7 @@ namespace Tensorflow /// The default name to use if the name argument is None. /// The list of Tensor arguments that are passed to the op function. /// The scope name. - public static ops.NameScope name_scope(string name, string default_name = "", object values = null) + public ops.NameScope name_scope(string name, string default_name = "", object values = null) => new ops.NameScope(name, default_name, values); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.random.cs b/src/TensorFlowNET.Core/APIs/tf.random.cs index 338542d0..ae115872 100644 --- a/src/TensorFlowNET.Core/APIs/tf.random.cs +++ b/src/TensorFlowNET.Core/APIs/tf.random.cs @@ -16,7 +16,7 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { /// /// Outputs random values from a normal distribution. @@ -28,21 +28,21 @@ namespace Tensorflow /// /// /// - public static Tensor random_normal(int[] shape, + public Tensor random_normal(int[] shape, float mean = 0.0f, float stddev = 1.0f, TF_DataType dtype = TF_DataType.TF_FLOAT, int? seed = null, string name = null) => random_ops.random_normal(shape, mean, stddev, dtype, seed, name); - public static Tensor random_uniform(int[] shape, + public Tensor random_uniform(int[] shape, float minval = 0, float maxval = 1, TF_DataType dtype = TF_DataType.TF_FLOAT, int? seed = null, string name = null) => random_ops.random_uniform(shape, minval, maxval, dtype, seed, name); - public static Tensor truncated_normal(int[] shape, + public Tensor truncated_normal(int[] shape, float mean = 0.0f, float stddev = 1.0f, TF_DataType dtype = TF_DataType.TF_FLOAT, diff --git a/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs b/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs index d97dd34b..325f0633 100644 --- a/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs +++ b/src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs @@ -16,9 +16,9 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor reduce_logsumexp(Tensor input_tensor, + public Tensor reduce_logsumexp(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) => math_ops.reduce_logsumexp(input_tensor, axis, keepdims, name); diff --git a/src/TensorFlowNET.Core/APIs/tf.reshape.cs b/src/TensorFlowNET.Core/APIs/tf.reshape.cs index fac5271e..78a00432 100644 --- a/src/TensorFlowNET.Core/APIs/tf.reshape.cs +++ b/src/TensorFlowNET.Core/APIs/tf.reshape.cs @@ -16,13 +16,13 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor reshape(Tensor tensor, + public Tensor reshape(Tensor tensor, Tensor shape, string name = null) => gen_array_ops.reshape(tensor, shape, name); - public static Tensor reshape(Tensor tensor, + public Tensor reshape(Tensor tensor, int[] shape, string name = null) => gen_array_ops.reshape(tensor, shape, name); } diff --git a/src/TensorFlowNET.Core/APIs/tf.summary.cs b/src/TensorFlowNET.Core/APIs/tf.summary.cs index a5d52df4..a2611739 100644 --- a/src/TensorFlowNET.Core/APIs/tf.summary.cs +++ b/src/TensorFlowNET.Core/APIs/tf.summary.cs @@ -16,11 +16,11 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Summaries.Summary summary = new Summaries.Summary(); + public Summaries.Summary summary = new Summaries.Summary(); - public static Tensor scalar(string name, Tensor tensor) + public Tensor scalar(string name, Tensor tensor) => summary.scalar(name, tensor); } } diff --git a/src/TensorFlowNET.Core/APIs/tf.tensor.cs b/src/TensorFlowNET.Core/APIs/tf.tensor.cs index 24d3ddf1..b553095e 100644 --- a/src/TensorFlowNET.Core/APIs/tf.tensor.cs +++ b/src/TensorFlowNET.Core/APIs/tf.tensor.cs @@ -16,12 +16,12 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor convert_to_tensor(object value, + public Tensor convert_to_tensor(object value, string name = null) => ops.convert_to_tensor(value, name: name); - public static Tensor strided_slice(Tensor input, Tensor begin, Tensor end, Tensor strides = null, + public Tensor strided_slice(Tensor input, Tensor begin, Tensor end, Tensor strides = null, int begin_mask = 0, int end_mask = 0, int ellipsis_mask = 0, @@ -38,7 +38,7 @@ namespace Tensorflow shrink_axis_mask: shrink_axis_mask, name: name); - public static Tensor strided_slice(Tensor input, T[] begin, T[] end, T[] strides = null, + public Tensor strided_slice(Tensor input, T[] begin, T[] end, T[] strides = null, int begin_mask = 0, int end_mask = 0, int ellipsis_mask = 0, diff --git a/src/TensorFlowNET.Core/APIs/tf.tile.cs b/src/TensorFlowNET.Core/APIs/tf.tile.cs index 3001166b..21017a17 100644 --- a/src/TensorFlowNET.Core/APIs/tf.tile.cs +++ b/src/TensorFlowNET.Core/APIs/tf.tile.cs @@ -18,12 +18,12 @@ using NumSharp; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static Tensor tile(Tensor input, + public Tensor tile(Tensor input, Tensor multiples, string name = null) => gen_array_ops.tile(input, multiples, name); - public static Tensor tile(NDArray input, + public Tensor tile(NDArray input, int[] multiples, string name = null) => gen_array_ops.tile(input, multiples, name); diff --git a/src/TensorFlowNET.Core/APIs/tf.variable.cs b/src/TensorFlowNET.Core/APIs/tf.variable.cs index 6512fd92..e855535a 100644 --- a/src/TensorFlowNET.Core/APIs/tf.variable.cs +++ b/src/TensorFlowNET.Core/APIs/tf.variable.cs @@ -18,21 +18,21 @@ using System.Collections.Generic; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static VariableV1[] global_variables(string scope = null) + public VariableV1[] global_variables(string scope = null) { return (ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope) as List) .ToArray(); } - public static Operation global_variables_initializer() + public Operation global_variables_initializer() { var g = variables.global_variables(); return variables.variables_initializer(g.ToArray()); } - public static RefVariable get_variable(string name, + public RefVariable get_variable(string name, TensorShape shape = null, TF_DataType dtype = TF_DataType.DtInvalid, object initializer = null, // IInitializer or Tensor diff --git a/src/TensorFlowNET.Core/Python.cs b/src/TensorFlowNET.Core/Binding.Util.cs similarity index 84% rename from src/TensorFlowNET.Core/Python.cs rename to src/TensorFlowNET.Core/Binding.Util.cs index e4585c61..da2cdf6e 100644 --- a/src/TensorFlowNET.Core/Python.cs +++ b/src/TensorFlowNET.Core/Binding.Util.cs @@ -15,7 +15,6 @@ ******************************************************************************/ using NumSharp; -using NumSharp.Backends; using System; using System.Collections; using System.Collections.Generic; @@ -26,18 +25,15 @@ using System.Linq; namespace Tensorflow { /// - /// Mapping C# functions to Python + /// Binding utilities to mimic python functions. /// - public static class Python + public static partial class Binding { public static void print(object obj) { Console.WriteLine(obj.ToString()); } - //protected int len(IEnumerable a) - // => a.Count(); - public static int len(object a) { switch (a) @@ -66,17 +62,15 @@ namespace Tensorflow return Enumerable.Range(start, end - start); } - public static T New(object args) where T : IPyClass + public static T New() where T : IObjectLife, new() { - var instance = Activator.CreateInstance(); - - instance.__init__(instance, args); - + var instance = new T(); + instance.__init__(); return instance; } [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception - public static void tf_with(IPython py, Action action) + public static void tf_with(IObjectLife py, Action action) { try { @@ -96,7 +90,7 @@ namespace Tensorflow } [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception - public static void tf_with(T py, Action action) where T : IPython + public static void tf_with(T py, Action action) where T : IObjectLife { try { @@ -116,7 +110,7 @@ namespace Tensorflow } [DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception - public static TOut tf_with(TIn py, Func action) where TIn : IPython + public static TOut tf_with(TIn py, Func action) where TIn : IObjectLife { try { @@ -126,7 +120,6 @@ namespace Tensorflow catch (Exception ex) { Console.WriteLine(ex.ToString()); - throw; return default(TOut); } finally @@ -278,7 +271,9 @@ namespace Tensorflow var __memberobject__ = __type__.GetMember(key); return (__memberobject__.Length > 0) ? true : false; } + public delegate object __object__(params object[] args); + public static __object__ getattr(object obj, string key, params Type[] ___parameter_type__) { var __dyn_obj__ = obj.GetType().GetMember(key); @@ -290,7 +285,7 @@ namespace Tensorflow try { var __method__ = (___parameter_type__.Length > 0) ? obj.GetType().GetMethod(key, ___parameter_type__) : obj.GetType().GetMethod(key); - return (__object__)((object[] args) => __method__.Invoke(obj, args)); + return (object[] args) => __method__.Invoke(obj, args); } catch (System.Reflection.AmbiguousMatchException ex) { @@ -299,27 +294,48 @@ namespace Tensorflow } else if (__type__.MemberType == System.Reflection.MemberTypes.Field) { - var __field__ = (object)obj.GetType().GetField(key).GetValue(obj); - return (__object__)((object[] args) => { return __field__; }); + var __field__ = obj.GetType().GetField(key).GetValue(obj); + return (object[] args) => { return __field__; }; } else if (__type__.MemberType == System.Reflection.MemberTypes.Property) { - var __property__ = (object)obj.GetType().GetProperty(key).GetValue(obj); - return (__object__)((object[] args) => { return __property__; }); + var __property__ = obj.GetType().GetProperty(key).GetValue(obj); + return (object[] args) => { return __property__; }; } - return (__object__)((object[] args) => { return "NaN"; }); + return (object[] args) => { return "NaN"; }; } - } - public interface IPython : IDisposable - { - void __enter__(); + public static IEnumerable TupleToEnumerable(object tuple) + { + Type t = tuple.GetType(); + if(t.IsGenericType && (t.FullName.StartsWith("System.Tuple") || t.FullName.StartsWith("System.ValueTuple"))) + { + var flds = t.GetFields(); + for(int i = 0; i < flds.Length;i++) + { + yield return flds[i].GetValue(tuple); + } + } + else + { + throw new System.Exception("Expected Tuple."); + } + } - void __exit__(); - } + public static bool isinstance(object Item1, Type Item2) + { + return Item1.GetType() == Item2; + } - public class PyObject where T : IPyClass - { - public T Instance { get; set; } + public static bool isinstance(object Item1, object tuple) + { + var tup = TupleToEnumerable(tuple); + foreach(var t in tup) + { + if(isinstance(Item1, (Type)t)) + return true; + } + return false; + } } } diff --git a/src/TensorFlowNET.Core/Binding.cs b/src/TensorFlowNET.Core/Binding.cs new file mode 100644 index 00000000..f443f2eb --- /dev/null +++ b/src/TensorFlowNET.Core/Binding.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public static partial class Binding + { + public static tensorflow tf { get; } = New(); + } +} diff --git a/src/TensorFlowNET.Core/Clustering/KMeans.cs b/src/TensorFlowNET.Core/Clustering/KMeans.cs index 1ef948a0..e3f2ab2a 100644 --- a/src/TensorFlowNET.Core/Clustering/KMeans.cs +++ b/src/TensorFlowNET.Core/Clustering/KMeans.cs @@ -15,6 +15,7 @@ ******************************************************************************/ using System; +using static Tensorflow.Binding; namespace Tensorflow.Clustering { diff --git a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs index 8112708f..2e86a5ea 100644 --- a/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs +++ b/src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Clustering { diff --git a/src/TensorFlowNET.Core/Framework/graph_util_impl.cs b/src/TensorFlowNET.Core/Framework/graph_util_impl.cs index f9514173..280ee8b9 100644 --- a/src/TensorFlowNET.Core/Framework/graph_util_impl.cs +++ b/src/TensorFlowNET.Core/Framework/graph_util_impl.cs @@ -18,7 +18,7 @@ using NumSharp; using System; using System.Collections.Generic; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Framework/importer.py.cs b/src/TensorFlowNET.Core/Framework/importer.py.cs index 254fda19..b6c011c4 100644 --- a/src/TensorFlowNET.Core/Framework/importer.py.cs +++ b/src/TensorFlowNET.Core/Framework/importer.py.cs @@ -19,7 +19,7 @@ using System; using System.Collections.Generic; using System.Linq; using static Tensorflow.OpDef.Types; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Framework/meta_graph.py.cs b/src/TensorFlowNET.Core/Framework/meta_graph.py.cs index 4a10ba1e..db9dba38 100644 --- a/src/TensorFlowNET.Core/Framework/meta_graph.py.cs +++ b/src/TensorFlowNET.Core/Framework/meta_graph.py.cs @@ -22,6 +22,7 @@ using System.Linq; using Tensorflow.Operations; using static Tensorflow.CollectionDef; using static Tensorflow.MetaGraphDef.Types; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Gradients/array_grad.cs b/src/TensorFlowNET.Core/Gradients/array_grad.cs index 11dfcc89..e98ec21e 100644 --- a/src/TensorFlowNET.Core/Gradients/array_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/array_grad.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using Tensorflow.Framework; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Gradients { @@ -196,6 +196,12 @@ namespace Tensorflow.Gradients return new Tensor[] { _ReshapeToInput(op, grads[0]) }; } + [RegisterGradient("StopGradient")] + public static Tensor[] _NoGradient(Operation op, Tensor[] grads) + { + return new Tensor[] {null}; + } + /// /// Gradient for StridedSlice op. /// diff --git a/src/TensorFlowNET.Core/Gradients/gradients_util.cs b/src/TensorFlowNET.Core/Gradients/gradients_util.cs index 43247fa4..3b6d0eea 100644 --- a/src/TensorFlowNET.Core/Gradients/gradients_util.cs +++ b/src/TensorFlowNET.Core/Gradients/gradients_util.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Gradients/math_grad.cs b/src/TensorFlowNET.Core/Gradients/math_grad.cs index a5ac79ba..672270b9 100644 --- a/src/TensorFlowNET.Core/Gradients/math_grad.cs +++ b/src/TensorFlowNET.Core/Gradients/math_grad.cs @@ -17,7 +17,7 @@ using System; using System.Linq; using Tensorflow.Operations; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Gradients { diff --git a/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs b/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs index f066676d..6c9f6b18 100644 --- a/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs +++ b/src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Linq; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs index 1030922b..436afcc9 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Graphs/Graph.cs b/src/TensorFlowNET.Core/Graphs/Graph.cs index 6656862f..77926dca 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.cs @@ -19,6 +19,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; +using static Tensorflow.Binding; namespace Tensorflow { @@ -247,7 +248,7 @@ namespace Tensorflow if (inputs == null) inputs = new Tensor[0]; - foreach ((int idx, Tensor a) in Python.enumerate(inputs)) + foreach ((int idx, Tensor a) in enumerate(inputs)) { } diff --git a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs index 900a77ec..6a75c982 100644 --- a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs +++ b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs @@ -22,7 +22,7 @@ namespace Tensorflow /// /// Context manager for `control_dependencies()` /// - public class _ControlDependenciesController : IPython + public class _ControlDependenciesController : IObjectLife { private Graph _graph; private List _control_inputs_val; @@ -110,6 +110,16 @@ namespace Tensorflow public void Dispose() { - } + } + + public void __init__() + { + + } + + public void __del__() + { + + } } } diff --git a/src/TensorFlowNET.Core/IPyClass.cs b/src/TensorFlowNET.Core/IObjectLife.cs similarity index 82% rename from src/TensorFlowNET.Core/IPyClass.cs rename to src/TensorFlowNET.Core/IObjectLife.cs index 4cde6ce5..a3978cc2 100644 --- a/src/TensorFlowNET.Core/IPyClass.cs +++ b/src/TensorFlowNET.Core/IObjectLife.cs @@ -14,20 +14,22 @@ limitations under the License. ******************************************************************************/ +using System; + namespace Tensorflow { - public interface IPyClass + public interface IObjectLife : IDisposable { /// /// Called when the instance is created. /// /// - void __init__(IPyClass self, dynamic args); + void __init__(); - void __enter__(IPyClass self); + void __enter__(); - void __exit__(IPyClass self); + void __exit__(); - void __del__(IPyClass self); + void __del__(); } } diff --git a/src/TensorFlowNET.Core/Keras/BackendBase.cs b/src/TensorFlowNET.Core/Keras/BackendBase.cs index 0b553644..a53db62e 100644 --- a/src/TensorFlowNET.Core/Keras/BackendBase.cs +++ b/src/TensorFlowNET.Core/Keras/BackendBase.cs @@ -15,6 +15,7 @@ ******************************************************************************/ using System; +using static Tensorflow.Binding; namespace Tensorflow.Keras { @@ -43,9 +44,9 @@ namespace Tensorflow.Keras { if (value == null) value = _IMAGE_DATA_FORMAT; - if (value.GetType() == typeof(ImageDataFormat)) + if (isinstance(value, typeof(ImageDataFormat))) return (ImageDataFormat)value; - else if (value.GetType() == typeof(string)) + else if (isinstance(value, typeof(string))) { ImageDataFormat dataFormat; if(Enum.TryParse((string)value, true, out dataFormat)) diff --git a/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs b/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs index 651961b4..e18b401c 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/Sequential.cs @@ -18,7 +18,7 @@ using Tensorflow.Keras.Layers; namespace Tensorflow.Keras.Engine { - public class Sequential : Model, IPython + public class Sequential : Model, IObjectLife { public Sequential(string name = null) : base(name: name) @@ -69,5 +69,15 @@ namespace Tensorflow.Keras.Engine { } + + public void __init__() + { + + } + + public void __del__() + { + + } } } diff --git a/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs b/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs index 156cc8c9..929b3a3f 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs @@ -17,6 +17,7 @@ using System; using System.Linq; using Tensorflow.Keras.Utils; +using static Tensorflow.Binding; namespace Tensorflow.Keras.Layers { @@ -82,7 +83,7 @@ namespace Tensorflow.Keras.Layers protected override void build(TensorShape input_shape) { var ndims = input_shape.ndim; - foreach (var (idx, x) in Python.enumerate(axis)) + foreach (var (idx, x) in enumerate(axis)) if (x < 0) axis[idx] = ndims + x; @@ -207,7 +208,7 @@ namespace Tensorflow.Keras.Layers public Tensor _assign_moving_average(RefVariable variable, Tensor value, Tensor momentum) { - return Python.tf_with(ops.name_scope(null, "AssignMovingAvg", new { variable, value, momentum }), scope => + return tf_with(ops.name_scope(null, "AssignMovingAvg", new { variable, value, momentum }), scope => { // var cm = ops.colocate_with(variable); var decay = ops.convert_to_tensor(1.0f - momentum, name: "decay"); diff --git a/src/TensorFlowNET.Core/Keras/Layers/Dense.cs b/src/TensorFlowNET.Core/Keras/Layers/Dense.cs index e2cea7f3..adfae5d1 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Dense.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Dense.cs @@ -19,7 +19,7 @@ using System.Collections.Generic; using System.Linq; using Tensorflow.Keras.Engine; using Tensorflow.Operations.Activation; -using static Tensorflow.tf; +using static Tensorflow.Binding; namespace Tensorflow.Keras.Layers { @@ -86,7 +86,7 @@ namespace Tensorflow.Keras.Layers } if (use_bias) - outputs = nn.bias_add(outputs, bias); + outputs = tf.nn.bias_add(outputs, bias); if (activation != null) return activation.Activate(outputs); diff --git a/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs b/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs index 299f158d..37f15baf 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Embedding.cs @@ -14,6 +14,8 @@ limitations under the License. ******************************************************************************/ +using static Tensorflow.Binding; + namespace Tensorflow.Keras.Layers { public class Embedding : Layer diff --git a/src/TensorFlowNET.Core/Keras/Layers/Layer.cs b/src/TensorFlowNET.Core/Keras/Layers/Layer.cs index d96c1f14..6681ec56 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/Layer.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/Layer.cs @@ -20,7 +20,7 @@ using System.Linq; using Tensorflow.Keras.Engine; using Tensorflow.Keras.Utils; using Tensorflow.Train; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Keras.Layers { diff --git a/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs b/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs index 77e78e1c..27234078 100644 --- a/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs +++ b/src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs @@ -1,4 +1,4 @@ -using static Tensorflow.tf; +using static Tensorflow.Binding; namespace Tensorflow.Keras.Layers { @@ -9,7 +9,7 @@ namespace Tensorflow.Keras.Layers int[] strides, string padding = "valid", string data_format = null, - string name = null) : base(nn.max_pool_fn, pool_size, + string name = null) : base(tf.nn.max_pool_fn, pool_size, strides, padding: padding, data_format: data_format, diff --git a/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs b/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs index a34d9ad0..d4feebc2 100644 --- a/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs +++ b/src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Linq; +using static Tensorflow.Binding; namespace Tensorflow.Keras.Utils { diff --git a/src/TensorFlowNET.Core/Keras/backend.cs b/src/TensorFlowNET.Core/Keras/backend.cs index 3760df04..5ac04f1a 100644 --- a/src/TensorFlowNET.Core/Keras/backend.cs +++ b/src/TensorFlowNET.Core/Keras/backend.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Keras { @@ -28,7 +28,7 @@ namespace Tensorflow.Keras //Func py_any = any; //Func> py_slice = slice; - public static Session _SESSION = Tensorflow.tf.defaultSession; + public static Session _SESSION = tf.defaultSession; public static Graph _GRAPH = null; public static Dictionary _GRAPH_LEARNING_PHASES; //Dictionary> PER_GRAPH_LAYER_NAME_UIDS; diff --git a/src/TensorFlowNET.Core/Keras/tf.keras.cs b/src/TensorFlowNET.Core/Keras/tf.keras.cs index bf439809..dee173f8 100644 --- a/src/TensorFlowNET.Core/Keras/tf.keras.cs +++ b/src/TensorFlowNET.Core/Keras/tf.keras.cs @@ -2,9 +2,9 @@ namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static class keras + public class keras { public static Initializers initializers => new Initializers(); } diff --git a/src/TensorFlowNET.Core/Layers/Layer.cs b/src/TensorFlowNET.Core/Layers/Layer.cs index 961952a6..304e7f7b 100644 --- a/src/TensorFlowNET.Core/Layers/Layer.cs +++ b/src/TensorFlowNET.Core/Layers/Layer.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Layers { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs index 136c9e3b..b1503567 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; using Tensorflow.Operations.ControlFlows; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs index 5cfecc49..2c05e36a 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs @@ -39,7 +39,7 @@ namespace Tensorflow.Operations /// 4. A ControlFlowContext has _context_stack. /// Pushed and popped by ctxt.Enter() and ctxt.Exit() /// - public abstract class ControlFlowContext : IPython + public abstract class ControlFlowContext : IObjectLife { /// /// The predicate tensor in this branch @@ -265,5 +265,14 @@ namespace Tensorflow.Operations { } + public void __init__() + { + + } + + public void __del__() + { + + } } } diff --git a/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs b/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs index c5e7121c..ccd88480 100644 --- a/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs +++ b/src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs @@ -19,8 +19,8 @@ using System.Collections.Generic; using System.Linq; using Tensorflow.Operations.ControlFlows; using Tensorflow.Util; -using static Tensorflow.Python; using static Tensorflow.control_flow_ops; +using static Tensorflow.Binding; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs index 69affeea..16be7bfb 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs @@ -17,7 +17,7 @@ //Base classes for probability distributions. using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow diff --git a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs index f4f4b4bf..c7483f96 100644 --- a/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs +++ b/src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; 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 c5a6ad22..de4bf964 100644 --- a/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using System; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs index b385f9c8..e28557c7 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs b/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs index b4955dec..3198942b 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/rnn.cs @@ -17,9 +17,8 @@ using System; using System.Collections.Generic; using System.Linq; -using static Tensorflow.Python; using Tensorflow.Util; -using NumSharp; +using static Tensorflow.Binding; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs index 934ae7d2..e6799f61 100644 --- a/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs +++ b/src/TensorFlowNET.Core/Operations/OpDefLibrary.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; using static Tensorflow.OpDef.Types; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { @@ -141,7 +141,7 @@ namespace Tensorflow dtype = input_arg.Type; else if (attrs.ContainsKey(input_arg.TypeAttr)) dtype = (DataType)attrs[input_arg.TypeAttr]; - else if (values.GetType() == typeof(string) && dtype == DataType.DtInvalid) + else if (isinstance(values, typeof(string)) && dtype == DataType.DtInvalid) dtype = DataType.DtString; else if (default_type_attr_map.ContainsKey(input_arg.TypeAttr)) default_dtype = (DataType)default_type_attr_map[input_arg.TypeAttr]; diff --git a/src/TensorFlowNET.Core/Operations/RNNCell.cs b/src/TensorFlowNET.Core/Operations/RNNCell.cs index 1b260981..442115c0 100644 --- a/src/TensorFlowNET.Core/Operations/RNNCell.cs +++ b/src/TensorFlowNET.Core/Operations/RNNCell.cs @@ -17,7 +17,7 @@ using System; using Tensorflow.Operations; using Tensorflow.Util; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/_GraphTensorArray.cs b/src/TensorFlowNET.Core/Operations/_GraphTensorArray.cs index bbeee929..4c700a5f 100644 --- a/src/TensorFlowNET.Core/Operations/_GraphTensorArray.cs +++ b/src/TensorFlowNET.Core/Operations/_GraphTensorArray.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Text; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Operations { diff --git a/src/TensorFlowNET.Core/Operations/array_ops.py.cs b/src/TensorFlowNET.Core/Operations/array_ops.py.cs index f563a61f..d3213250 100644 --- a/src/TensorFlowNET.Core/Operations/array_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/array_ops.py.cs @@ -17,7 +17,7 @@ using NumSharp; using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/check_ops.cs b/src/TensorFlowNET.Core/Operations/check_ops.cs index 06b648b6..8b670640 100644 --- a/src/TensorFlowNET.Core/Operations/check_ops.cs +++ b/src/TensorFlowNET.Core/Operations/check_ops.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs b/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs index b2790de0..b48139e0 100644 --- a/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs +++ b/src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using System; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs index c8c711e7..04595256 100644 --- a/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs @@ -20,7 +20,7 @@ using System.Linq; using Tensorflow.Operations; using Tensorflow.Operations.ControlFlows; using util = Tensorflow.control_flow_util; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/embedding_ops.cs b/src/TensorFlowNET.Core/Operations/embedding_ops.cs index 23864329..3c02e825 100644 --- a/src/TensorFlowNET.Core/Operations/embedding_ops.cs +++ b/src/TensorFlowNET.Core/Operations/embedding_ops.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using System; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs index dc7188a8..baaf4fbe 100644 --- a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using System; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index 1e2363e4..fa1fda12 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -18,7 +18,7 @@ using NumSharp; using System; using System.Collections.Generic; using Tensorflow.Framework; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs index 84fb5486..bd70c10a 100644 --- a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs @@ -15,7 +15,7 @@ ******************************************************************************/ using Tensorflow.Operations; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/nn_ops.cs b/src/TensorFlowNET.Core/Operations/nn_ops.cs index 1a63dc20..cbf55861 100644 --- a/src/TensorFlowNET.Core/Operations/nn_ops.cs +++ b/src/TensorFlowNET.Core/Operations/nn_ops.cs @@ -17,7 +17,7 @@ using System; using System.Linq; using Tensorflow.Operations; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { @@ -50,7 +50,7 @@ namespace Tensorflow string data_format = null, string name = null) { - return Python.tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => + return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => { name = scope; value = ops.convert_to_tensor(value, name: "input"); diff --git a/src/TensorFlowNET.Core/Operations/random_ops.py.cs b/src/TensorFlowNET.Core/Operations/random_ops.py.cs index 3232c917..9ca4db88 100644 --- a/src/TensorFlowNET.Core/Operations/random_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/random_ops.py.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs b/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs index d8bfcbac..8895c147 100644 --- a/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs +++ b/src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Sessions/Session.cs b/src/TensorFlowNET.Core/Sessions/Session.cs index 6b238ae7..ec2e443f 100644 --- a/src/TensorFlowNET.Core/Sessions/Session.cs +++ b/src/TensorFlowNET.Core/Sessions/Session.cs @@ -15,11 +15,11 @@ ******************************************************************************/ using System; -using System.Runtime.InteropServices; +using static Tensorflow.Binding; namespace Tensorflow { - public class Session : BaseSession, IPython + public class Session : BaseSession, IObjectLife { public Session(string target = "", Graph g = null) : base(target, g, null) @@ -85,5 +85,15 @@ namespace Tensorflow { } + + public void __init__() + { + + } + + public void __del__() + { + + } } } diff --git a/src/TensorFlowNET.Core/Summaries/Summary.cs b/src/TensorFlowNET.Core/Summaries/Summary.cs index 258edf88..2bea0ddc 100644 --- a/src/TensorFlowNET.Core/Summaries/Summary.cs +++ b/src/TensorFlowNET.Core/Summaries/Summary.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Summaries { diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs index 4bd32d74..eb912eb9 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs @@ -16,7 +16,7 @@ using System; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index 312dde43..d52b9422 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -21,7 +21,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using Tensorflow.Framework; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/constant_op.cs b/src/TensorFlowNET.Core/Tensors/constant_op.cs index 2e4f64eb..92eda9ba 100644 --- a/src/TensorFlowNET.Core/Tensors/constant_op.cs +++ b/src/TensorFlowNET.Core/Tensors/constant_op.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Tensors/tf.constant.cs b/src/TensorFlowNET.Core/Tensors/tf.constant.cs index ddb450e2..a6516740 100644 --- a/src/TensorFlowNET.Core/Tensors/tf.constant.cs +++ b/src/TensorFlowNET.Core/Tensors/tf.constant.cs @@ -18,11 +18,11 @@ using NumSharp; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { // public static Tensor constant(NDArray nd, string name = "Const") => constant_op.constant(nd, name: name); - public static Tensor constant(object value, + public Tensor constant(object value, TF_DataType dtype = TF_DataType.DtInvalid, int[] shape = null, string name = "Const", @@ -33,30 +33,30 @@ namespace Tensorflow verify_shape: verify_shape, allow_broadcast: false); - public static Tensor constant(string value, + public Tensor constant(string value, string name = "Const") => constant_op._constant_impl(value, - tf.@string, + @string, new int[] { 1 }, name, verify_shape: false, allow_broadcast: false); - public static Tensor constant(float value, + public Tensor constant(float value, int shape, string name = "Const") => constant_op._constant_impl(value, - tf.float32, + float32, new int[] { shape }, name, verify_shape: false, allow_broadcast: false); - public static Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) + public Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) => array_ops.zeros(shape, dtype, name); - public static Tensor ones(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) + public Tensor ones(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) => array_ops.ones(shape, dtype, name); - public static Tensor size(Tensor input, + public Tensor size(Tensor input, string name = null, TF_DataType out_type = TF_DataType.TF_INT32) => array_ops.size(input, name, diff --git a/src/TensorFlowNET.Core/Train/AdamOptimizer.cs b/src/TensorFlowNET.Core/Train/AdamOptimizer.cs index 673e1307..d182a5cd 100644 --- a/src/TensorFlowNET.Core/Train/AdamOptimizer.cs +++ b/src/TensorFlowNET.Core/Train/AdamOptimizer.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; using Tensorflow.Framework; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Train { diff --git a/src/TensorFlowNET.Core/Train/Optimizer.cs b/src/TensorFlowNET.Core/Train/Optimizer.cs index e945b120..c031da54 100644 --- a/src/TensorFlowNET.Core/Train/Optimizer.cs +++ b/src/TensorFlowNET.Core/Train/Optimizer.cs @@ -19,7 +19,7 @@ using System.Collections.Generic; using System.Linq; using Tensorflow.Framework; using Tensorflow.Train; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { @@ -382,7 +382,7 @@ namespace Tensorflow if ((int)gate_gradients == Optimizer.GATE_GRAPH) grads = control_flow_ops.tuple(grads); - var grads_and_vars = Python.zip(grads, var_list) + var grads_and_vars = zip(grads, var_list) .Select(x => new Tuple(x.Item1, x.Item2)) .ToArray(); diff --git a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs index 95775a72..c9b60d32 100644 --- a/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs +++ b/src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Linq; using Tensorflow.Operations; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Train/Saving/Saver.cs b/src/TensorFlowNET.Core/Train/Saving/Saver.cs index 781c6461..3f72a438 100644 --- a/src/TensorFlowNET.Core/Train/Saving/Saver.cs +++ b/src/TensorFlowNET.Core/Train/Saving/Saver.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { @@ -144,7 +144,7 @@ namespace Tensorflow _check_saver_def(); - _next_checkpoint_time = Python.time() + _saver_def.KeepCheckpointEveryNHours * 3600; + _next_checkpoint_time = time() + _saver_def.KeepCheckpointEveryNHours * 3600; } private void _check_saver_def() diff --git a/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs b/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs index 267e7561..1e119405 100644 --- a/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs +++ b/src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Train/SlotCreator.cs b/src/TensorFlowNET.Core/Train/SlotCreator.cs index 57582355..29e073c7 100644 --- a/src/TensorFlowNET.Core/Train/SlotCreator.cs +++ b/src/TensorFlowNET.Core/Train/SlotCreator.cs @@ -16,7 +16,7 @@ using System; using Tensorflow.Operations.Initializers; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow.Train { diff --git a/src/TensorFlowNET.Core/Train/tf.optimizers.cs b/src/TensorFlowNET.Core/Train/tf.optimizers.cs index 5dee2060..0c801f90 100644 --- a/src/TensorFlowNET.Core/Train/tf.optimizers.cs +++ b/src/TensorFlowNET.Core/Train/tf.optimizers.cs @@ -19,28 +19,30 @@ using Tensorflow.Train; namespace Tensorflow { - public static partial class tf + public partial class tensorflow { - public static class train + public train_internal train { get; } = new train_internal(); + + public class train_internal { - public static Optimizer GradientDescentOptimizer(float learning_rate) + public Optimizer GradientDescentOptimizer(float learning_rate) => new GradientDescentOptimizer(learning_rate); - public static Optimizer AdamOptimizer(float learning_rate, string name = "Adam") + public Optimizer AdamOptimizer(float learning_rate, string name = "Adam") => new AdamOptimizer(learning_rate, name: name); - public static Saver Saver(VariableV1[] var_list = null) => new Saver(var_list: var_list); + public Saver Saver(VariableV1[] var_list = null) => new Saver(var_list: var_list); - public static string write_graph(Graph graph, string logdir, string name, bool as_text = true) + public string write_graph(Graph graph, string logdir, string name, bool as_text = true) => graph_io.write_graph(graph, logdir, name, as_text); - public static Saver import_meta_graph(string meta_graph_or_file, + public Saver import_meta_graph(string meta_graph_or_file, bool clear_devices = false, string import_scope = "") => saver._import_meta_graph_with_return_elements(meta_graph_or_file, clear_devices, import_scope).Item1; - public static (MetaGraphDef, Dictionary) export_meta_graph(string filename = "", + public (MetaGraphDef, Dictionary) export_meta_graph(string filename = "", bool as_text = false, bool clear_devices = false, bool clear_extraneous_savers = false, diff --git a/src/TensorFlowNET.Core/Util/nest.py.cs b/src/TensorFlowNET.Core/Util/nest.py.cs index 5f782ba2..b3ae594f 100644 --- a/src/TensorFlowNET.Core/Util/nest.py.cs +++ b/src/TensorFlowNET.Core/Util/nest.py.cs @@ -79,10 +79,10 @@ namespace Tensorflow.Util } public static IEnumerable<(T1, T2)> zip(IEnumerable e1, IEnumerable e2) - => Python.zip(e1, e2); + => zip(e1, e2); public static Dictionary ConvertToDict(object dyn) - => Python.ConvertToDict(dyn); + => ConvertToDict(dyn); //def _get_attrs_values(obj): // """Returns the list of values from an attrs instance.""" diff --git a/src/TensorFlowNET.Core/Variables/PureVariableScope.cs b/src/TensorFlowNET.Core/Variables/PureVariableScope.cs index b6cd2add..2326d9e3 100644 --- a/src/TensorFlowNET.Core/Variables/PureVariableScope.cs +++ b/src/TensorFlowNET.Core/Variables/PureVariableScope.cs @@ -19,7 +19,7 @@ using System.Linq; namespace Tensorflow { - public class PureVariableScope : IPython + public class PureVariableScope : IObjectLife { private string _name; private VariableScope _scope; @@ -101,6 +101,16 @@ namespace Tensorflow _var_scope_store.current_scope = _old; } + public void __init__() + { + + } + + public void __del__() + { + + } + public static implicit operator VariableScope(PureVariableScope scope) { return scope.variable_scope_object; diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs index 5adf5d9a..b4c77226 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.cs b/src/TensorFlowNET.Core/Variables/RefVariable.cs index 463ba2d0..9ac7e6ea 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.cs @@ -17,7 +17,7 @@ using Google.Protobuf; using System; using System.Collections.Generic; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/VariableScope.cs b/src/TensorFlowNET.Core/Variables/VariableScope.cs index 778e59b1..afc221c8 100644 --- a/src/TensorFlowNET.Core/Variables/VariableScope.cs +++ b/src/TensorFlowNET.Core/Variables/VariableScope.cs @@ -14,7 +14,7 @@ limitations under the License. ******************************************************************************/ -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/_VariableStore.cs b/src/TensorFlowNET.Core/Variables/_VariableStore.cs index 06719dc1..8957568e 100644 --- a/src/TensorFlowNET.Core/Variables/_VariableStore.cs +++ b/src/TensorFlowNET.Core/Variables/_VariableStore.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using static Tensorflow.Binding; namespace Tensorflow { diff --git a/src/TensorFlowNET.Core/Variables/variable_scope.py.cs b/src/TensorFlowNET.Core/Variables/variable_scope.py.cs index 9a658c77..6bc83052 100644 --- a/src/TensorFlowNET.Core/Variables/variable_scope.py.cs +++ b/src/TensorFlowNET.Core/Variables/variable_scope.py.cs @@ -23,7 +23,7 @@ namespace Tensorflow /// /// A context manager for defining ops that creates variables (layers). /// - public class variable_scope : IPython + public class variable_scope : IObjectLife { public static string _VARSTORE_KEY = "__variable_store"; public static string _VARSCOPESTORE_KEY = "__varscope"; @@ -293,5 +293,15 @@ namespace Tensorflow { throw new NotImplementedException(); } + + public void __init__() + { + + } + + public void __del__() + { + + } } } diff --git a/src/TensorFlowNET.Core/ops._DefaultStack.cs b/src/TensorFlowNET.Core/ops._DefaultStack.cs index ecdd8d9b..3a6932a4 100644 --- a/src/TensorFlowNET.Core/ops._DefaultStack.cs +++ b/src/TensorFlowNET.Core/ops._DefaultStack.cs @@ -23,7 +23,7 @@ namespace Tensorflow { _DefaultStack _default_session_stack = new _DefaultStack(); - public class _DefaultStack : IPython + public class _DefaultStack : IObjectLife { Stack stack; bool _enforce_nesting = true; @@ -35,18 +35,28 @@ namespace Tensorflow public void __enter__() { - throw new NotImplementedException(); + } public void __exit__() { - throw new NotImplementedException(); + } public void Dispose() { throw new NotImplementedException(); } + + public void __init__() + { + + } + + public void __del__() + { + + } } } } diff --git a/src/TensorFlowNET.Core/ops.py.cs b/src/TensorFlowNET.Core/ops.cs similarity index 99% rename from src/TensorFlowNET.Core/ops.py.cs rename to src/TensorFlowNET.Core/ops.cs index 979e132e..b2945f13 100644 --- a/src/TensorFlowNET.Core/ops.py.cs +++ b/src/TensorFlowNET.Core/ops.cs @@ -20,7 +20,7 @@ using System.Runtime.InteropServices; using Google.Protobuf; using System.Linq; using NumSharp; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace Tensorflow { @@ -447,7 +447,7 @@ namespace Tensorflow { var ret = new List(); - foreach(var (i, value) in Python.enumerate(values)) + foreach(var (i, value) in enumerate(values)) { if (value == null) { diff --git a/src/TensorFlowNET.Core/ops.name_scope.cs b/src/TensorFlowNET.Core/ops.name_scope.cs index 7096c6ad..bd98f2ca 100644 --- a/src/TensorFlowNET.Core/ops.name_scope.cs +++ b/src/TensorFlowNET.Core/ops.name_scope.cs @@ -27,7 +27,7 @@ namespace Tensorflow /// /// Returns a context manager that creates hierarchical names for operations. /// - public class NameScope : IPython + public class NameScope : IObjectLife { public string _name; public string _default_name; @@ -70,6 +70,16 @@ namespace Tensorflow { } + public void __init__() + { + + } + + public void __del__() + { + + } + /// /// __enter__() /// diff --git a/src/TensorFlowNET.Core/tf.cs b/src/TensorFlowNET.Core/tensorflow.cs similarity index 52% rename from src/TensorFlowNET.Core/tf.cs rename to src/TensorFlowNET.Core/tensorflow.cs index b10f41b0..da873722 100644 --- a/src/TensorFlowNET.Core/tf.cs +++ b/src/TensorFlowNET.Core/tensorflow.cs @@ -18,25 +18,25 @@ using Tensorflow.Eager; namespace Tensorflow { - public static partial class tf + public partial class tensorflow : IObjectLife { - public static TF_DataType @byte = TF_DataType.TF_UINT8; - public static TF_DataType @sbyte = TF_DataType.TF_INT8; - public static TF_DataType int16 = TF_DataType.TF_INT16; - public static TF_DataType int32 = TF_DataType.TF_INT32; - public static TF_DataType int64 = TF_DataType.TF_INT64; - public static TF_DataType float16 = TF_DataType.TF_HALF; - public static TF_DataType float32 = TF_DataType.TF_FLOAT; - public static TF_DataType float64 = TF_DataType.TF_DOUBLE; - public static TF_DataType @bool = TF_DataType.TF_BOOL; - public static TF_DataType chars = TF_DataType.TF_STRING; - public static TF_DataType @string = TF_DataType.TF_STRING; - - public static Context context = new Context(new ContextOptions(), new Status()); - - public static Session defaultSession; - - public static RefVariable Variable(T data, + public TF_DataType @byte = TF_DataType.TF_UINT8; + public TF_DataType @sbyte = TF_DataType.TF_INT8; + public TF_DataType int16 = TF_DataType.TF_INT16; + public TF_DataType int32 = TF_DataType.TF_INT32; + public TF_DataType int64 = TF_DataType.TF_INT64; + public TF_DataType float16 = TF_DataType.TF_HALF; + public TF_DataType float32 = TF_DataType.TF_FLOAT; + public TF_DataType float64 = TF_DataType.TF_DOUBLE; + public TF_DataType @bool = TF_DataType.TF_BOOL; + public TF_DataType chars = TF_DataType.TF_STRING; + public TF_DataType @string = TF_DataType.TF_STRING; + + public Context context = new Context(new ContextOptions(), new Status()); + + public Session defaultSession; + + public RefVariable Variable(T data, bool trainable = true, bool validate_shape = true, string name = null, @@ -49,33 +49,58 @@ namespace Tensorflow dtype: dtype); } - public static unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null) + public unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null) { return gen_array_ops.placeholder(dtype, shape, name); } - public static void enable_eager_execution() + public void enable_eager_execution() { // contex = new Context(); context.default_execution_mode = Context.EAGER_MODE; } - public static string VERSION => c_api.StringPiece(c_api.TF_Version()); + public string VERSION => c_api.StringPiece(c_api.TF_Version()); - public static Session Session() + public Session Session() { defaultSession = new Session(); return defaultSession; } - public static Session Session(Graph graph) + public Session Session(Graph graph) { return new Session(graph); } - public static Session Session(SessionOptions opts) + public Session Session(SessionOptions opts) { return new Session(null, opts); } + + public void __init__() + { + + } + + public void __enter__() + { + + } + + public void __exit__() + { + + } + + public void __del__() + { + + } + + public void Dispose() + { + + } } } diff --git a/src/TensorFlowNet.Benchmarks/TensorBenchmark.cs b/src/TensorFlowNet.Benchmarks/TensorBenchmark.cs index 3a0eeb65..d9386b99 100644 --- a/src/TensorFlowNet.Benchmarks/TensorBenchmark.cs +++ b/src/TensorFlowNet.Benchmarks/TensorBenchmark.cs @@ -2,6 +2,7 @@ using BenchmarkDotNet.Attributes; using NumSharp; using Tensorflow; +using static Tensorflow.Binding; namespace TensorFlowBenchmark { diff --git a/test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs b/test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs index 38c650a3..9b32dc63 100644 --- a/test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs +++ b/test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs @@ -6,7 +6,6 @@ open NumSharp open Tensorflow open System - let run()= let N_points = 75 // Number of points for constructing function @@ -40,6 +39,7 @@ let run()= let n_hidden_layer_1 = 25 // Hidden layer 1 let n_hidden_layer_2 = 25 // Hidden layer 2 + let tf = Binding.New() let x = tf.placeholder(tf.float64, new TensorShape(N_points,n_input)) let y = tf.placeholder(tf.float64, new TensorShape(n_output)) @@ -77,7 +77,7 @@ let run()= let init = tf.global_variables_initializer() - Tensorflow.Python.``tf_with``(tf.Session(), fun (sess:Session) -> + Tensorflow.Binding.``tf_with``(tf.Session(), fun (sess:Session) -> sess.run(init) |> ignore // Loop over epochs for epoch in [0..training_epochs] do diff --git a/test/TensorFlowNET.Examples/BasicEagerApi.cs b/test/TensorFlowNET.Examples/BasicEagerApi.cs index ab2d1f8a..ac6e6e82 100644 --- a/test/TensorFlowNET.Examples/BasicEagerApi.cs +++ b/test/TensorFlowNET.Examples/BasicEagerApi.cs @@ -1,5 +1,6 @@ using System; using Tensorflow; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs index 25ce085e..ecd9e27d 100644 --- a/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs @@ -19,7 +19,7 @@ using System; using System.Diagnostics; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs b/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs index 0098404d..a9dfbe7e 100644 --- a/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/BasicModels/LinearRegression.cs @@ -17,7 +17,7 @@ using NumSharp; using System; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs b/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs index 1b34b961..73d40d28 100644 --- a/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs +++ b/test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs @@ -20,7 +20,7 @@ using System.Diagnostics; using System.IO; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs index 70809cc7..fde1653d 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using Tensorflow; using NumSharp; -using static Tensorflow.Python; +using static Tensorflow.Binding; using System.IO; using TensorFlowNET.Examples.Utility; diff --git a/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs b/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs index eb96d275..22607c3d 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs @@ -18,7 +18,7 @@ using NumSharp; using System; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs b/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs index 8b158012..e9bcf0cb 100644 --- a/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs +++ b/test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs @@ -18,7 +18,7 @@ using System; using NumSharp; using Tensorflow; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/BasicOperations.cs b/test/TensorFlowNET.Examples/BasicOperations.cs index c7314abe..ff382009 100644 --- a/test/TensorFlowNET.Examples/BasicOperations.cs +++ b/test/TensorFlowNET.Examples/BasicOperations.cs @@ -1,7 +1,7 @@ using NumSharp; using System; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -95,7 +95,7 @@ namespace TensorFlowNET.Examples Console.WriteLine(result.ToString()); // ==> [[ 12.]] }; - // `BatchMatMul` is actually embedded into the `MatMul` operation on the tensorflow.dll side. Every time we ask + // `BatchMatMul` is actually embedded into the `MatMul` operation on the tf.dll side. Every time we ask // for a multiplication between matrices with rank > 2, the first rank - 2 dimensions are checked to be consistent // across the two matrices and a common matrix multiplication is done on the residual 2 dimensions. // diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs index 52e47e3d..28c4b093 100644 --- a/test/TensorFlowNET.Examples/HelloWorld.cs +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -1,6 +1,6 @@ using System; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/CIFAR10-CNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/CIFAR10-CNN.cs index a77a5b00..477ce85e 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/CIFAR10-CNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/CIFAR10-CNN.cs @@ -19,7 +19,6 @@ using System.Collections.Generic; using System.Text; using Tensorflow; using TensorFlowDatasets; -using static Tensorflow.Python; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs index 9c22b149..ab387fa5 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs @@ -19,7 +19,7 @@ using System; using System.Diagnostics; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -27,7 +27,7 @@ namespace TensorFlowNET.Examples /// Convolutional Neural Network classifier for Hand Written Digits /// CNN architecture with two convolutional layers, followed by two fully-connected layers at the end. /// Use Stochastic Gradient Descent (SGD) optimizer. - /// http://www.easy-tensorflow.com/tf-tutorials/convolutional-neural-nets-cnns/cnn1 + /// http://www.easy-tf.com/tf-tutorials/convolutional-neural-nets-cnns/cnn1 /// public class DigitRecognitionCNN : IExample { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs index 9125c286..a68b58ef 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs @@ -18,7 +18,7 @@ using NumSharp; using System; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -26,7 +26,7 @@ namespace TensorFlowNET.Examples /// Neural Network classifier for Hand Written Digits /// Sample Neural Network architecture with two layers implemented for classifying MNIST digits. /// Use Stochastic Gradient Descent (SGD) optimizer. - /// http://www.easy-tensorflow.com/tf-tutorials/neural-networks + /// http://www.easy-tf.com/tf-tutorials/neural-networks /// public class DigitRecognitionNN : IExample { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs index cecd85ff..76d3d63f 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs @@ -18,7 +18,7 @@ using NumSharp; using System; using Tensorflow; using Tensorflow.Hub; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs index 8eed577b..1bc9781f 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ImageBackgroundRemoval.cs @@ -2,7 +2,7 @@ using System.IO; using Tensorflow; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs b/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs index 85e0357a..0414d68d 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ImageRecognitionInception.cs @@ -6,7 +6,7 @@ using System.IO; using Console = Colorful.Console; using Tensorflow; using System.Drawing; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -89,7 +89,7 @@ namespace TensorFlowNET.Examples Directory.CreateDirectory(dir); // get model file - string url = "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip"; + string url = "https://storage.googleapis.com/download.tf.org/models/inception5h.zip"; Utility.Web.Download(url, dir, "inception5h.zip"); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs b/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs index 93fa9c2c..704067fc 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/InceptionArchGoogLeNet.cs @@ -3,7 +3,7 @@ using System; using System.IO; using System.Linq; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -93,7 +93,7 @@ namespace TensorFlowNET.Examples Directory.CreateDirectory(dir); // get model file - string url = "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz"; + string url = "https://storage.googleapis.com/download.tf.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz"; Utility.Web.Download(url, dir, $"{pbFile}.tar.gz"); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs index f5c967a7..50093f3c 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs @@ -22,7 +22,7 @@ using TensorFlowNET.Examples.Utility; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -84,7 +84,7 @@ namespace TensorFlowNET.Examples public void PrepareData() { // get model file - string url = "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz"; + string url = "http://download.tf.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz"; Web.Download(url, modelDir, "ssd_mobilenet_v1_coco.tar.gz"); Compress.ExtractTGZ(Path.Join(modelDir, "ssd_mobilenet_v1_coco.tar.gz"), "./"); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs b/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs index 92442d17..79cc548f 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/RetrainImageClassifier.cs @@ -23,7 +23,7 @@ using System.IO; using System.Linq; using Tensorflow; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { @@ -32,7 +32,7 @@ namespace TensorFlowNET.Examples /// and simply train a new classification layer on top. Transfer learning is a technique that shortcuts much of this /// by taking a piece of a model that has already been trained on a related task and reusing it in a new model. /// - /// https://www.tensorflow.org/hub/tutorials/image_retraining + /// https://www.tf.org/hub/tutorials/image_retraining /// public class RetrainImageClassifier : IExample { @@ -167,7 +167,7 @@ namespace TensorFlowNET.Examples /// weights, and then sets up all the gradients for the backward pass. /// /// The set up for the softmax and fully-connected layers is based on: - /// https://www.tensorflow.org/tutorials/mnist/beginners/index.html + /// https://www.tf.org/tutorials/mnist/beginners/index.html /// /// /// @@ -508,7 +508,7 @@ namespace TensorFlowNET.Examples { // get a set of images to teach the network about the new classes string fileName = "flower_photos.tgz"; - string url = $"http://download.tensorflow.org/example_images/{fileName}"; + string url = $"http://download.tf.org/example_images/{fileName}"; Web.Download(url, data_dir, fileName); Compress.ExtractTGZ(Path.Join(data_dir, fileName), data_dir); diff --git a/test/TensorFlowNET.Examples/Keras.cs b/test/TensorFlowNET.Examples/Keras.cs index 3bf46c00..aa17e9b2 100644 --- a/test/TensorFlowNET.Examples/Keras.cs +++ b/test/TensorFlowNET.Examples/Keras.cs @@ -4,6 +4,7 @@ using Tensorflow; using Keras.Layers; using NumSharp; using Keras; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/Program.cs b/test/TensorFlowNET.Examples/Program.cs index 0a4c6721..8679a730 100644 --- a/test/TensorFlowNET.Examples/Program.cs +++ b/test/TensorFlowNET.Examples/Program.cs @@ -22,6 +22,7 @@ using System.Linq; using System.Reflection; using Tensorflow; using Console = Colorful.Console; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs index d781bccd..3519d972 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs @@ -24,7 +24,7 @@ using Tensorflow; using Tensorflow.Sessions; using TensorFlowNET.Examples.Text; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs b/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs index db5f230f..42eab6c4 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/NER/LstmCrfNer.cs @@ -6,7 +6,7 @@ using System.Linq; using Tensorflow; using Tensorflow.Estimator; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; using static TensorFlowNET.Examples.DataHelpers; namespace TensorFlowNET.Examples.Text.NER diff --git a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs index 33f50aad..ba945606 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs @@ -5,7 +5,7 @@ using System.IO; using System.Linq; using Tensorflow; using TensorFlowNET.Examples.Utility; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples { diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs index 75308b8c..63132809 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/CharCnn.cs @@ -1,5 +1,5 @@ using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples.Text { diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs index 8087a2b2..9b28fdc0 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/VdCnn.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples.Text { @@ -32,7 +32,7 @@ namespace TensorFlowNET.Examples.Text num_filters = new int[] { 64, 64, 128, 256, 512 }; num_blocks = new int[] { 2, 2, 2, 2 }; learning_rate = 0.001f; - cnn_initializer = tf.keras.initializers.he_normal(); + cnn_initializer = tensorflow.keras.initializers.he_normal(); fc_initializer = tf.truncated_normal_initializer(stddev: 0.05f); x = tf.placeholder(tf.int32, new TensorShape(-1, document_max_len), name: "x"); diff --git a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs index 3448ac83..ef5bc9db 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/cnn_models/WordCnn.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.Examples.Text { diff --git a/test/TensorFlowNET.UnitTest/Basics/AssignTests.cs b/test/TensorFlowNET.UnitTest/Basics/AssignTests.cs index 9b2b6f3a..15d9b819 100644 --- a/test/TensorFlowNET.UnitTest/Basics/AssignTests.cs +++ b/test/TensorFlowNET.UnitTest/Basics/AssignTests.cs @@ -1,6 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.Basics { diff --git a/test/TensorFlowNET.UnitTest/Basics/NegativeTests.cs b/test/TensorFlowNET.UnitTest/Basics/NegativeTests.cs index e953eb8e..600b2731 100644 --- a/test/TensorFlowNET.UnitTest/Basics/NegativeTests.cs +++ b/test/TensorFlowNET.UnitTest/Basics/NegativeTests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.Basics { diff --git a/test/TensorFlowNET.UnitTest/ConstantTest.cs b/test/TensorFlowNET.UnitTest/ConstantTest.cs index 0fbd1883..c1d4c9e5 100644 --- a/test/TensorFlowNET.UnitTest/ConstantTest.cs +++ b/test/TensorFlowNET.UnitTest/ConstantTest.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using System.Runtime.InteropServices; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/ConsumersTest.cs b/test/TensorFlowNET.UnitTest/ConsumersTest.cs index a310fbc9..8ffc7113 100644 --- a/test/TensorFlowNET.UnitTest/ConsumersTest.cs +++ b/test/TensorFlowNET.UnitTest/ConsumersTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs index 7bcec065..c980692c 100644 --- a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs +++ b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using TensorFlowNET.Examples; +using static Tensorflow.Binding; namespace TensorFlowNET.ExamplesTests { diff --git a/test/TensorFlowNET.UnitTest/GradientTest.cs b/test/TensorFlowNET.UnitTest/GradientTest.cs index 6a073471..b52bc1cf 100644 --- a/test/TensorFlowNET.UnitTest/GradientTest.cs +++ b/test/TensorFlowNET.UnitTest/GradientTest.cs @@ -2,7 +2,7 @@ using NumSharp; using System.Linq; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/GraphTest.cs b/test/TensorFlowNET.UnitTest/GraphTest.cs index 31abd561..f5431e01 100644 --- a/test/TensorFlowNET.UnitTest/GraphTest.cs +++ b/test/TensorFlowNET.UnitTest/GraphTest.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using Tensorflow; using Buffer = Tensorflow.Buffer; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/KerasTests.cs b/test/TensorFlowNET.UnitTest/KerasTests.cs index f60b3c61..dfbe3860 100644 --- a/test/TensorFlowNET.UnitTest/KerasTests.cs +++ b/test/TensorFlowNET.UnitTest/KerasTests.cs @@ -2,6 +2,7 @@ using Keras.Layers; using NumSharp; using Microsoft.VisualStudio.TestTools.UnitTesting; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/NameScopeTest.cs b/test/TensorFlowNET.UnitTest/NameScopeTest.cs index 9a2b4346..4ff50deb 100644 --- a/test/TensorFlowNET.UnitTest/NameScopeTest.cs +++ b/test/TensorFlowNET.UnitTest/NameScopeTest.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs index d1db80f1..4c6ae3d0 100644 --- a/test/TensorFlowNET.UnitTest/OperationsTest.cs +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -5,6 +5,7 @@ using System.Linq; using NumSharp; using Tensorflow; using Buffer = Tensorflow.Buffer; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs index c8ca0dab..14b16c23 100644 --- a/test/TensorFlowNET.UnitTest/PlaceholderTest.cs +++ b/test/TensorFlowNET.UnitTest/PlaceholderTest.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs index dff62549..6fd0d7c3 100644 --- a/test/TensorFlowNET.UnitTest/PythonBaseTests.cs +++ b/test/TensorFlowNET.UnitTest/PythonBaseTests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { @@ -25,6 +25,31 @@ namespace TensorFlowNET.UnitTest Assert.IsTrue(b); } + [TestMethod] + public void isinstance_test() + { + var s1 = "hi"; + var s2 = "hello"; + + var t1 = (s1, s2); + var t2 = (s1, s2, s1); + var t3 = (s2, s1); + + var true1 = isinstance(s1, typeof(string)); + var false1 = isinstance(t1, typeof(string)); + var true2 = isinstance(t1, t3.GetType()); + var false2 = isinstance(t1, t2.GetType()); + var true3 = isinstance(t1, (t2.GetType(), t1.GetType(), typeof(string))); + var false3 = isinstance(t3, (t2.GetType(), typeof(string))); + + Assert.IsTrue(true1); + Assert.IsTrue(true2); + Assert.IsTrue(true3); + Assert.IsFalse(false1); + Assert.IsFalse(false2); + Assert.IsFalse(false3); + } + [TestMethod] public void hasattr_getattr() { diff --git a/test/TensorFlowNET.UnitTest/PythonTest.cs b/test/TensorFlowNET.UnitTest/PythonTest.cs index 12dbd0c3..701b4b4b 100644 --- a/test/TensorFlowNET.UnitTest/PythonTest.cs +++ b/test/TensorFlowNET.UnitTest/PythonTest.cs @@ -5,8 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; using NumSharp; using Tensorflow; -using Tensorflow.Util; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { @@ -239,7 +238,7 @@ namespace TensorFlowNET.UnitTest return s.as_default(); } - private IPython _constrain_devices_and_set_default(Session sess, bool useGpu, bool forceGpu) + private IObjectLife _constrain_devices_and_set_default(Session sess, bool useGpu, bool forceGpu) { //def _constrain_devices_and_set_default(self, sess, use_gpu, force_gpu): //"""Set the session and its graph to global default and constrain devices.""" diff --git a/test/TensorFlowNET.UnitTest/SessionTest.cs b/test/TensorFlowNET.UnitTest/SessionTest.cs index 51620b19..9c8485ec 100644 --- a/test/TensorFlowNET.UnitTest/SessionTest.cs +++ b/test/TensorFlowNET.UnitTest/SessionTest.cs @@ -3,7 +3,7 @@ using NumSharp; using System; using System.Collections.Generic; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/TensorTest.cs b/test/TensorFlowNET.UnitTest/TensorTest.cs index 6666443c..07da9dca 100644 --- a/test/TensorFlowNET.UnitTest/TensorTest.cs +++ b/test/TensorFlowNET.UnitTest/TensorTest.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs index 625ca874..ce68e2b5 100644 --- a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs +++ b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs @@ -1,7 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/VariableTest.cs b/test/TensorFlowNET.UnitTest/VariableTest.cs index fc4078c1..4c5ddd7a 100644 --- a/test/TensorFlowNET.UnitTest/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/VariableTest.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { @@ -28,7 +28,7 @@ namespace TensorFlowNET.UnitTest } /// - /// https://www.tensorflow.org/api_docs/python/tf/variable_scope + /// https://www.tf.org/api_docs/python/tf/variable_scope /// how to create a new variable /// [TestMethod] diff --git a/test/TensorFlowNET.UnitTest/VersionTest.cs b/test/TensorFlowNET.UnitTest/VersionTest.cs index f687efa6..cabcdd25 100644 --- a/test/TensorFlowNET.UnitTest/VersionTest.cs +++ b/test/TensorFlowNET.UnitTest/VersionTest.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest { diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs index 94686049..eea640ac 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; 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 31109f0a..4e82a2b6 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs @@ -1,7 +1,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; 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 68ee14e4..ecd69977 100644 --- a/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs +++ b/test/TensorFlowNET.UnitTest/gradients_test/GradientsTest.cs @@ -4,7 +4,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.gradients_test { @@ -129,6 +129,19 @@ namespace TensorFlowNET.UnitTest.gradients_test } } + [TestMethod] + public void testStopGradientFunction() + { + var ap = tf.constant(1f); + var b = tf.tanh(ap) + gen_array_ops.stop_gradient(ap); + var g = tf.gradients(b, ap); + using (var sess = tf.Session()) + { + var result = sess.run(g); + var actual = result[0].GetData()[0]; + self.assertEquals(0.41997434127f, actual); + } + } [Ignore("TODO")] [TestMethod] public void testUnusedOutput() diff --git a/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs b/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs index e7a3592c..53334349 100644 --- a/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs +++ b/test/TensorFlowNET.UnitTest/nest_test/NestTest.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq; using NumSharp; using Tensorflow; using Tensorflow.Util; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.nest_test { diff --git a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs index 3f52d887..1fd7d3aa 100644 --- a/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs +++ b/test/TensorFlowNET.UnitTest/nn_test/ZeroFractionTest.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.nn_test { diff --git a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs index 8c8a89dd..f39a71b2 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Eager; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.ops_test { diff --git a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs index dcaeaf11..cdbd5f14 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Operations; -using static Tensorflow.Python; +using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.ops_test {