From 5808e34ff7a98db815258b0f8c4d4e47880c0937 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 9 Nov 2019 12:30:12 -0600 Subject: [PATCH] fixed Repeated Abs name #442 --- src/TensorFlowNET.Core/APIs/tf.math.cs | 5 +++- .../Operations/Operation.cs | 5 ++++ .../Operations/gen_math_ops.cs | 13 +++-------- src/TensorFlowNET.Core/Operations/math_ops.cs | 23 ++++++++++++++++--- .../Tensors/Tensor.Operators.cs | 8 +++---- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index cba05d0e..e3b9e257 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -441,7 +441,7 @@ namespace Tensorflow return math_ops.reduce_sum(input, keepdims: keepdims, name: name); } - public Tensor reduce_sum(Tensor input, int[] axis, int? reduction_indices = null, + public Tensor reduce_sum(Tensor input, TensorShape axis, int? reduction_indices = null, bool keepdims = false, string name = null) => math_ops.reduce_sum(input, axis, keepdims: keepdims, name: name); @@ -456,6 +456,9 @@ namespace Tensorflow 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 Tensor reduce_max(Tensor input_tensor, int axis, bool keepdims = false, string name = null) + => math_ops.reduce_max(input_tensor, axis, keepdims, name); + 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); diff --git a/src/TensorFlowNET.Core/Operations/Operation.cs b/src/TensorFlowNET.Core/Operations/Operation.cs index 359dc870..0ee72c39 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.cs @@ -186,6 +186,11 @@ namespace Tensorflow if (op_def == null) op_def = g.GetOpDef(node_def.Op); + if (node_def.Name.Equals("learn_rate/cond/pred_id")) + { + + } + var grouped_inputs = _reconstruct_sequence_inputs(op_def, inputs, node_def.Attr); _handle = ops._create_c_op(g, node_def, grouped_inputs, control_input_ops.ToArray()); _is_stateful = op_def.IsStateful; diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index 7e54349f..e4a8d175 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -629,9 +629,9 @@ namespace Tensorflow public static Tensor _abs(Tensor x, string name = null) { - var _op = _op_def_lib._apply_op_helper("Abs", name, new { x }); + var _op = _op_def_lib._apply_op_helper("Abs", name, args: new { x }); - return _op.outputs[0]; + return _op.output; } public static Tensor _any(Tx input, Ty axis, bool keep_dims = false, string name = null) @@ -662,14 +662,7 @@ namespace Tensorflow return _op.outputs[0]; } - public static Tensor _sum(Tensor input, Tensor axis = null, bool keep_dims = false, string name = null) - { - var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims }); - - return _op.outputs[0]; - } - - public static Tensor _sum(Tensor input, int axis, bool keep_dims = false, string name = null) + public static Tensor _sum(Tx input, Ty axis = default, bool keep_dims = false, string name = null) { var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims }); diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index f158ffb1..fd73dd0f 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -31,6 +31,7 @@ namespace Tensorflow { return tf_with(ops.name_scope(name, "Abs", new { x }), scope => { + name = scope; x = ops.convert_to_tensor(x, name: "x"); if (x.dtype.is_complex()) throw new NotImplementedException("math_ops.abs for dtype.is_complex"); @@ -379,6 +380,13 @@ namespace Tensorflow return _may_reduce_to_scalar(keepdims, axis, max); } + public static Tensor reduce_max(Tensor input_tensor, int axis, bool keepdims = false, string name = null) + { + var r = _ReductionDims(input_tensor, axis); + var max = gen_math_ops._max(input_tensor, r, keepdims, name); + return _may_reduce_to_scalar(keepdims, axis, max); + } + public static Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) { var r = _ReductionDims(input_tensor, axis); @@ -434,15 +442,14 @@ namespace Tensorflow public static Tensor reduce_sum(Tensor input_tensor, int[] axis, bool keepdims = false, string name = null) { - var r = _ReductionDims(input_tensor, axis); - var m = gen_math_ops._sum(input_tensor, r, keep_dims: keepdims, name: name); + var m = gen_math_ops._sum(input_tensor, axis, keep_dims: keepdims, name: name); return _may_reduce_to_scalar(keepdims, axis, m); } public static Tensor reduce_sum(Tensor input_tensor, int axis, bool keepdims = false, string name = null) { var m = gen_math_ops._sum(input_tensor, axis, keep_dims: keepdims, name: name); - return _may_reduce_to_scalar(keepdims, new int[] { axis }, m); + return _may_reduce_to_scalar(keepdims, axis, m); } private static Tensor _may_reduce_to_scalar(bool keepdims, Tensor axis, Tensor output) @@ -464,6 +471,11 @@ namespace Tensorflow return output; } + private static Tensor _may_reduce_to_scalar(bool keepdims, int axis, Tensor output) + { + return output; + } + private static Tensor _ReductionDims(Tensor x, Tensor axis) { if (axis != null) @@ -477,6 +489,11 @@ namespace Tensorflow } } + private static int _ReductionDims(Tensor x, int axis) + { + return axis; + } + private static Tensor _ReductionDims(Tensor x, int[] axis) { if (axis != null) diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs index 2a901e07..b205674d 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs @@ -328,18 +328,16 @@ namespace Tensorflow switch (name.ToLowerInvariant()) { case "add": - result = gen_math_ops.add(x1, y1, name: scope); + result = math_ops.add(x1, y1, name: scope); break; case "div": - result = _intTfDataTypes.Contains(x1.dtype) || _intTfDataTypes.Contains(y1.dtype) - ? gen_math_ops.floor_div(x1, y1, name: scope) - : gen_math_ops.real_div(x1, y1, name: scope); + result = math_ops.div(x1, y1, name: scope); break; case "floordiv": result = gen_math_ops.floor_div(x1, y1, name: scope); break; case "truediv": - result = gen_math_ops.real_div(x1, y1, name: scope); + result = math_ops.truediv(x1, y1, name: scope); break; case "mul": result = gen_math_ops.mul(x1, y1, name: scope);