| @@ -31,7 +31,7 @@ namespace Tensorflow | |||||
| public Optimizer AdamOptimizer(float learning_rate, string name = "Adam") | public Optimizer AdamOptimizer(float learning_rate, string name = "Adam") | ||||
| => new AdamOptimizer(learning_rate, name: name); | => new AdamOptimizer(learning_rate, name: name); | ||||
| public object ExponentialMovingAverage(float decay) | |||||
| public ExponentialMovingAverage ExponentialMovingAverage(float decay) | |||||
| => new ExponentialMovingAverage(decay); | => new ExponentialMovingAverage(decay); | ||||
| public 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); | ||||
| @@ -1,6 +1,8 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | |||||
| using System.Text; | using System.Text; | ||||
| using static Tensorflow.Binding; | |||||
| namespace Tensorflow.Train | namespace Tensorflow.Train | ||||
| { | { | ||||
| @@ -11,6 +13,7 @@ namespace Tensorflow.Train | |||||
| bool _zero_debias; | bool _zero_debias; | ||||
| string _name; | string _name; | ||||
| public string name => _name; | public string name => _name; | ||||
| List<VariableV1> _averages; | |||||
| public ExponentialMovingAverage(float decay, int? num_updates = null, bool zero_debias = false, | public ExponentialMovingAverage(float decay, int? num_updates = null, bool zero_debias = false, | ||||
| string name = "ExponentialMovingAverage") | string name = "ExponentialMovingAverage") | ||||
| @@ -19,6 +22,7 @@ namespace Tensorflow.Train | |||||
| _num_updates = num_updates; | _num_updates = num_updates; | ||||
| _zero_debias = zero_debias; | _zero_debias = zero_debias; | ||||
| _name = name; | _name = name; | ||||
| _averages = new List<VariableV1>(); | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -26,11 +30,23 @@ namespace Tensorflow.Train | |||||
| /// </summary> | /// </summary> | ||||
| /// <param name="var_list"></param> | /// <param name="var_list"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public Operation apply(VariableV1[] var_list = null) | |||||
| public Operation apply(RefVariable[] var_list = null) | |||||
| { | { | ||||
| throw new NotImplementedException(""); | |||||
| } | |||||
| if (var_list == null) | |||||
| var_list = variables.trainable_variables() as RefVariable[]; | |||||
| foreach(var var in var_list) | |||||
| { | |||||
| if (!_averages.Contains(var)) | |||||
| { | |||||
| ops.init_scope(); | |||||
| var slot = new SlotCreator(); | |||||
| var.initialized_value(); | |||||
| // var avg = slot.create_zeros_slot | |||||
| } | |||||
| } | |||||
| throw new NotImplementedException(""); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -308,5 +308,28 @@ namespace Tensorflow | |||||
| { | { | ||||
| throw new NotImplementedException(); | throw new NotImplementedException(); | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Returns the value of this variable, read in the current context. | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| private ITensorOrOperation read_value() | |||||
| { | |||||
| return array_ops.identity(_variable, name: "read"); | |||||
| } | |||||
| public Tensor is_variable_initialized(RefVariable variable) | |||||
| { | |||||
| return state_ops.is_variable_initialized(variable); | |||||
| } | |||||
| public Tensor initialized_value() | |||||
| { | |||||
| ops.init_scope(); | |||||
| throw new NotImplementedException(""); | |||||
| /*return control_flow_ops.cond(is_variable_initialized(this), | |||||
| read_value, | |||||
| () => initial_value);*/ | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -14,6 +14,7 @@ | |||||
| limitations under the License. | limitations under the License. | ||||
| ******************************************************************************/ | ******************************************************************************/ | ||||
| using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using Tensorflow.Eager; | using Tensorflow.Eager; | ||||
| @@ -145,5 +146,10 @@ namespace Tensorflow | |||||
| var _op = _op_def_lib._apply_op_helper("ScatterAdd", name: name, args: new { @ref, indices, updates, use_locking }); | var _op = _op_def_lib._apply_op_helper("ScatterAdd", name: name, args: new { @ref, indices, updates, use_locking }); | ||||
| return _op.outputs[0]; | return _op.outputs[0]; | ||||
| } | } | ||||
| public static Tensor is_variable_initialized(RefVariable @ref, string name = null) | |||||
| { | |||||
| throw new NotImplementedException(""); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -106,5 +106,13 @@ namespace Tensorflow | |||||
| throw new NotImplementedException("scatter_add"); | throw new NotImplementedException("scatter_add"); | ||||
| } | } | ||||
| public static Tensor is_variable_initialized(RefVariable @ref, string name = null) | |||||
| { | |||||
| if (@ref.dtype.is_ref_dtype()) | |||||
| return gen_state_ops.is_variable_initialized(@ref: @ref, name: name); | |||||
| throw new NotImplementedException(""); | |||||
| //return @ref.is_initialized(name: name); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -91,7 +91,12 @@ namespace TensorFlowNET.Examples.ImageProcessing.YOLO | |||||
| tf_with(tf.name_scope("define_loss"), scope => | tf_with(tf.name_scope("define_loss"), scope => | ||||
| { | { | ||||
| model = new YOLOv3(cfg, input_data, trainable); | |||||
| // model = new YOLOv3(cfg, input_data, trainable); | |||||
| }); | |||||
| tf_with(tf.name_scope("define_weight_decay"), scope => | |||||
| { | |||||
| var moving_ave = tf.train.ExponentialMovingAverage(moving_ave_decay).apply((RefVariable[])tf.trainable_variables()); | |||||
| }); | }); | ||||
| return graph; | return graph; | ||||
| @@ -8,6 +8,9 @@ using static Tensorflow.Binding; | |||||
| namespace TensorFlowNET.UnitTest | namespace TensorFlowNET.UnitTest | ||||
| { | { | ||||
| /// <summary> | |||||
| /// Find more examples in https://www.programcreek.com/python/example/90444/tensorflow.read_file | |||||
| /// </summary> | |||||
| [TestClass] | [TestClass] | ||||
| public class ImageTest | public class ImageTest | ||||
| { | { | ||||
| @@ -69,9 +69,7 @@ namespace TensorFlowNET.UnitTest | |||||
| Assert.AreEqual("scope1", g._name_stack); | Assert.AreEqual("scope1", g._name_stack); | ||||
| var const3 = tf.constant(2.0); | var const3 = tf.constant(2.0); | ||||
| Assert.AreEqual("scope1/Const_1:0", const3.name); | Assert.AreEqual("scope1/Const_1:0", const3.name); | ||||
| } | |||||
| ; | |||||
| }; | |||||
| g.Dispose(); | g.Dispose(); | ||||