From c62d9ee5202e010a1f76b62aadf9c0f2e0441318 Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Mon, 1 Jul 2019 15:21:06 +0930 Subject: [PATCH] AddControlInput and UpdateEdge works.. --- .../Graphs/python_api.graph.cs | 20 ---- .../Operations/Operation.Control.cs | 100 +++++++++--------- .../Operations/array_ops.py.cs | 2 + .../Operations/nn_impl.py.cs | 2 - 4 files changed, 52 insertions(+), 72 deletions(-) delete mode 100644 src/TensorFlowNET.Core/Graphs/python_api.graph.cs diff --git a/src/TensorFlowNET.Core/Graphs/python_api.graph.cs b/src/TensorFlowNET.Core/Graphs/python_api.graph.cs deleted file mode 100644 index b266580c..00000000 --- a/src/TensorFlowNET.Core/Graphs/python_api.graph.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Graphs -{ - /// - /// Lots of other functions required for Operation control flow like AddControlInput, UpdateEdge, RemoveAllControlInputs etc are not exposed via C_API and there is a C implementation of it. - /// https://github.com/tensorflow/tensorflow/blob/r1.14/tensorflow/c/python_api.h - /// https://github.com/tensorflow/tensorflow/blob/r1.14/tensorflow/c/python_api.cc - /// - /// - public class python_api - { - public static void UpdateEdge(Graph graph, TF_Output new_src, TF_Input dst, Status status) - { - - } - } -} diff --git a/src/TensorFlowNET.Core/Operations/Operation.Control.cs b/src/TensorFlowNET.Core/Operations/Operation.Control.cs index 9b3aefe2..4f1c156f 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Control.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Control.cs @@ -1,52 +1,52 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Tensorflow.Operations; - -namespace Tensorflow -{ - public partial class Operation - { +using System; +using System.Collections.Generic; +using System.Text; +using Tensorflow.Operations; + +namespace Tensorflow +{ + public partial class Operation + { private ControlFlowContext _control_flow_context; - /// - /// Add this op to its control flow context. - /// - /// This may add new ops and change this op's inputs. self.inputs must be - /// available before calling this method. - /// - public void _control_flow_post_processing() - { - foreach(var input_tensor in inputs) - { - //TODO: implement below code dependency - //control_flow_util.CheckInputFromValidContext(this, input_tensor.op); - } - - if (_control_flow_context != null) - _control_flow_context.AddOp(this); - } - - public void _add_control_input(Operation op) - { - //c_api.TF_AddControlInput(_operDesc, op); - c_api.AddControlInput(graph, _handle, op); - } - - public void _add_control_inputs(Operation[] ops) - { - foreach (var op in ops) - _add_control_input(op); - } - - public void _set_control_flow_context(ControlFlowContext ctx) - { - _control_flow_context = ctx; - } - - public ControlFlowContext _get_control_flow_context() - { - return _control_flow_context; - } - } -} + /// + /// Add this op to its control flow context. + /// + /// This may add new ops and change this op's inputs. self.inputs must be + /// available before calling this method. + /// + public void _control_flow_post_processing() + { + foreach(var input_tensor in inputs) + { + //TODO: implement below code dependency + //control_flow_util.CheckInputFromValidContext(this, input_tensor.op); + } + + if (_control_flow_context != null) + _control_flow_context.AddOp(this); + } + + public void _add_control_input(Operation op) + { + //c_api.TF_AddControlInput(_operDesc, op); + c_api.AddControlInput(graph, _handle, op); + } + + public void _add_control_inputs(Operation[] ops) + { + foreach (var op in ops) + _add_control_input(op); + } + + public void _set_control_flow_context(ControlFlowContext ctx) + { + _control_flow_context = ctx; + } + + public ControlFlowContext _get_control_flow_context() + { + return _control_flow_context; + } + } +} diff --git a/src/TensorFlowNET.Core/Operations/array_ops.py.cs b/src/TensorFlowNET.Core/Operations/array_ops.py.cs index c997f179..262752b2 100644 --- a/src/TensorFlowNET.Core/Operations/array_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/array_ops.py.cs @@ -30,6 +30,8 @@ namespace Tensorflow return _constant_if_small(0.0F, shape, dtype, name); case TF_DataType.TF_INT32: return _constant_if_small(0, shape, dtype, name); + case TF_DataType.TF_INT8: + return _constant_if_small(0, shape, dtype, name); default: throw new TypeError("can't find type for zeros"); } diff --git a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs index ef20d20e..8a75c506 100644 --- a/src/TensorFlowNET.Core/Operations/nn_impl.py.cs +++ b/src/TensorFlowNET.Core/Operations/nn_impl.py.cs @@ -129,10 +129,8 @@ namespace Tensorflow { return with(ops.name_scope(name, "zero_fraction", new { value }), scope => { - value = ops.convert_to_tensor(value, name: "value"); Tensor size = array_ops.size(value, out_type: dtypes.int64); - Func fu_true = () => math_ops.cast(_count_nonzero(value, dtype: dtypes.int32)); Tensor zero_fraction_float32 = null; size = gen_math_ops.less_equal(size, dtypes.int32.max());