From 54427278aa6cb8d93c4a3757db8f83c780bab854 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Fri, 15 Mar 2019 21:16:32 -0500 Subject: [PATCH] change CondContext to IControlFlowContext in Operation and Graph. --- .../Gradients/control_flow_grad.py.cs | 3 ++- .../Operations/Operation.Control.cs | 6 +++--- src/TensorFlowNET.Core/Operations/Operation.cs | 6 +++++- .../Operations/control_flow_util.py.cs | 2 +- src/TensorFlowNET.Core/TensorFlowNET.Core.csproj | 11 +++++------ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs b/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs index 5e27f38c..afc87d45 100644 --- a/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs +++ b/src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Tensorflow.Operations; namespace Tensorflow.Gradients { @@ -13,7 +14,7 @@ namespace Tensorflow.Gradients var input_op = op.inputs[0].op; var graph = ops.get_default_graph(); var op_ctxt = control_flow_util.GetOutputContext(input_op); - var pred = op_ctxt.pred; + var pred = (op_ctxt as CondContext).pred; var results = control_flow_ops._SwitchRefOrTensor(grad, pred, name: "cond_grad"); return new Tensor[] { results.Item1, results.Item2 }; diff --git a/src/TensorFlowNET.Core/Operations/Operation.Control.cs b/src/TensorFlowNET.Core/Operations/Operation.Control.cs index 654e1b81..fec3c89d 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Control.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Control.cs @@ -7,7 +7,7 @@ namespace Tensorflow { public partial class Operation { - private CondContext _control_flow_context; + private IControlFlowContext _control_flow_context; /// /// Add this op to its control flow context. @@ -28,12 +28,12 @@ namespace Tensorflow } } - public void _set_control_flow_context(CondContext ctx) + public void _set_control_flow_context(IControlFlowContext ctx) { _control_flow_context = ctx; } - public CondContext _get_control_flow_context() + public IControlFlowContext _get_control_flow_context() { return _control_flow_context; } diff --git a/src/TensorFlowNET.Core/Operations/Operation.cs b/src/TensorFlowNET.Core/Operations/Operation.cs index 9df75321..378df9c5 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.cs @@ -102,8 +102,12 @@ namespace Tensorflow } } + // Dict mapping op name to file and line information for op colocation + // context managers. + _control_flow_context = graph._get_control_flow_context(); + // This will be set by self.inputs. - if(op_def == null) + if (op_def == null) op_def = g.GetOpDef(node_def.Op); var grouped_inputs = _reconstruct_sequence_inputs(op_def, inputs, node_def.Attr); diff --git a/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs b/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs index 146b681c..0de8bdeb 100644 --- a/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs +++ b/src/TensorFlowNET.Core/Operations/control_flow_util.py.cs @@ -27,7 +27,7 @@ namespace Tensorflow return op.type == "Switch" || op.type == "RefSwitch"; } - public static CondContext GetOutputContext(Operation op) + public static IControlFlowContext GetOutputContext(Operation op) { var ctxt = op._get_control_flow_context(); diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index 23d5b0a6..b9b980f9 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -4,7 +4,7 @@ netstandard2.0 TensorFlow.NET Tensorflow - 0.4.2 + 0.5.0 Haiping Chen SciSharp STACK true @@ -13,14 +13,13 @@ git https://github.com/SciSharp https://avatars3.githubusercontent.com/u/44989469?s=200&v=4 - TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET + TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET, C# Google's TensorFlow binding in .NET Standard. Docs: https://tensorflownet.readthedocs.io - 0.4.2.0 - Added ConfigProto to control CPU and GPU resource. -Fixed import name scope issue. + 0.5.0.0 + Add a lot of APIs to build neural networks model 7.2 - 0.4.2.0 + 0.5.0.0