| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 468cb8e commit a8a0731
26 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ limitations under the License. | |||
| 15 | 15 | ******************************************************************************/ | |
| 16 | 16 | ||
| 17 | 17 | using System; | |
| 18 | + using System.Collections.Generic; | ||
| 18 | 19 | using Tensorflow.Eager; | |
| 19 | 20 | using static Tensorflow.Binding; | |
| 20 | 21 | ||
@@ -26,5 +27,29 @@ public void disable_eager_execution() | |||
| 26 | 27 | { | |
| 27 | 28 | tf.context.default_execution_mode = Context.GRAPH_MODE; | |
| 28 | 29 | } | |
| 30 | + | ||
| 31 | + public IVariableV1 get_variable(string name, | ||
| 32 | + TensorShape shape = null, | ||
| 33 | + TF_DataType dtype = TF_DataType.DtInvalid, | ||
| 34 | + object initializer = null, // IInitializer or Tensor | ||
| 35 | + bool? trainable = null, | ||
| 36 | + List<string> collections = null, | ||
| 37 | + bool? use_resource = null, | ||
| 38 | + bool validate_shape = true, | ||
| 39 | + VariableSynchronization synchronization = VariableSynchronization.Auto, | ||
| 40 | + VariableAggregation aggregation = VariableAggregation.None) | ||
| 41 | + { | ||
| 42 | + var scope = Tensorflow.variable_scope.get_variable_scope(); | ||
| 43 | + var store = Tensorflow.variable_scope._get_default_variable_store(); | ||
| 44 | + return scope.get_variable(store, | ||
| 45 | + name, | ||
| 46 | + shape: shape, | ||
| 47 | + dtype: dtype, | ||
| 48 | + use_resource: use_resource, | ||
| 49 | + validate_shape: validate_shape, | ||
| 50 | + initializer: initializer, | ||
| 51 | + trainable: trainable, | ||
| 52 | + collections: collections); | ||
| 53 | + } | ||
| 29 | 54 | } | |
| 30 | 55 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,13 +27,13 @@ public partial class tensorflow | |||
| 27 | 27 | ||
| 28 | 28 | public class nn_internal | |
| 29 | 29 | { | |
| 30 | - public Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true, | ||
| 30 | + public Tensor conv2d(Tensor input, IVariableV1 filter, int[] strides, string padding, bool use_cudnn_on_gpu = true, | ||
| 31 | 31 | string data_format= "NHWC", int[] dilations= null, string name = null) | |
| 32 | 32 | { | |
| 33 | 33 | var parameters = new Conv2dParams | |
| 34 | 34 | { | |
| 35 | 35 | Input = input, | |
| 36 | - Filter = filter, | ||
| 36 | + Filter = filter.AsTensor(), | ||
| 37 | 37 | Strides = strides, | |
| 38 | 38 | Padding = padding, | |
| 39 | 39 | UseCudnnOnGpu = use_cudnn_on_gpu, | |
@@ -98,7 +98,7 @@ public Tensor elu(Tensor features, string name = null) | |||
| 98 | 98 | name: name, | |
| 99 | 99 | keep_dims: keep_dims); | |
| 100 | 100 | ||
| 101 | - public Tensor embedding_lookup(RefVariable @params, | ||
| 101 | + public Tensor embedding_lookup(IVariableV1 @params, | ||
| 102 | 102 | Tensor ids, | |
| 103 | 103 | string partition_strategy = "mod", | |
| 104 | 104 | string name = null) => embedding_ops._embedding_lookup_and_transform(@params, | |
@@ -150,12 +150,12 @@ public Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = | |||
| 150 | 150 | public Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = null) | |
| 151 | 151 | => gen_nn_ops.top_kv2(input, k: k, sorted: sorted, name: name); | |
| 152 | 152 | ||
| 153 | - public Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null) | ||
| 153 | + public Tensor bias_add(Tensor value, IVariableV1 bias, string data_format = null, string name = null) | ||
| 154 | 154 | { | |
| 155 | 155 | return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope => | |
| 156 | 156 | { | |
| 157 | 157 | name = scope; | |
| 158 | - return gen_nn_ops.bias_add(value, bias, data_format: data_format, name: name); | ||
| 158 | + return gen_nn_ops.bias_add(value, bias.AsTensor(), data_format: data_format, name: name); | ||
| 159 | 159 | }); | |
| 160 | 160 | } | |
| 161 | 161 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ namespace Tensorflow | |||
| 18 | 18 | { | |
| 19 | 19 | public partial class tensorflow | |
| 20 | 20 | { | |
| 21 | - public Tensor assign_add<T>(IVariableV1 @ref, T value, | ||
| 21 | + public ITensorOrOperation assign_add<T>(IVariableV1 @ref, T value, | ||
| 22 | 22 | bool use_locking = false, string name = null) | |
| 23 | 23 | => state_ops.assign_add(@ref, value, use_locking: use_locking, name: name); | |
| 24 | 24 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,10 +26,10 @@ public partial class tensorflow | |||
| 26 | 26 | ||
| 27 | 27 | public class train_internal | |
| 28 | 28 | { | |
| 29 | - public RefVariable create_global_step(Graph graph) | ||
| 29 | + public IVariableV1 create_global_step(Graph graph) | ||
| 30 | 30 | => TrainingUtil.create_global_step(graph); | |
| 31 | 31 | ||
| 32 | - public RefVariable get_global_step(Graph graph) | ||
| 32 | + public IVariableV1 get_global_step(Graph graph) | ||
| 33 | 33 | => TrainingUtil.get_global_step(graph); | |
| 34 | 34 | ||
| 35 | 35 | public Optimizer GradientDescentOptimizer(float learning_rate) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,30 +50,6 @@ public Operation global_variables_initializer() | |||
| 50 | 50 | public IVariableV1[] trainable_variables(string scope = null) | |
| 51 | 51 | => (variables.trainable_variables() as List<IVariableV1>).ToArray(); | |
| 52 | 52 | ||
| 53 | - public RefVariable get_variable(string name, | ||
| 54 | - TensorShape shape = null, | ||
| 55 | - TF_DataType dtype = TF_DataType.DtInvalid, | ||
| 56 | - object initializer = null, // IInitializer or Tensor | ||
| 57 | - bool? trainable = null, | ||
| 58 | - List<string> collections = null, | ||
| 59 | - bool? use_resource = null, | ||
| 60 | - bool validate_shape = true, | ||
| 61 | - VariableSynchronization synchronization = VariableSynchronization.Auto, | ||
| 62 | - VariableAggregation aggregation = VariableAggregation.None) | ||
| 63 | - { | ||
| 64 | - var scope = Tensorflow.variable_scope.get_variable_scope(); | ||
| 65 | - var store = Tensorflow.variable_scope._get_default_variable_store(); | ||
| 66 | - return scope.get_variable(store, | ||
| 67 | - name, | ||
| 68 | - shape: shape, | ||
| 69 | - dtype: dtype, | ||
| 70 | - use_resource: use_resource, | ||
| 71 | - validate_shape: validate_shape, | ||
| 72 | - initializer: initializer, | ||
| 73 | - trainable: trainable, | ||
| 74 | - collections: collections); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | 53 | public VariableScope get_variable_scope() | |
| 78 | 54 | => Tensorflow.variable_scope.get_variable_scope(); | |
| 79 | 55 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -535,7 +535,7 @@ public TensorShape GetTensorShape(TF_Output output) | |||
| 535 | 535 | string debugString = string.Empty; | |
| 536 | 536 | public override string ToString() | |
| 537 | 537 | { | |
| 538 | - return $"{graph_key}, ({_handle})"; | ||
| 538 | + return $"{graph_key}, 0x{_handle.ToString("x16")}"; | ||
| 539 | 539 | /*if (string.IsNullOrEmpty(debugString)) | |
| 540 | 540 | { | |
| 541 | 541 | int len = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,7 @@ public PolynomialDecay(float initial_learning_rate, | |||
| 34 | 34 | this.name = name; | |
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | - public Tensor __call__(RefVariable step) | ||
| 37 | + public Tensor __call__(IVariableV1 step) | ||
| 38 | 38 | { | |
| 39 | 39 | return tf_with(ops.name_scope(name ?? "PolynomialDecay"), scope => | |
| 40 | 40 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,7 +161,7 @@ protected virtual IVariableV1 add_weight(string name, | |||
| 161 | 161 | initializer: initializer, | |
| 162 | 162 | trainable: trainable, | |
| 163 | 163 | getter: (name1, shape1, dtype1, initializer1, trainable1) => | |
| 164 | - tf.get_variable(name1, | ||
| 164 | + tf.compat.v1.get_variable(name1, | ||
| 165 | 165 | shape: new TensorShape(shape1), | |
| 166 | 166 | dtype: dtype1, | |
| 167 | 167 | initializer: initializer1, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,11 +68,11 @@ public static Tensor add_n(Tensor[] inputs, string name = null) | |||
| 68 | 68 | return gen_math_ops.add_n(inputs, name: name); | |
| 69 | 69 | } | |
| 70 | 70 | ||
| 71 | - public static Tensor cast(RefVariable x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null) | ||
| 71 | + public static Tensor cast(IVariableV1 x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null) | ||
| 72 | 72 | { | |
| 73 | 73 | var base_type = dtype.as_base_dtype(); | |
| 74 | 74 | if (base_type == x.dtype) | |
| 75 | - return x; | ||
| 75 | + return x.AsTensor(); | ||
| 76 | 76 | ||
| 77 | 77 | return tf_with(ops.name_scope(name, "Cast", new { x }), scope => | |
| 78 | 78 | { | |
@@ -81,7 +81,7 @@ public static Tensor cast(RefVariable x, TF_DataType dtype = TF_DataType.DtInval | |||
| 81 | 81 | if (t_x.dtype.as_base_dtype() != base_type) | |
| 82 | 82 | t_x = gen_math_ops.cast(t_x, base_type, name: name); | |
| 83 | 83 | ||
| 84 | - return x; | ||
| 84 | + return x.AsTensor(); | ||
| 85 | 85 | }); | |
| 86 | 86 | } | |
| 87 | 87 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,7 @@ public override Operation _apply_dense(Tensor grad, RefVariable var) | |||
| 79 | 79 | use_locking: _use_locking).op; | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - private Operation _apply_sparse_shared(Tensor grad, RefVariable var, Tensor indices, Func<RefVariable, Tensor, Tensor, Tensor> scatter_add) | ||
| 82 | + private Operation _apply_sparse_shared(Tensor grad, IVariableV1 var, Tensor indices, Func<IVariableV1, Tensor, Tensor, Tensor> scatter_add) | ||
| 83 | 83 | { | |
| 84 | 84 | var (beta1_power_v, beta2_power_v) = _get_beta_accumulators(); | |
| 85 | 85 | Tensor beta1_power = math_ops.cast(beta1_power_v, var.dtype.as_base_dtype()); | |
@@ -91,15 +91,15 @@ private Operation _apply_sparse_shared(Tensor grad, RefVariable var, Tensor indi | |||
| 91 | 91 | var lr = (lr_t * math_ops.sqrt(1 - beta2_power) / (1 - beta1_power)); | |
| 92 | 92 | var m = get_slot(var, "m"); | |
| 93 | 93 | var m_scaled_g_values = grad * (1 - beta1_t); | |
| 94 | - var m_t = state_ops.assign(m, m * beta1_t, use_locking: _use_locking); | ||
| 94 | + var m_t = state_ops.assign(m.AsTensor(), m.AsTensor() * beta1_t, use_locking: _use_locking); | ||
| 95 | 95 | tf_with(ops.control_dependencies(new[] { m_t }), delegate | |
| 96 | 96 | { | |
| 97 | 97 | m_t = scatter_add(m, indices, m_scaled_g_values); | |
| 98 | 98 | }); | |
| 99 | 99 | ||
| 100 | 100 | var v = get_slot(var, "v"); | |
| 101 | 101 | var v_scaled_g_values = (grad * grad) * (1 - beta2_t); | |
| 102 | - var v_t = state_ops.assign(v, v * beta2_t, use_locking: _use_locking); | ||
| 102 | + var v_t = state_ops.assign(v.AsTensor(), v.AsTensor() * beta2_t, use_locking: _use_locking); | ||
| 103 | 103 | tf_with(ops.control_dependencies(new[] { v_t }), delegate | |
| 104 | 104 | { | |
| 105 | 105 | v_t = scatter_add(v, indices, v_scaled_g_values); | |
@@ -132,8 +132,8 @@ public override Operation _finish(Operation[] update_ops, string name_scope) | |||
| 132 | 132 | { | |
| 133 | 133 | var (beta1_power, beta2_power) = _get_beta_accumulators(); | |
| 134 | 134 | ops.colocate_with(beta1_power); | |
| 135 | - var update_beta1 = beta1_power.assign(beta1_power * _beta1_t, use_locking: _use_locking); | ||
| 136 | - var update_beta2 = beta2_power.assign(beta2_power * _beta2_t, use_locking: _use_locking); | ||
| 135 | + var update_beta1 = beta1_power.assign(beta1_power.AsTensor() * _beta1_t, use_locking: _use_locking); | ||
| 136 | + var update_beta2 = beta2_power.assign(beta2_power.AsTensor() * _beta2_t, use_locking: _use_locking); | ||
| 137 | 137 | ||
| 138 | 138 | operations.Add(update_beta1); | |
| 139 | 139 | operations.Add(update_beta2); | |
@@ -142,12 +142,12 @@ public override Operation _finish(Operation[] update_ops, string name_scope) | |||
| 142 | 142 | return control_flow_ops.group(operations.ToArray(), name: name_scope); | |
| 143 | 143 | } | |
| 144 | 144 | ||
| 145 | - private (RefVariable, RefVariable) _get_beta_accumulators() | ||
| 145 | + private (IVariableV1, IVariableV1) _get_beta_accumulators() | ||
| 146 | 146 | { | |
| 147 | 147 | ops.init_scope(); | |
| 148 | 148 | var graph = ops.get_default_graph(); | |
| 149 | - return (_get_non_slot_variable("beta1_power", graph: graph) as RefVariable, | ||
| 150 | - _get_non_slot_variable("beta2_power", graph: graph) as RefVariable); | ||
| 149 | + return (_get_non_slot_variable("beta1_power", graph: graph), | ||
| 150 | + _get_non_slot_variable("beta2_power", graph: graph)); | ||
| 151 | 151 | } | |
| 152 | 152 | ||
| 153 | 153 | public override void _prepare() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments