diff --git a/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs b/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs new file mode 100644 index 00000000..99887a49 --- /dev/null +++ b/src/TensorFlowNET.Core/Gradients/AggregationMethod.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public class AggregationMethod + { + public static int ADD_N = 0; + public static int DEFAULT = ADD_N; + // The following are experimental and may not be supported in future releases. + public static int EXPERIMENTAL_TREE = 1; + public static int EXPERIMENTAL_ACCUMULATE_N = 2; + } +} diff --git a/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs new file mode 100644 index 00000000..80cc563a --- /dev/null +++ b/src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public class gradients_impl + { + public static void gradients(object ys, + object xs, + List grad_ys = null, + string name = "gradients", + bool colocate_gradients_with_ops = false, + bool gate_gradients = false, + int? aggregation_method = null) + { + _GradientsHelper(ys, xs, grad_ys, name, colocate_gradients_with_ops, gate_gradients); + } + + public static void _GradientsHelper(object ys, + object xs, + List grad_ys = null, + string name = "gradients", + bool colocate_gradients_with_ops = false, + bool gate_gradients = false, + Graph src_graph = null) + { + if (src_graph == null) + src_graph = ops.get_default_graph(); + } + } +} diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index 9b8c1727..e5f868b7 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -222,7 +222,7 @@ namespace Tensorflow } } - return ""; + return $"{name} {dtype} {rank} {string.Join(",", shape)}"; } public void Dispose() diff --git a/src/TensorFlowNET.Core/Train/Optimizer.cs b/src/TensorFlowNET.Core/Train/Optimizer.cs index 6b054d99..5d83a15e 100644 --- a/src/TensorFlowNET.Core/Train/Optimizer.cs +++ b/src/TensorFlowNET.Core/Train/Optimizer.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using distribute_lib = Tensorflow.Distribute; @@ -48,8 +49,10 @@ namespace Tensorflow /// public List> compute_gradients(Tensor loss, List var_list = null, + int? aggregation_method = null, GateGradientType gate_gradients = GateGradientType.GATE_OP, - bool colocate_gradients_with_ops = false) + bool colocate_gradients_with_ops = false, + List grad_loss = null) { int num_towers = 1; if(distribute_lib.get_loss_reduction() == VariableAggregationType.MEAN) @@ -65,10 +68,13 @@ namespace Tensorflow break; } - foreach(var v in var_list) - { + var processors = var_list.Select(v => optimizer._get_processor(v)); + var var_refs = processors.Select(x => x.target()).ToList(); - } + gradients_impl.gradients(loss, var_refs, grad_ys: grad_loss, + gate_gradients: (gate_gradients == GateGradientType.GATE_OP), + aggregation_method: aggregation_method, + colocate_gradients_with_ops: colocate_gradients_with_ops); return null; } diff --git a/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs b/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs new file mode 100644 index 00000000..90f5fb52 --- /dev/null +++ b/src/TensorFlowNET.Core/Train/_OptimizableVariable.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public interface _OptimizableVariable + { + Tensor target(); + void update_op(Graph g); + } +} diff --git a/src/TensorFlowNET.Core/Train/optimizer.py.cs b/src/TensorFlowNET.Core/Train/optimizer.py.cs new file mode 100644 index 00000000..0a98eaf8 --- /dev/null +++ b/src/TensorFlowNET.Core/Train/optimizer.py.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow +{ + public class optimizer + { + public static _OptimizableVariable _get_processor(RefVariable v) + { + return new _RefVariableProcessor(v); + } + } + + public class _RefVariableProcessor : _OptimizableVariable + { + private RefVariable _v; + + public _RefVariableProcessor(RefVariable v) + { + _v = v; + } + + public Tensor target() + { + return _v._ref(); + } + + public void update_op(Graph g) + { + + } + } +} diff --git a/src/TensorFlowNET.Core/Variables/RefVariable.cs b/src/TensorFlowNET.Core/Variables/RefVariable.cs index 5b2171cf..c073b311 100644 --- a/src/TensorFlowNET.Core/Variables/RefVariable.cs +++ b/src/TensorFlowNET.Core/Variables/RefVariable.cs @@ -78,6 +78,11 @@ namespace Tensorflow ops.add_to_collections(collections, this); } + public Tensor _ref() + { + return _variable; + } + public static implicit operator _VariableScopeStore(RefVariable variable) { return null;