@@ -1,13 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Clustering | |||
{ | |||
/// <summary> | |||
/// Creates the graph for k-means clustering. | |||
/// </summary> | |||
public class KMeans : Python | |||
public class KMeans | |||
{ | |||
public const string CLUSTERS_VAR_NAME = "clusters"; | |||
@@ -2,13 +2,14 @@ | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Clustering | |||
{ | |||
/// <summary> | |||
/// Internal class to create the op to initialize the clusters. | |||
/// </summary> | |||
public class _InitializeClustersOpFactory : Python | |||
public class _InitializeClustersOpFactory | |||
{ | |||
Tensor[] _inputs; | |||
Tensor _num_clusters; | |||
@@ -4,10 +4,11 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using static Tensorflow.OpDef.Types; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class importer : Python | |||
public class importer | |||
{ | |||
public static ITensorOrOperation[] import_graph_def(GraphDef graph_def, | |||
Dictionary<string, Tensor> input_map = null, | |||
@@ -4,10 +4,11 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class gradients_impl : Python | |||
public class gradients_impl | |||
{ | |||
public static Tensor[] gradients(Tensor[] ys, | |||
Tensor[] xs, | |||
@@ -3,13 +3,14 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Gradients | |||
{ | |||
/// <summary> | |||
/// Gradients for operators defined in math_ops.py. | |||
/// </summary> | |||
public class math_grad : Python | |||
public class math_grad | |||
{ | |||
public static Tensor[] _AddGrad(Operation op, Tensor[] grads) | |||
{ | |||
@@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using Tensorflow.Operations.ControlFlows; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Operations | |||
{ | |||
@@ -46,9 +47,9 @@ namespace Tensorflow.Operations | |||
if (pred == null && context_def == null) return; | |||
_name = ops.get_default_graph().unique_name(name); | |||
if (context_def != null) | |||
{ | |||
_init_from_proto(context_def, import_scope: import_scope); | |||
if (context_def != null) | |||
{ | |||
_init_from_proto(context_def, import_scope: import_scope); | |||
} | |||
else | |||
{ | |||
@@ -66,16 +67,16 @@ namespace Tensorflow.Operations | |||
} | |||
} | |||
private void _init_from_proto(CondContextDef context_def, string import_scope = null) | |||
{ | |||
var g = ops.get_default_graph(); | |||
_name = ops.prepend_name_scope(context_def.ContextName, import_scope); | |||
var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); | |||
_pred = g.as_graph_element(p1) as Tensor; | |||
var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); | |||
_pivot = g.as_graph_element(p2) as Tensor; | |||
_branch = context_def.Branch; | |||
__init__(values_def: context_def.ValuesDef, import_scope: import_scope); | |||
private void _init_from_proto(CondContextDef context_def, string import_scope = null) | |||
{ | |||
var g = ops.get_default_graph(); | |||
_name = ops.prepend_name_scope(context_def.ContextName, import_scope); | |||
var p1 = ops.prepend_name_scope(context_def.PredName, import_scope); | |||
_pred = g.as_graph_element(p1) as Tensor; | |||
var p2 = ops.prepend_name_scope(context_def.PivotName, import_scope); | |||
_pivot = g.as_graph_element(p2) as Tensor; | |||
_branch = context_def.Branch; | |||
__init__(values_def: context_def.ValuesDef, import_scope: import_scope); | |||
} | |||
/// <summary> | |||
@@ -90,8 +91,8 @@ namespace Tensorflow.Operations | |||
// Use the real value if it comes from outer context. This is needed in | |||
// particular for nested conds. | |||
if (_external_values.ContainsKey(val.name)) | |||
result = _external_values[val.name]; | |||
result = _external_values[val.name]; | |||
result = result == null ? val : result; | |||
} | |||
else | |||
@@ -107,10 +108,10 @@ namespace Tensorflow.Operations | |||
} | |||
with(ops.control_dependencies(null), ctrl => | |||
{ | |||
var results = control_flow_ops._SwitchRefOrTensor(result, _pred); | |||
result = results[_branch]; | |||
if (_outer_context != null) | |||
{ | |||
var results = control_flow_ops._SwitchRefOrTensor(result, _pred); | |||
result = results[_branch]; | |||
if (_outer_context != null) | |||
_outer_context.AddInnerOp(result.op); | |||
}); | |||
@@ -127,87 +128,87 @@ namespace Tensorflow.Operations | |||
} | |||
_external_values[val.name] = result; | |||
} | |||
return result; | |||
} | |||
return result; | |||
} | |||
/// <summary> | |||
/// Add the subgraph defined by fn() to the graph. | |||
/// </summary> | |||
public (T, Tensor) BuildCondBranch<T>(Func<T> fn) | |||
{ | |||
// Add the subgraph defined by fn() to the graph. | |||
var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
var original_result = fn(); | |||
var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
//TODO: port this chunck of missing code: | |||
/* | |||
if len(post_summaries) > len(pre_summaries): | |||
new_summaries = post_summaries[len(pre_summaries):] | |||
summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access | |||
summary_ref[:] = pre_summaries | |||
with ops.control_dependencies(new_summaries): | |||
if original_result is None: | |||
return no_op(), None | |||
else: | |||
original_result = nest.map_structure(array_ops.identity, | |||
original_result) | |||
*/ | |||
if (original_result == null) | |||
return (original_result, null); | |||
switch (original_result) | |||
{ | |||
case Tensor result: | |||
return (original_result, _BuildCondTensor(result)); | |||
case Operation op: | |||
return (original_result, _BuildCondTensor(op)); | |||
public (T, Tensor) BuildCondBranch<T>(Func<T> fn) | |||
{ | |||
// Add the subgraph defined by fn() to the graph. | |||
var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
var original_result = fn(); | |||
var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
//TODO: port this chunck of missing code: | |||
/* | |||
if len(post_summaries) > len(pre_summaries): | |||
new_summaries = post_summaries[len(pre_summaries):] | |||
summary_ref = ops.get_collection_ref(ops.GraphKeys._SUMMARY_COLLECTION) # pylint: disable=protected-access | |||
summary_ref[:] = pre_summaries | |||
with ops.control_dependencies(new_summaries): | |||
if original_result is None: | |||
return no_op(), None | |||
else: | |||
original_result = nest.map_structure(array_ops.identity, | |||
original_result) | |||
*/ | |||
if (original_result == null) | |||
return (original_result, null); | |||
switch (original_result) | |||
{ | |||
case Tensor result: | |||
return (original_result, _BuildCondTensor(result)); | |||
case Operation op: | |||
return (original_result, _BuildCondTensor(op)); | |||
case float[] fv: | |||
{ | |||
var result = ops.convert_to_tensor(fv[0]); | |||
return (original_result, _BuildCondTensor(result)); | |||
} | |||
default: | |||
return (original_result, null); | |||
} | |||
} | |||
public (T[], Tensor[]) BuildCondBranch<T>(Func<T[]> fn) | |||
{ | |||
// Add the subgraph defined by fn() to the graph. | |||
var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
var original_result = fn(); | |||
var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
switch (original_result) | |||
{ | |||
case Tensor[] results: | |||
return (original_result, results.Select(_BuildCondTensor).ToArray()); | |||
case Operation[] results: | |||
return (original_result, results.Select(_BuildCondTensor).ToArray()); | |||
case float[] fv: | |||
var result = ops.convert_to_tensor(fv[0]); | |||
return (original_result, new Tensor[] { result }); | |||
default: | |||
return (original_result, new Tensor[0]); | |||
} | |||
} | |||
private Tensor _BuildCondTensor(ITensorOrOperation v) | |||
{ | |||
switch (v) | |||
{ | |||
case Operation op: | |||
// Use pivot as the proxy for this op. | |||
return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); | |||
case Tensor t: | |||
return _ProcessOutputTensor(t); | |||
default: | |||
return _ProcessOutputTensor(ops.convert_to_tensor(v)); | |||
} | |||
} | |||
} | |||
default: | |||
return (original_result, null); | |||
} | |||
} | |||
public (T[], Tensor[]) BuildCondBranch<T>(Func<T[]> fn) | |||
{ | |||
// Add the subgraph defined by fn() to the graph. | |||
var pre_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
var original_result = fn(); | |||
var post_summaries = ops.get_collection(ops.GraphKeys._SUMMARY_COLLECTION); | |||
switch (original_result) | |||
{ | |||
case Tensor[] results: | |||
return (original_result, results.Select(_BuildCondTensor).ToArray()); | |||
case Operation[] results: | |||
return (original_result, results.Select(_BuildCondTensor).ToArray()); | |||
case float[] fv: | |||
var result = ops.convert_to_tensor(fv[0]); | |||
return (original_result, new Tensor[] { result }); | |||
default: | |||
return (original_result, new Tensor[0]); | |||
} | |||
} | |||
private Tensor _BuildCondTensor(ITensorOrOperation v) | |||
{ | |||
switch (v) | |||
{ | |||
case Operation op: | |||
// Use pivot as the proxy for this op. | |||
return control_flow_ops.with_dependencies(new Operation[] { op }, _pivot); | |||
case Tensor t: | |||
return _ProcessOutputTensor(t); | |||
default: | |||
return _ProcessOutputTensor(ops.convert_to_tensor(v)); | |||
} | |||
} | |||
/// <summary> | |||
/// Process an output tensor of a conditional branch. | |||
/// </summary> | |||
@@ -238,7 +239,7 @@ namespace Tensorflow.Operations | |||
} | |||
return real_val; | |||
} | |||
protected override void _AddOpInternal(Operation op) | |||
{ | |||
if (op.inputs.Length == 0) | |||
@@ -324,20 +325,20 @@ namespace Tensorflow.Operations | |||
} | |||
} | |||
public CondContextDef to_proto(string export_scope) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public CondContext from_proto(CondContextDef proto, string import_scope) | |||
{ | |||
var ret = new CondContext(context_def: proto, import_scope: import_scope); | |||
ret.Enter(); | |||
foreach (var nested_def in proto.NestedContexts) | |||
from_control_flow_context_def(nested_def, import_scope: import_scope); | |||
ret.Exit(); | |||
return ret; | |||
} | |||
} | |||
public CondContextDef to_proto(string export_scope) | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
public CondContext from_proto(CondContextDef proto, string import_scope) | |||
{ | |||
var ret = new CondContext(context_def: proto, import_scope: import_scope); | |||
ret.Enter(); | |||
foreach (var nested_def in proto.NestedContexts) | |||
from_control_flow_context_def(nested_def, import_scope: import_scope); | |||
ret.Exit(); | |||
return ret; | |||
} | |||
} | |||
} |
@@ -3,10 +3,11 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using Tensorflow.Operations.ControlFlows; | |||
using static Tensorflow.ControlFlowContextDef; | |||
using static Tensorflow.ControlFlowContextDef; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Operations | |||
{ | |||
{ | |||
/// <summary> | |||
/// The base class for control flow context. | |||
/// | |||
@@ -24,7 +25,7 @@ namespace Tensorflow.Operations | |||
/// 4. A ControlFlowContext has _context_stack. | |||
/// Pushed and popped by ctxt.Enter() and ctxt.Exit() | |||
/// </summary> | |||
public abstract class ControlFlowContext : Python, IPython | |||
public abstract class ControlFlowContext : IPython | |||
{ | |||
/// <summary> | |||
/// The predicate tensor in this branch | |||
@@ -59,38 +60,38 @@ namespace Tensorflow.Operations | |||
{ | |||
} | |||
/// <summary> | |||
/// Initializes values and external_values from `ValuesDef` protocol buffer. | |||
/// </summary> | |||
/// <param name="values_def"></param> | |||
/// <summary> | |||
/// Initializes values and external_values from `ValuesDef` protocol buffer. | |||
/// </summary> | |||
/// <param name="values_def"></param> | |||
/// <param name="import_scope"></param> | |||
protected void _init_values_from_proto(ValuesDef values_def, string import_scope = null) | |||
{ | |||
_external_values = new Dictionary<string, ITensorOrOperation>(); | |||
foreach (var value in values_def.Values) | |||
_values.Add(value); | |||
var g = ops.get_default_graph(); | |||
foreach(var value in values_def.ExternalValues) | |||
{ | |||
var k = ops.prepend_name_scope(value.Key, import_scope); | |||
var v = value.Value; | |||
_external_values[k] = g.as_graph_element(ops.prepend_name_scope(v, import_scope)); | |||
} | |||
var op_names = _values.Where(x => !_external_values.ContainsKey(x)) | |||
.Select(x => x.Split(':')[0]) | |||
.ToArray(); | |||
foreach (var op in op_names) | |||
(g.as_graph_element(op) as Operation)._set_control_flow_context(this); | |||
protected void _init_values_from_proto(ValuesDef values_def, string import_scope = null) | |||
{ | |||
_external_values = new Dictionary<string, ITensorOrOperation>(); | |||
foreach (var value in values_def.Values) | |||
_values.Add(value); | |||
var g = ops.get_default_graph(); | |||
foreach(var value in values_def.ExternalValues) | |||
{ | |||
var k = ops.prepend_name_scope(value.Key, import_scope); | |||
var v = value.Value; | |||
_external_values[k] = g.as_graph_element(ops.prepend_name_scope(v, import_scope)); | |||
} | |||
var op_names = _values.Where(x => !_external_values.ContainsKey(x)) | |||
.Select(x => x.Split(':')[0]) | |||
.ToArray(); | |||
foreach (var op in op_names) | |||
(g.as_graph_element(op) as Operation)._set_control_flow_context(this); | |||
} | |||
public void __exit__() | |||
{ | |||
} | |||
/// <summary> | |||
/// Enter this control flow context. | |||
/// <summary> | |||
/// Enter this control flow context. | |||
/// </summary> | |||
public virtual void Enter() | |||
{ | |||
@@ -127,7 +128,7 @@ namespace Tensorflow.Operations | |||
public virtual Tensor AddValue(Tensor val) | |||
{ | |||
// to be overridden | |||
return null; | |||
return null; | |||
} | |||
/// <summary> | |||
@@ -148,17 +149,17 @@ namespace Tensorflow.Operations | |||
protected virtual void _AddOpInternal(Operation op) | |||
{ | |||
} | |||
} | |||
protected bool OpInContext(Operation op) | |||
{ | |||
return IsContainingContext(op._get_control_flow_context(), this); | |||
} | |||
/// <summary> | |||
/// Returns true if `maybe_containing_ctxt` is or contains `ctxt`. | |||
/// </summary> | |||
public static bool IsContainingContext(ControlFlowContext ctxt, ControlFlowContext maybe_containing_ctxt) | |||
} | |||
/// <summary> | |||
/// Returns true if `maybe_containing_ctxt` is or contains `ctxt`. | |||
/// </summary> | |||
public static bool IsContainingContext(ControlFlowContext ctxt, ControlFlowContext maybe_containing_ctxt) | |||
{ | |||
while (ctxt != maybe_containing_ctxt) | |||
{ | |||
@@ -167,7 +168,7 @@ namespace Tensorflow.Operations | |||
ctxt = ctxt.outer_context; | |||
} | |||
return true; | |||
} | |||
} | |||
protected virtual void _RemoveExternalControlEdges(Operation op) | |||
@@ -185,21 +186,21 @@ namespace Tensorflow.Operations | |||
return null; | |||
} | |||
/// <summary> | |||
/// Deserializes `context_def` into the appropriate ControlFlowContext. | |||
/// </summary> | |||
/// <param name="context_def">ControlFlowContextDef proto</param> | |||
/// <param name="import_scope">Name scope to add</param> | |||
/// <summary> | |||
/// Deserializes `context_def` into the appropriate ControlFlowContext. | |||
/// </summary> | |||
/// <param name="context_def">ControlFlowContextDef proto</param> | |||
/// <param name="import_scope">Name scope to add</param> | |||
/// <returns>A ControlFlowContext subclass</returns> | |||
protected ControlFlowContext from_control_flow_context_def(ControlFlowContextDef context_def, string import_scope = "") | |||
{ | |||
switch (context_def.CtxtCase) | |||
{ | |||
case CtxtOneofCase.CondCtxt: | |||
return new CondContext().from_proto(context_def.CondCtxt, import_scope: import_scope); | |||
} | |||
throw new NotImplementedException($"Unknown ControlFlowContextDef field: {context_def.CtxtCase}"); | |||
protected ControlFlowContext from_control_flow_context_def(ControlFlowContextDef context_def, string import_scope = "") | |||
{ | |||
switch (context_def.CtxtCase) | |||
{ | |||
case CtxtOneofCase.CondCtxt: | |||
return new CondContext().from_proto(context_def.CondCtxt, import_scope: import_scope); | |||
} | |||
throw new NotImplementedException($"Unknown ControlFlowContextDef field: {context_def.CtxtCase}"); | |||
} | |||
public object to_proto() | |||
@@ -2,12 +2,12 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class _BaseDistribution : Python | |||
public class _BaseDistribution | |||
{ | |||
// Abstract base class needed for resolving subclass hierarchy. | |||
} | |||
@@ -1,6 +1,7 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class LossesImpl : Python | |||
public class LossesImpl | |||
{ | |||
public Tensor sparse_softmax_cross_entropy(Tensor labels, | |||
Tensor logits, | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow.Operations | |||
{ | |||
public class MaxPoolFunction : Python, IPoolFunction | |||
public class MaxPoolFunction : IPoolFunction | |||
{ | |||
public Tensor Apply(Tensor value, | |||
int[] ksize, | |||
@@ -7,10 +7,11 @@ using System.Linq; | |||
using System.Runtime.InteropServices; | |||
using System.Text; | |||
using static Tensorflow.OpDef.Types; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class OpDefLibrary : Python | |||
public class OpDefLibrary | |||
{ | |||
public Operation _apply_op_helper(string op_type_name, string name = null, object args = null) | |||
=> _apply_op_helper(op_type_name, name: name, keywords: ConvertToDict(args)); | |||
@@ -2,10 +2,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class array_ops : Python | |||
public class array_ops | |||
{ | |||
public static Tensor placeholder_with_default<T>(T input, int[] shape, string name = null) | |||
=> gen_array_ops.placeholder_with_default(input, shape, name); | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class check_ops : Python | |||
public class check_ops | |||
{ | |||
/// <summary> | |||
/// Assert the condition `x == y` holds element-wise. | |||
@@ -5,10 +5,11 @@ using System.Text; | |||
using Tensorflow.Operations; | |||
using Tensorflow.Operations.ControlFlows; | |||
using util = Tensorflow.control_flow_util; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class control_flow_ops : Python | |||
public class control_flow_ops | |||
{ | |||
public static Operation Assert(Tensor condition, object[] data, int? summarize = null, string name = null) | |||
{ | |||
@@ -143,8 +144,8 @@ namespace Tensorflow | |||
return tpl.ToArray(); | |||
}); | |||
} | |||
} | |||
/// <summary> | |||
/// Produces the content of `output_tensor` only after `dependencies`. | |||
/// | |||
@@ -155,11 +156,11 @@ namespace Tensorflow | |||
/// no guarantee that `output_tensor` will be evaluated after any `dependencies` | |||
/// have run. | |||
/// | |||
/// See also `tf.tuple` and `tf.group`. | |||
/// </summary> | |||
/// <param name="dependencies">Iterable of operations to run before this op finishes.</param> | |||
/// <param name="output_tensor">A `Tensor` or `IndexedSlices` that will be returned.</param> | |||
/// <param name="name">(Optional) A name for this operation.</param> | |||
/// See also `tf.tuple` and `tf.group`. | |||
/// </summary> | |||
/// <param name="dependencies">Iterable of operations to run before this op finishes.</param> | |||
/// <param name="output_tensor">A `Tensor` or `IndexedSlices` that will be returned.</param> | |||
/// <param name="name">(Optional) A name for this operation.</param> | |||
/// <returns>Same as `output_tensor`.</returns> | |||
public static Tensor with_dependencies(Operation[] dependencies, Tensor output_tensor, string name = null) | |||
{ | |||
@@ -210,23 +211,23 @@ namespace Tensorflow | |||
/// </returns> | |||
public static Tensor[] _SwitchRefOrTensor(Tensor data, Tensor pred, string name = "Switch") | |||
{ | |||
data = ops.convert_to_tensor_or_indexed_slices(data, name: "data"); | |||
// NOTE(vrv): ops.colocate_with(data, ignore_existing=True) below | |||
// addresses the following scenario. | |||
// | |||
// Assume you execute Optimizer.apply_gradients() in a branch of a cond(). | |||
// | |||
// 1. The update op is created inside a `with ops.colocate(var):` block | |||
// | |||
// 2. Some tensor `data` is captured and a switch is created in a | |||
// `with ops.colocate_with(data):` block. | |||
// | |||
// with ops.colocate_with(var): | |||
// with ops.colocate_with(data): | |||
// op = ... | |||
// | |||
// var and data may be pinned to different devices, so we want to ops | |||
// created within ops.colocate_with(data) to ignore the existing stack. | |||
data = ops.convert_to_tensor_or_indexed_slices(data, name: "data"); | |||
// NOTE(vrv): ops.colocate_with(data, ignore_existing=True) below | |||
// addresses the following scenario. | |||
// | |||
// Assume you execute Optimizer.apply_gradients() in a branch of a cond(). | |||
// | |||
// 1. The update op is created inside a `with ops.colocate(var):` block | |||
// | |||
// 2. Some tensor `data` is captured and a switch is created in a | |||
// `with ops.colocate_with(data):` block. | |||
// | |||
// with ops.colocate_with(var): | |||
// with ops.colocate_with(data): | |||
// op = ... | |||
// | |||
// var and data may be pinned to different devices, so we want to ops | |||
// created within ops.colocate_with(data) to ignore the existing stack. | |||
ops.colocate_with(data, ignore_existing: true); | |||
{ | |||
if (data is Tensor) | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class embedding_ops : Python | |||
public class embedding_ops | |||
{ | |||
/// <summary> | |||
/// Helper function for embedding_lookup and _compute_sampled_logits. | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class gen_control_flow_ops : Python | |||
public class gen_control_flow_ops | |||
{ | |||
public static OpDefLibrary _op_def_lib = new OpDefLibrary(); | |||
@@ -13,8 +14,8 @@ namespace Tensorflow | |||
var _op = _op_def_lib._apply_op_helper("NoOp", name, null); | |||
return _op; | |||
} | |||
} | |||
/// <summary> | |||
/// Forwards `data` to the output port determined by `pred`. | |||
/// | |||
@@ -3,13 +3,14 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow.Framework; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
/// <summary> | |||
/// python\ops\math_ops.py | |||
/// </summary> | |||
public class math_ops : Python | |||
public class math_ops | |||
{ | |||
public static Tensor abs(Tensor x, string name = null) | |||
{ | |||
@@ -2,10 +2,11 @@ | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow.Operations; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class nn_impl : Python | |||
public class nn_impl | |||
{ | |||
/// <summary> | |||
/// Normalizes along dimension `axis` using an L2 norm. | |||
@@ -1,10 +1,11 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class random_ops : Python | |||
public class random_ops | |||
{ | |||
/// <summary> | |||
/// | |||
@@ -12,9 +12,9 @@ namespace Tensorflow | |||
/// <summary> | |||
/// Mapping C# functions to Python | |||
/// </summary> | |||
public class Python | |||
public static class Python | |||
{ | |||
protected void print(object obj) | |||
public static void print(object obj) | |||
{ | |||
Console.WriteLine(obj.ToString()); | |||
} | |||
@@ -22,9 +22,9 @@ namespace Tensorflow | |||
//protected int len<T>(IEnumerable<T> a) | |||
// => a.Count(); | |||
protected int len(object a) | |||
public static int len(object a) | |||
{ | |||
switch (a) | |||
switch (a) | |||
{ | |||
case Array arr: | |||
return arr.Length; | |||
@@ -35,17 +35,17 @@ namespace Tensorflow | |||
case NDArray ndArray: | |||
return ndArray.len; | |||
case IEnumerable enumerable: | |||
return enumerable.OfType<object>().Count(); | |||
} | |||
throw new NotImplementedException("len() not implemented for type: " + a.GetType()); | |||
return enumerable.OfType<object>().Count(); | |||
} | |||
throw new NotImplementedException("len() not implemented for type: " + a.GetType()); | |||
} | |||
protected IEnumerable<int> range(int end) | |||
public static IEnumerable<int> range(int end) | |||
{ | |||
return Enumerable.Range(0, end); | |||
} | |||
protected IEnumerable<int> range(int start, int end) | |||
public static IEnumerable<int> range(int start, int end) | |||
{ | |||
return Enumerable.Range(start, end - start); | |||
} | |||
@@ -170,8 +170,8 @@ namespace Tensorflow | |||
dictionary.Add(name, obj); | |||
} | |||
return dictionary; | |||
} | |||
} | |||
public static bool hasattr(object obj, string key) | |||
{ | |||
var __type__ = (obj).GetType(); | |||
@@ -1,6 +1,7 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -6,6 +6,7 @@ using System.Linq; | |||
using System.Runtime.InteropServices; | |||
using System.Text; | |||
using static Tensorflow.c_api; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -13,7 +14,7 @@ namespace Tensorflow | |||
/// A tensor is a generalization of vectors and matrices to potentially higher dimensions. | |||
/// Internally, TensorFlow represents tensors as n-dimensional arrays of base datatypes. | |||
/// </summary> | |||
public partial class Tensor : Python, IDisposable, ITensorOrOperation | |||
public partial class Tensor : IDisposable, ITensorOrOperation | |||
{ | |||
private readonly IntPtr _handle; | |||
@@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using distribute_lib = Tensorflow.Distribute; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -12,7 +13,7 @@ namespace Tensorflow | |||
/// class directly, but instead instantiate one of its subclasses such as | |||
/// `GradientDescentOptimizer`, `AdagradOptimizer`, or `MomentumOptimizer`. | |||
/// </summary> | |||
public abstract class Optimizer : Python | |||
public abstract class Optimizer | |||
{ | |||
// Values for gate_gradients. | |||
public static int GATE_NONE = 0; | |||
@@ -89,8 +90,8 @@ namespace Tensorflow | |||
$" that do not support gradients, between variables {string.Join(",", vars_with_grad.Select(x => x.name))} and loss {loss}."); | |||
return apply_gradients(grads_and_vars, global_step:global_step, name:name); | |||
} | |||
} | |||
/// <summary> | |||
/// Apply gradients to variables. | |||
/// | |||
@@ -3,10 +3,11 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using Tensorflow.Operations; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public class BaseSaverBuilder : Python | |||
public class BaseSaverBuilder | |||
{ | |||
protected SaverDef.Types.CheckpointFormatVersion _write_version; | |||
@@ -1,6 +1,7 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -4,6 +4,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -1,13 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
/// <summary> | |||
/// Variable scope object to carry defaults to provide to `get_variable` | |||
/// </summary> | |||
public class VariableScope : Python | |||
public class VariableScope | |||
{ | |||
public bool use_resource { get; set; } | |||
private _ReuseMode _reuse; | |||
@@ -1,6 +1,7 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
@@ -14,7 +15,7 @@ namespace Tensorflow | |||
/// the variable are fixed. The value can be changed using one of the assign methods. | |||
/// https://tensorflow.org/guide/variables | |||
/// </summary> | |||
public class VariableV1 : Python | |||
public class VariableV1 | |||
{ | |||
public VariableV1(object initial_value = null, | |||
bool trainable = true, | |||
@@ -8,10 +8,11 @@ using Google.Protobuf; | |||
using System.Linq; | |||
using NumSharp; | |||
using System.ComponentModel; | |||
using static Tensorflow.Python; | |||
namespace Tensorflow | |||
{ | |||
public partial class ops : Python | |||
public partial class ops | |||
{ | |||
public static void add_to_collection<T>(string name, T value) | |||
{ | |||
@@ -49,7 +50,7 @@ namespace Tensorflow | |||
return get_default_graph().get_collection_ref(key); | |||
} | |||
private static Graph default_graph; | |||
private static Graph default_graph; | |||
/// <summary> | |||
/// Returns the default graph for the current thread. | |||
/// | |||
@@ -60,8 +61,8 @@ namespace Tensorflow | |||
/// NOTE: The default graph is a property of the current thread.If you | |||
/// create a new thread, and wish to use the default graph in that | |||
/// thread, you must explicitly add a `with g.as_default():` in that | |||
/// thread's function. | |||
/// </summary> | |||
/// thread's function. | |||
/// </summary> | |||
/// <returns></returns> | |||
public static Graph get_default_graph() | |||
{ | |||
@@ -76,8 +77,8 @@ namespace Tensorflow | |||
//TODO: original source does not have a 'set_default_graph' and indicates there should be a _default_graph_stack! | |||
default_graph = graph; | |||
return default_graph; | |||
} | |||
} | |||
/// <summary> | |||
/// Clears the default graph stack and resets the global default graph. | |||
/// | |||
@@ -85,8 +86,8 @@ namespace Tensorflow | |||
/// function applies only to the current thread.Calling this function while | |||
/// a `tf.Session` or `tf.InteractiveSession` is active will result in undefined | |||
/// behavior. Using any previously created `tf.Operation` or `tf.Tensor` objects | |||
/// after calling this function will result in undefined behavior. | |||
/// </summary> | |||
/// after calling this function will result in undefined behavior. | |||
/// </summary> | |||
/// <returns></returns> | |||
public static void reset_default_graph() | |||
{ | |||
@@ -138,8 +139,8 @@ namespace Tensorflow | |||
public static Tensor internal_convert_to_tensor_or_composite(Tensor value, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool as_ref = false) | |||
{ | |||
return internal_convert_to_tensor(value, dtype: dtype, name: name, as_ref: as_ref); | |||
} | |||
} | |||
/// <summary> | |||
/// Wrapper for `Graph.control_dependencies()` using the default graph. | |||
/// | |||
@@ -3,6 +3,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples | |||
/// Basic Operations example using TensorFlow library. | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_operations.py | |||
/// </summary> | |||
public class BasicOperations : Python, IExample | |||
public class BasicOperations : IExample | |||
{ | |||
public bool Enabled { get; set; } = true; | |||
public int Priority => 2; | |||
@@ -2,6 +2,7 @@ | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -9,7 +10,7 @@ namespace TensorFlowNET.Examples | |||
/// Simple hello world using TensorFlow | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py | |||
/// </summary> | |||
public class HelloWorld : Python, IExample | |||
public class HelloWorld : IExample | |||
{ | |||
public int Priority => 1; | |||
public bool Enabled { get; set; } = true; | |||
@@ -9,6 +9,7 @@ using System.Net; | |||
using System.Text; | |||
using Tensorflow; | |||
using System.Drawing; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -17,7 +18,7 @@ namespace TensorFlowNET.Examples | |||
/// that has been shown to attain greater than 78.1% accuracy on the ImageNet dataset. | |||
/// The model is the culmination of many ideas developed by multiple researchers over the years. | |||
/// </summary> | |||
public class ImageRecognitionInception : Python, IExample | |||
public class ImageRecognitionInception : IExample | |||
{ | |||
public int Priority => 7; | |||
public bool Enabled { get; set; } = true; | |||
@@ -10,6 +10,7 @@ using System.Text; | |||
using System.Threading; | |||
using System.Threading.Tasks; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -17,7 +18,7 @@ namespace TensorFlowNET.Examples | |||
/// Inception Architecture for Computer Vision | |||
/// Port from tensorflow\examples\label_image\label_image.py | |||
/// </summary> | |||
public class InceptionArchGoogLeNet : Python, IExample | |||
public class InceptionArchGoogLeNet : IExample | |||
{ | |||
public bool Enabled { get; set; } = false; | |||
public int Priority => 100; | |||
@@ -7,6 +7,7 @@ using System.Text; | |||
using Tensorflow; | |||
using Tensorflow.Clustering; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -15,7 +16,7 @@ namespace TensorFlowNET.Examples | |||
/// handwritten digit images. | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/kmeans.py | |||
/// </summary> | |||
public class KMeansClustering : Python, IExample | |||
public class KMeansClustering : IExample | |||
{ | |||
public int Priority => 8; | |||
public bool Enabled { get; set; } = true; | |||
@@ -3,6 +3,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples | |||
/// A linear regression learning algorithm example using TensorFlow library. | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/linear_regression.py | |||
/// </summary> | |||
public class LinearRegression : Python, IExample | |||
public class LinearRegression : IExample | |||
{ | |||
public int Priority => 3; | |||
public bool Enabled { get; set; } = true; | |||
@@ -7,6 +7,7 @@ using System.Linq; | |||
using System.Text; | |||
using Tensorflow; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -15,7 +16,7 @@ namespace TensorFlowNET.Examples | |||
/// This example is using the MNIST database of handwritten digits | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/logistic_regression.py | |||
/// </summary> | |||
public class LogisticRegression : Python, IExample | |||
public class LogisticRegression : IExample | |||
{ | |||
public int Priority => 4; | |||
public bool Enabled { get; set; } = true; | |||
@@ -4,10 +4,11 @@ using System.IO; | |||
using System.Runtime.InteropServices; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
public class MetaGraph : Python, IExample | |||
public class MetaGraph : IExample | |||
{ | |||
public int Priority => 100; | |||
public bool Enabled { get; set; } = false; | |||
@@ -4,13 +4,14 @@ using System.Text; | |||
using Tensorflow; | |||
using NumSharp; | |||
using System.Linq; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
/// <summary> | |||
/// https://github.com/nicolov/naive_bayes_tensorflow | |||
/// </summary> | |||
public class NaiveBayesClassifier : Python, IExample | |||
public class NaiveBayesClassifier : IExample | |||
{ | |||
public int Priority => 6; | |||
public bool Enabled { get; set; } = true; | |||
@@ -2,13 +2,14 @@ | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
/// <summary> | |||
/// https://github.com/guillaumegenthial/tf_ner | |||
/// </summary> | |||
public class NamedEntityRecognition : Python, IExample | |||
public class NamedEntityRecognition : IExample | |||
{ | |||
public int Priority => 100; | |||
public bool Enabled { get; set; } = false; | |||
@@ -4,6 +4,7 @@ using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -12,7 +13,7 @@ namespace TensorFlowNET.Examples | |||
/// This example is using the MNIST database of handwritten digits | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/nearest_neighbor.py | |||
/// </summary> | |||
public class NearestNeighbor : Python, IExample | |||
public class NearestNeighbor : IExample | |||
{ | |||
public int Priority => 5; | |||
public bool Enabled { get; set; } = true; | |||
@@ -4,6 +4,7 @@ using System.Text; | |||
using NumSharp; | |||
using Tensorflow; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -11,7 +12,7 @@ namespace TensorFlowNET.Examples | |||
/// Simple vanilla neural net solving the famous XOR problem | |||
/// https://github.com/amygdala/tensorflow-workshop/blob/master/workshop_sections/getting_started/xor/README.md | |||
/// </summary> | |||
public class NeuralNetXor : Python, IExample | |||
public class NeuralNetXor : IExample | |||
{ | |||
public int Priority => 10; | |||
public bool Enabled { get; set; } = true; | |||
@@ -9,11 +9,12 @@ using TensorFlowNET.Examples.Utility; | |||
using System.Drawing; | |||
using System.Drawing.Drawing2D; | |||
using System.Linq; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
public class ObjectDetection : Python, IExample | |||
public class ObjectDetection : IExample | |||
{ | |||
public int Priority => 11; | |||
public bool Enabled { get; set; } = true; | |||
@@ -6,6 +6,7 @@ using Newtonsoft.Json; | |||
using System.Linq; | |||
using System.Text.RegularExpressions; | |||
using NumSharp; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -14,7 +15,7 @@ namespace TensorFlowNET.Examples | |||
/// This is a binary—or two-class—classification, an important and widely applicable kind of machine learning problem. | |||
/// https://github.com/tensorflow/docs/blob/master/site/en/tutorials/keras/basic_text_classification.ipynb | |||
/// </summary> | |||
public class BinaryTextClassification : Python, IExample | |||
public class BinaryTextClassification : IExample | |||
{ | |||
public int Priority => 9; | |||
public bool Enabled { get; set; } = true; | |||
@@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
using System.IO; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -10,7 +11,7 @@ namespace TensorFlowNET.Examples | |||
/// Bidirectional LSTM-CRF Models for Sequence Tagging | |||
/// https://github.com/guillaumegenthial/tf_ner/tree/master/models/lstm_crf | |||
/// </summary> | |||
public class BiLstmCrfNer : Python, IExample | |||
public class BiLstmCrfNer : IExample | |||
{ | |||
public int Priority => 13; | |||
@@ -10,13 +10,14 @@ using Tensorflow.Keras.Engine; | |||
using TensorFlowNET.Examples.Text.cnn_models; | |||
using TensorFlowNET.Examples.TextClassification; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples.CnnTextClassification | |||
{ | |||
/// <summary> | |||
/// https://github.com/dongjun-Lee/text-classification-models-tf | |||
/// </summary> | |||
public class TextClassificationTrain : Python, IExample | |||
public class TextClassificationTrain : IExample | |||
{ | |||
public int Priority => 100; | |||
public bool Enabled { get; set; } = false; | |||
@@ -53,8 +54,8 @@ namespace TensorFlowNET.Examples.CnnTextClassification | |||
Console.WriteLine("Building dataset..."); | |||
var (x, y, alphabet_size) = DataHelpers.build_char_dataset("train", model_name, CHAR_MAX_LEN, DataLimit); | |||
var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); | |||
var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); | |||
var meta_file = model_name + "_untrained.meta"; | |||
tf.train.import_meta_graph(Path.Join("graph", meta_file)); | |||
@@ -92,22 +93,22 @@ namespace TensorFlowNET.Examples.CnnTextClassification | |||
var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); | |||
ITextClassificationModel model = null; | |||
switch (model_name) // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn | |||
{ | |||
case "word_cnn": | |||
case "char_cnn": | |||
case "word_rnn": | |||
case "att_rnn": | |||
case "rcnn": | |||
throw new NotImplementedException(); | |||
break; | |||
ITextClassificationModel model = null; | |||
switch (model_name) // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn | |||
{ | |||
case "word_cnn": | |||
case "char_cnn": | |||
case "word_rnn": | |||
case "att_rnn": | |||
case "rcnn": | |||
throw new NotImplementedException(); | |||
break; | |||
case "vd_cnn": | |||
model=new VdCnn(alphabet_size, CHAR_MAX_LEN, NUM_CLASS); | |||
break; | |||
} | |||
// todo train the model | |||
return false; | |||
model=new VdCnn(alphabet_size, CHAR_MAX_LEN, NUM_CLASS); | |||
break; | |||
} | |||
// todo train the model | |||
return false; | |||
} | |||
private (int[][], int[][], int[], int[]) train_test_split(int[][] x, int[] y, float test_size = 0.3f) | |||
@@ -6,6 +6,7 @@ using System.Linq; | |||
using System.Text; | |||
using Tensorflow; | |||
using TensorFlowNET.Examples.Utility; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples | |||
{ | |||
@@ -13,7 +14,7 @@ namespace TensorFlowNET.Examples | |||
/// Implement Word2Vec algorithm to compute vector representations of words. | |||
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/word2vec.py | |||
/// </summary> | |||
public class Word2Vec : Python, IExample | |||
public class Word2Vec : IExample | |||
{ | |||
public int Priority => 12; | |||
public bool Enabled { get; set; } = true; | |||
@@ -4,10 +4,11 @@ using System.Linq; | |||
using System.Text; | |||
using Tensorflow; | |||
using TensorFlowNET.Examples.Text.cnn_models; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.Examples.TextClassification | |||
{ | |||
public class VdCnn : Python, ITextClassificationModel | |||
public class VdCnn : ITextClassificationModel | |||
{ | |||
private int embedding_size; | |||
private int[] filter_sizes; | |||
@@ -3,10 +3,11 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
public class CApiTest : Python | |||
public class CApiTest | |||
{ | |||
protected TF_Code TF_OK = TF_Code.TF_OK; | |||
protected TF_DataType TF_FLOAT = TF_DataType.TF_FLOAT; | |||
@@ -6,11 +6,12 @@ using System.Linq; | |||
using System.Runtime.InteropServices; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
[TestClass] | |||
public class ConstantTest : Python | |||
public class ConstantTest | |||
{ | |||
Status status = new Status(); | |||
@@ -3,11 +3,12 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
[TestClass] | |||
public class NameScopeTest : Python | |||
public class NameScopeTest | |||
{ | |||
Graph g = ops.get_default_graph(); | |||
string name = ""; | |||
@@ -3,11 +3,12 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
[TestClass] | |||
public class PlaceholderTest : Python | |||
public class PlaceholderTest | |||
{ | |||
[TestMethod] | |||
public void placeholder() | |||
@@ -3,6 +3,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
@@ -8,13 +8,14 @@ using Newtonsoft.Json.Linq; | |||
using NumSharp; | |||
using Tensorflow; | |||
using Tensorflow.Util; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
/// <summary> | |||
/// Use as base class for test classes to get additional assertions | |||
/// </summary> | |||
public class PythonTest : Python | |||
public class PythonTest | |||
{ | |||
#region python compatibility layer | |||
protected PythonTest self { get => this; } | |||
@@ -4,6 +4,7 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
@@ -4,11 +4,12 @@ using System.Collections.Generic; | |||
using System.IO; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
[TestClass] | |||
public class TrainSaverTest : Python | |||
public class TrainSaverTest | |||
{ | |||
public void ExportGraph() | |||
{ | |||
@@ -3,11 +3,12 @@ using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest | |||
{ | |||
[TestClass] | |||
public class VariableTest : Python | |||
public class VariableTest | |||
{ | |||
[TestMethod] | |||
public void Initializer() | |||
@@ -2,6 +2,7 @@ | |||
using Newtonsoft.Json; | |||
using System; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.control_flow_ops_test | |||
{ | |||
@@ -5,6 +5,7 @@ using System.Text; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using Tensorflow; | |||
using Tensorflow.Operations; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.control_flow_ops_test | |||
{ | |||
@@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
using System.Text; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.gradients_test | |||
{ | |||
@@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; | |||
using NumSharp; | |||
using Tensorflow; | |||
using Tensorflow.Util; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.nest_test | |||
{ | |||
@@ -5,6 +5,7 @@ using System.Text; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using NumSharp; | |||
using Tensorflow; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.nn_test | |||
{ | |||
@@ -5,6 +5,7 @@ using System.Text; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using Tensorflow; | |||
using Tensorflow.Eager; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.ops_test | |||
{ | |||
@@ -5,6 +5,7 @@ using System.Text; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using Tensorflow; | |||
using Tensorflow.Operations; | |||
using static Tensorflow.Python; | |||
namespace TensorFlowNET.UnitTest.ops_test | |||
{ | |||