| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a38bd5d commit 3f9f2a3
64 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,14 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections.Generic; | |
| 3 | 3 | using System.Text; | |
| 4 | + using static Tensorflow.Python; | ||
| 4 | 5 | ||
| 5 | 6 | namespace Tensorflow.Clustering | |
| 6 | 7 | { | |
| 7 | 8 | /// <summary> | |
| 8 | 9 | /// Creates the graph for k-means clustering. | |
| 9 | 10 | /// </summary> | |
| 10 | - public class KMeans : Python | ||
| 11 | + public class KMeans | ||
| 11 | 12 | { | |
| 12 | 13 | public const string CLUSTERS_VAR_NAME = "clusters"; | |
| 13 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,13 +2,14 @@ | |||
| 2 | 2 | using System.Collections.Generic; | |
| 3 | 3 | using System.Linq; | |
| 4 | 4 | using System.Text; | |
| 5 | + using static Tensorflow.Python; | ||
| 5 | 6 | ||
| 6 | 7 | namespace Tensorflow.Clustering | |
| 7 | 8 | { | |
| 8 | 9 | /// <summary> | |
| 9 | 10 | /// Internal class to create the op to initialize the clusters. | |
| 10 | 11 | /// </summary> | |
| 11 | - public class _InitializeClustersOpFactory : Python | ||
| 12 | + public class _InitializeClustersOpFactory | ||
| 12 | 13 | { | |
| 13 | 14 | Tensor[] _inputs; | |
| 14 | 15 | Tensor _num_clusters; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,10 +4,11 @@ | |||
| 4 | 4 | using System.Linq; | |
| 5 | 5 | using System.Text; | |
| 6 | 6 | using static Tensorflow.OpDef.Types; | |
| 7 | + using static Tensorflow.Python; | ||
| 7 | 8 | ||
| 8 | 9 | namespace Tensorflow | |
| 9 | 10 | { | |
| 10 | - public class importer : Python | ||
| 11 | + public class importer | ||
| 11 | 12 | { | |
| 12 | 13 | public static ITensorOrOperation[] import_graph_def(GraphDef graph_def, | |
| 13 | 14 | Dictionary<string, Tensor> input_map = null, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,10 +4,11 @@ | |||
| 4 | 4 | using System.Linq; | |
| 5 | 5 | using System.Text; | |
| 6 | 6 | using System.Threading; | |
| 7 | + using static Tensorflow.Python; | ||
| 7 | 8 | ||
| 8 | 9 | namespace Tensorflow | |
| 9 | 10 | { | |
| 10 | - public class gradients_impl : Python | ||
| 11 | + public class gradients_impl | ||
| 11 | 12 | { | |
| 12 | 13 | public static Tensor[] gradients(Tensor[] ys, | |
| 13 | 14 | Tensor[] xs, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,13 +3,14 @@ | |||
| 3 | 3 | using System.Collections.Generic; | |
| 4 | 4 | using System.Linq; | |
| 5 | 5 | using System.Text; | |
| 6 | + using static Tensorflow.Python; | ||
| 6 | 7 | ||
| 7 | 8 | namespace Tensorflow.Gradients | |
| 8 | 9 | { | |
| 9 | 10 | /// <summary> | |
| 10 | 11 | /// Gradients for operators defined in math_ops.py. | |
| 11 | 12 | /// </summary> | |
| 12 | - public class math_grad : Python | ||
| 13 | + public class math_grad | ||
| 13 | 14 | { | |
| 14 | 15 | public static Tensor[] _AddGrad(Operation op, Tensor[] grads) | |
| 15 | 16 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | using System.Linq; | |
| 4 | 4 | using System.Text; | |
| 5 | 5 | using Tensorflow.Operations.ControlFlows; | |
| 6 | + using static Tensorflow.Python; | ||
| 6 | 7 | ||
| 7 | 8 | namespace Tensorflow.Operations | |
| 8 | 9 | { | |
@@ -46,9 +47,9 @@ public CondContext(Tensor pred = null, | |||
| 46 | 47 | if (pred == null && context_def == null) return; | |
| 47 | 48 | ||
| 48 | 49 | _name = ops.get_default_graph().unique_name(name); | |
| 49 | - if (context_def != null) | ||
| 50 | - { | ||
| 51 | - _init_from_proto(context_def, import_scope: import_scope); | ||
| 50 | + if (context_def != null) | ||
| 51 | + { | ||
| 52 | + _init_from_proto(context_def, import_scope: import_scope); | ||
| 52 | 53 | } | |
| 53 | 54 | else | |
| 54 | 55 | { | |
@@ -66,16 +67,16 @@ public CondContext(Tensor pred = null, | |||
| 66 | 67 | } | |
| 67 | 68 | } | |
| 68 | 69 | ||
| 69 | - private void _init_from_proto(CondContextDef context_def, string import_scope = null) | ||
| 70 | - { | ||
| 71 | - var g = ops.get_default_graph(); | ||
| 72 | - _name = ops.prepend_name_scope(context_def.ContextName, import_scope); | ||
| 73 | - var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); | ||
| 74 | - _pred = g.as_graph_element(p1) as Tensor; | ||
| 75 | - var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); | ||
| 76 | - _pivot = g.as_graph_element(p2) as Tensor; | ||
| 77 | - _branch = context_def.Branch; | ||
| 78 | - __init__(values_def: context_def.ValuesDef, import_scope: import_scope); | ||
| 70 | + private void _init_from_proto(CondContextDef context_def, string import_scope = null) | ||
| 71 | + { | ||
| 72 | + var g = ops.get_default_graph(); | ||
| 73 | + _name = ops.prepend_name_scope(context_def.ContextName, import_scope); | ||
| 74 | + var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); | ||
| 75 | + _pred = g.as_graph_element(p1) as Tensor; | ||
| 76 | + var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); | ||
| 77 | + _pivot = g.as_graph_element(p2) as Tensor; | ||
| 78 | + _branch = context_def.Branch; | ||
| 79 | + __init__(values_def: context_def.ValuesDef, import_scope: import_scope); | ||
| 79 | 80 | } | |
| 80 | 81 | ||
| 81 | 82 | /// <summary> | |
@@ -90,8 +91,8 @@ public override Tensor AddValue(Tensor val) | |||
| 90 | 91 | // Use the real value if it comes from outer context. This is needed in | |
| 91 | 92 | // particular for nested conds. | |
| 92 | 93 | if (_external_values.ContainsKey(val.name)) | |
| 93 | - result = _external_values[val.name]; | ||
| 94 | - | ||
| 94 | + result = _external_values[val.name]; | ||
| 95 | + | ||
| 95 | 96 | result = result == null ? val : result; | |
| 96 | 97 | } | |
| 97 | 98 | else | |
@@ -107,10 +108,10 @@ public override Tensor AddValue(Tensor val) | |||
| 107 | 108 | } | |
| 108 | 109 | ||
| 109 | 110 | with(ops.control_dependencies(null), ctrl => | |
| 110 | - { | ||
| 111 | - var results = control_flow_ops._SwitchRefOrTensor(result, _pred); | ||
| 112 | - result = results[_branch]; | ||
| 113 | - if (_outer_context != null) | ||
| 111 | + { | ||
| 112 | + var results = control_flow_ops._SwitchRefOrTensor(result, _pred); | ||
| 113 | + result = results[_branch]; | ||
| 114 | + if (_outer_context != null) | ||
| 114 | 115 | _outer_context.AddInnerOp(result.op); | |
| 115 | 116 | }); | |
| 116 | 117 | ||
@@ -127,87 +128,87 @@ public override Tensor AddValue(Tensor val) | |||
| 127 | 128 | } | |
| 128 | 129 | _external_values[val.name] = result; | |
| 129 | 130 | } | |
| 130 | - return result; | ||
| 131 | - } | ||
| 132 | - | ||
| 131 | + return result; | ||
| 132 | + } | ||
| 133 | + | ||
| 133 | 134 | /// <summary> | |
| 134 | 135 | /// Add the subgraph defined by fn() to the graph. | |
| 135 | 136 | /// </summary> | |
| 136 | - public (T, Tensor) BuildCondBranch<T>(Func<T> fn) | ||
| 137 | - { | ||
| 138 | - // Add the subgraph defined by fn() to the graph. | ||
| 139 | - var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 140 | - var original_result = fn(); | ||
| 141 | - var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 142 | - | ||
| 143 | - //TODO: port this chunck of missing code: | ||
| 144 | - /* | ||
| 145 | - if len(post_summaries) > len(pre_summaries): | ||
| 146 | - new_summaries = post_summaries[len(pre_summaries):] | ||
| 147 | - summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access | ||
| 148 | - summary_ref[:] = pre_summaries | ||
| 149 | - with ops.control_dependencies(new_summaries): | ||
| 150 | - if original_result is None: | ||
| 151 | - return no_op(), None | ||
| 152 | - else: | ||
| 153 | - original_result = nest.map_structure(array_ops.identity, | ||
| 154 | - original_result) | ||
| 155 | - */ | ||
| 156 | - if (original_result == null) | ||
| 157 | - return (original_result, null); | ||
| 158 | - | ||
| 159 | - switch (original_result) | ||
| 160 | - { | ||
| 161 | - case Tensor result: | ||
| 162 | - return (original_result, _BuildCondTensor(result)); | ||
| 163 | - case Operation op: | ||
| 164 | - return (original_result, _BuildCondTensor(op)); | ||
| 137 | + public (T, Tensor) BuildCondBranch<T>(Func<T> fn) | ||
| 138 | + { | ||
| 139 | + // Add the subgraph defined by fn() to the graph. | ||
| 140 | + var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 141 | + var original_result = fn(); | ||
| 142 | + var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 143 | + | ||
| 144 | + //TODO: port this chunck of missing code: | ||
| 145 | + /* | ||
| 146 | + if len(post_summaries) > len(pre_summaries): | ||
| 147 | + new_summaries = post_summaries[len(pre_summaries):] | ||
| 148 | + summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access | ||
| 149 | + summary_ref[:] = pre_summaries | ||
| 150 | + with ops.control_dependencies(new_summaries): | ||
| 151 | + if original_result is None: | ||
| 152 | + return no_op(), None | ||
| 153 | + else: | ||
| 154 | + original_result = nest.map_structure(array_ops.identity, | ||
| 155 | + original_result) | ||
| 156 | + */ | ||
| 157 | + if (original_result == null) | ||
| 158 | + return (original_result, null); | ||
| 159 | + | ||
| 160 | + switch (original_result) | ||
| 161 | + { | ||
| 162 | + case Tensor result: | ||
| 163 | + return (original_result, _BuildCondTensor(result)); | ||
| 164 | + case Operation op: | ||
| 165 | + return (original_result, _BuildCondTensor(op)); | ||
| 165 | 166 | case float[] fv: | |
| 166 | 167 | { | |
| 167 | 168 | var result = ops.convert_to_tensor(fv[0]); | |
| 168 | 169 | return (original_result, _BuildCondTensor(result)); | |
| 169 | - } | ||
| 170 | - default: | ||
| 171 | - return (original_result, null); | ||
| 172 | - } | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - public (T[], Tensor[]) BuildCondBranch<T>(Func<T[]> fn) | ||
| 176 | - { | ||
| 177 | - // Add the subgraph defined by fn() to the graph. | ||
| 178 | - var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 179 | - var original_result = fn(); | ||
| 180 | - var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 181 | - | ||
| 182 | - switch (original_result) | ||
| 183 | - { | ||
| 184 | - case Tensor[] results: | ||
| 185 | - return (original_result, results.Select(_BuildCondTensor).ToArray()); | ||
| 186 | - case Operation[] results: | ||
| 187 | - return (original_result, results.Select(_BuildCondTensor).ToArray()); | ||
| 188 | - case float[] fv: | ||
| 189 | - var result = ops.convert_to_tensor(fv[0]); | ||
| 190 | - return (original_result, new Tensor[] { result }); | ||
| 191 | - default: | ||
| 192 | - return (original_result, new Tensor[0]); | ||
| 193 | - } | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - private Tensor _BuildCondTensor(ITensorOrOperation v) | ||
| 197 | - { | ||
| 198 | - switch (v) | ||
| 199 | - { | ||
| 200 | - case Operation op: | ||
| 201 | - // Use pivot as the proxy for this op. | ||
| 202 | - return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); | ||
| 203 | - case Tensor t: | ||
| 204 | - return _ProcessOutputTensor(t); | ||
| 205 | - default: | ||
| 206 | - return _ProcessOutputTensor(ops.convert_to_tensor(v)); | ||
| 207 | - | ||
| 208 | - } | ||
| 209 | - } | ||
| 210 | - | ||
| 170 | + } | ||
| 171 | + default: | ||
| 172 | + return (original_result, null); | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public (T[], Tensor[]) BuildCondBranch<T>(Func<T[]> fn) | ||
| 177 | + { | ||
| 178 | + // Add the subgraph defined by fn() to the graph. | ||
| 179 | + var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 180 | + var original_result = fn(); | ||
| 181 | + var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | ||
| 182 | + | ||
| 183 | + switch (original_result) | ||
| 184 | + { | ||
| 185 | + case Tensor[] results: | ||
| 186 | + return (original_result, results.Select(_BuildCondTensor).ToArray()); | ||
| 187 | + case Operation[] results: | ||
| 188 | + return (original_result, results.Select(_BuildCondTensor).ToArray()); | ||
| 189 | + case float[] fv: | ||
| 190 | + var result = ops.convert_to_tensor(fv[0]); | ||
| 191 | + return (original_result, new Tensor[] { result }); | ||
| 192 | + default: | ||
| 193 | + return (original_result, new Tensor[0]); | ||
| 194 | + } | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + private Tensor _BuildCondTensor(ITensorOrOperation v) | ||
| 198 | + { | ||
| 199 | + switch (v) | ||
| 200 | + { | ||
| 201 | + case Operation op: | ||
| 202 | + // Use pivot as the proxy for this op. | ||
| 203 | + return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); | ||
| 204 | + case Tensor t: | ||
| 205 | + return _ProcessOutputTensor(t); | ||
| 206 | + default: | ||
| 207 | + return _ProcessOutputTensor(ops.convert_to_tensor(v)); | ||
| 208 | + | ||
| 209 | + } | ||
| 210 | + } | ||
| 211 | + | ||
| 211 | 212 | /// <summary> | |
| 212 | 213 | /// Process an output tensor of a conditional branch. | |
| 213 | 214 | /// </summary> | |
@@ -238,7 +239,7 @@ private Tensor _ProcessOutputTensor(Tensor val) | |||
| 238 | 239 | } | |
| 239 | 240 | return real_val; | |
| 240 | 241 | } | |
| 241 | - | ||
| 242 | + | ||
| 242 | 243 | protected override void _AddOpInternal(Operation op) | |
| 243 | 244 | { | |
| 244 | 245 | if (op.inputs.Length == 0) | |
@@ -324,20 +325,20 @@ public override bool back_prop | |||
| 324 | 325 | } | |
| 325 | 326 | } | |
| 326 | 327 | ||
| 327 | - public CondContextDef to_proto(string export_scope) | ||
| 328 | - { | ||
| 329 | - throw new NotImplementedException(); | ||
| 330 | - } | ||
| 331 | - | ||
| 332 | - public CondContext from_proto(CondContextDef proto, string import_scope) | ||
| 333 | - { | ||
| 334 | - var ret = new CondContext(context_def: proto, import_scope: import_scope); | ||
| 335 | - | ||
| 336 | - ret.Enter(); | ||
| 337 | - foreach (var nested_def in proto.NestedContexts) | ||
| 338 | - from_control_flow_context_def(nested_def, import_scope: import_scope); | ||
| 339 | - ret.Exit(); | ||
| 340 | - return ret; | ||
| 341 | - } | ||
| 342 | - } | ||
| 328 | + public CondContextDef to_proto(string export_scope) | ||
| 329 | + { | ||
| 330 | + throw new NotImplementedException(); | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + public CondContext from_proto(CondContextDef proto, string import_scope) | ||
| 334 | + { | ||
| 335 | + var ret = new CondContext(context_def: proto, import_scope: import_scope); | ||
| 336 | + | ||
| 337 | + ret.Enter(); | ||
| 338 | + foreach (var nested_def in proto.NestedContexts) | ||
| 339 | + from_control_flow_context_def(nested_def, import_scope: import_scope); | ||
| 340 | + ret.Exit(); | ||
| 341 | + return ret; | ||
| 342 | + } | ||
| 343 | + } | ||
| 343 | 344 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments