@@ -26,7 +26,7 @@ namespace Tensorflow | |||
string prefix = ""; | |||
var graph = ops.get_default_graph(); | |||
with(new ops.name_scope(name, "import", input_map.Values), scope => | |||
with(ops.name_scope(name, "import", input_map.Values), scope => | |||
{ | |||
prefix = scope; | |||
/*if (!string.IsNullOrEmpty(prefix)) | |||
@@ -16,8 +16,8 @@ namespace Tensorflow | |||
/// <param name="default_name">The default name to use if the name argument is None.</param> | |||
/// <param name="values">The list of Tensor arguments that are passed to the op function.</param> | |||
/// <returns>The scope name.</returns> | |||
public static ops.name_scope name_scope(string name, | |||
public static ops.NameScope name_scope(string name, | |||
string default_name = "", | |||
object values = null) => new ops.name_scope(name, default_name, values); | |||
object values = null) => new ops.NameScope(name, default_name, values); | |||
} | |||
} |
@@ -58,7 +58,7 @@ namespace Tensorflow | |||
**/ | |||
var grads = new Dictionary<string, Tensor[][]>(); | |||
with(new ops.name_scope(name, "gradients", values: all), scope => | |||
with(ops.name_scope(name, "gradients", values: all), scope => | |||
{ | |||
string grad_scope = scope; | |||
// Get a uid for this call to gradients that can be used to help | |||
@@ -131,7 +131,7 @@ namespace Tensorflow | |||
// for ops that do not have gradients. | |||
var grad_fn = ops.get_gradient_function(op); | |||
with(new ops.name_scope(op.name + "_grad"), scope1 => | |||
with(ops.name_scope(op.name + "_grad"), scope1 => | |||
{ | |||
string name1 = scope1; | |||
if (grad_fn != null) | |||
@@ -31,7 +31,7 @@ namespace Tensorflow.Keras.Engine | |||
bool build_graph = tf_utils.are_all_symbolic_tensors(input_list); | |||
// Handle Keras mask propagation from previous layer to current layer. | |||
Python.with(new ops.name_scope(_name_scope()), delegate | |||
Python.with(ops.name_scope(_name_scope()), delegate | |||
{ | |||
if (!built) | |||
{ | |||
@@ -92,7 +92,7 @@ namespace Tensorflow.Layers | |||
auxiliary_name_scope: false), scope => | |||
{ | |||
_current_scope = scope; | |||
Python.with(new ops.name_scope(_name_scope()), delegate | |||
Python.with(ops.name_scope(_name_scope()), delegate | |||
{ | |||
@@ -33,7 +33,7 @@ namespace Tensorflow | |||
parameters.Add("validate_args", validate_args); | |||
parameters.Add("allow_nan_stats", allow_nan_stats); | |||
with(new ops.name_scope(name, "", new { loc, scale }), scope => | |||
with(ops.name_scope(name, "", new { loc, scale }), scope => | |||
{ | |||
with(ops.control_dependencies(validate_args ? new Operation[] { scale.op} : new Operation[] { }), cd => | |||
{ | |||
@@ -12,7 +12,7 @@ namespace Tensorflow | |||
string scope = "", | |||
string loss_collection= "losses") | |||
{ | |||
with(new ops.name_scope(scope, | |||
with(ops.name_scope(scope, | |||
"sparse_softmax_cross_entropy_loss", | |||
(logits, labels, weights)), | |||
namescope => | |||
@@ -44,7 +44,7 @@ namespace Tensorflow | |||
var input_types = new List<TF_DataType>(); | |||
dynamic values = null; | |||
return with(new ops.name_scope(name), scope => | |||
return with(ops.name_scope(name), scope => | |||
{ | |||
var inferred_from = new Dictionary<string, object>(); | |||
var base_types = new List<TF_DataType>(); | |||
@@ -12,7 +12,7 @@ namespace Tensorflow | |||
public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||
{ | |||
dtype = dtype.as_base_dtype(); | |||
return with(new ops.name_scope(name, "zeros", shape), scope => | |||
return with(ops.name_scope(name, "zeros", shape), scope => | |||
{ | |||
name = scope; | |||
switch (dtype) | |||
@@ -68,7 +68,7 @@ namespace Tensorflow | |||
private static Tensor ones_like_impl<T>(T tensor, TF_DataType dtype, string name, bool optimize = true) | |||
{ | |||
return with(new ops.name_scope(name, "ones_like", new { tensor }), scope => | |||
return with(ops.name_scope(name, "ones_like", new { tensor }), scope => | |||
{ | |||
name = scope; | |||
var tensor1 = ops.convert_to_tensor(tensor, name: "tensor"); | |||
@@ -84,7 +84,7 @@ namespace Tensorflow | |||
public static Tensor ones(Tensor shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||
{ | |||
dtype = dtype.as_base_dtype(); | |||
return with(new ops.name_scope(name, "ones", new { shape }), scope => | |||
return with(ops.name_scope(name, "ones", new { shape }), scope => | |||
{ | |||
name = scope; | |||
var output = gen_array_ops.fill(shape, constant_op.constant(1.0f, dtype: dtype), name: name); | |||
@@ -130,7 +130,7 @@ namespace Tensorflow | |||
private static Tensor shape_internal(Tensor input, string name = null, bool optimize = true, TF_DataType out_type = TF_DataType.TF_INT32) | |||
{ | |||
return with(new ops.name_scope(name, "Shape", new { input }), scope => | |||
return with(ops.name_scope(name, "Shape", new { input }), scope => | |||
{ | |||
name = scope; | |||
@@ -151,7 +151,7 @@ namespace Tensorflow | |||
private static Tensor size_internal(Tensor input, string name = null, bool optimize = true, TF_DataType out_type = TF_DataType.TF_INT32) | |||
{ | |||
return with(new ops.name_scope(name, "Size", new Tensor[] { input }), scope => | |||
return with(ops.name_scope(name, "Size", new Tensor[] { input }), scope => | |||
{ | |||
name = scope; | |||
@@ -182,7 +182,7 @@ namespace Tensorflow | |||
public static Tensor zeros_like(Tensor tensor, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool optimize = true) | |||
{ | |||
return with(new ops.name_scope(name, "zeros_like", new Tensor[] { tensor }), scope => | |||
return with(ops.name_scope(name, "zeros_like", new Tensor[] { tensor }), scope => | |||
{ | |||
name = scope; | |||
tensor = ops.convert_to_tensor(tensor, name: "tensor"); | |||
@@ -9,7 +9,7 @@ namespace Tensorflow | |||
{ | |||
public static Operation group<T>(T[] inputs, string name = null) where T : ITensorOrOperation | |||
{ | |||
return with(new ops.name_scope(name, "group_deps", inputs), scope => | |||
return with(ops.name_scope(name, "group_deps", inputs), scope => | |||
{ | |||
name = scope; | |||
@@ -83,7 +83,7 @@ namespace Tensorflow | |||
public static Tensor[] tuple(Tensor[] tensors, string name = null, Operation[] control_inputs = null) | |||
{ | |||
return with(new ops.name_scope(name, "tuple", tensors), scope => | |||
return with(ops.name_scope(name, "tuple", tensors), scope => | |||
{ | |||
name = scope; | |||
var gating_ops = tensors.Select(x => x.op).ToList(); | |||
@@ -115,7 +115,7 @@ namespace Tensorflow | |||
values.AddRange(dependencies); | |||
values.Add(output_tensor); | |||
return with(new ops.name_scope(name, "control_dependency", values), scope => | |||
return with(ops.name_scope(name, "control_dependency", values), scope => | |||
{ | |||
name = scope; | |||
@@ -20,7 +20,7 @@ namespace Tensorflow | |||
string name = null, | |||
string max_norm = null) | |||
{ | |||
return with(new ops.name_scope(name, "embedding_lookup", new { @params, ids }), scope => | |||
return with(ops.name_scope(name, "embedding_lookup", new { @params, ids }), scope => | |||
{ | |||
name = scope; | |||
int np = 1; | |||
@@ -15,7 +15,7 @@ namespace Tensorflow | |||
if(base_type == x.dtype) | |||
return x; | |||
return with(new ops.name_scope(name, "Cast", new { x }), scope => | |||
return with(ops.name_scope(name, "Cast", new { x }), scope => | |||
{ | |||
x = ops.convert_to_tensor(x, name: "x"); | |||
if (x.dtype.as_base_dtype() != base_type) | |||
@@ -166,7 +166,7 @@ namespace Tensorflow | |||
if (delta == null) | |||
delta = 1; | |||
return with(new ops.name_scope(name, "Range", new object[] { start, limit, delta }), scope => | |||
return with(ops.name_scope(name, "Range", new object[] { start, limit, delta }), scope => | |||
{ | |||
name = scope; | |||
var start1 = ops.convert_to_tensor(start, name: "start"); | |||
@@ -179,7 +179,7 @@ namespace Tensorflow | |||
public static Tensor floordiv(Tensor x, Tensor y, string name = null) | |||
{ | |||
return with(new ops.name_scope(name, "floordiv", new { x, y }), scope => | |||
return with(ops.name_scope(name, "floordiv", new { x, y }), scope => | |||
{ | |||
return gen_math_ops.floor_div(x, y, scope); | |||
}); | |||
@@ -187,7 +187,7 @@ namespace Tensorflow | |||
public static Tensor rank_internal(Tensor input, string name = null, bool optimize = true) | |||
{ | |||
return with(new ops.name_scope(name, "Rank", new List<Tensor> { input }), scope => | |||
return with(ops.name_scope(name, "Rank", new List<Tensor> { input }), scope => | |||
{ | |||
name = scope; | |||
var input_tensor = ops.convert_to_tensor(input); | |||
@@ -207,7 +207,7 @@ namespace Tensorflow | |||
{ | |||
Tensor result = null; | |||
with(new ops.name_scope(name, "MatMul", new Tensor[] { a, b }), scope => | |||
with(ops.name_scope(name, "MatMul", new Tensor[] { a, b }), scope => | |||
{ | |||
name = scope; | |||
@@ -237,7 +237,7 @@ namespace Tensorflow | |||
if (dt.is_floating() || dt.is_integer()) | |||
return x; | |||
return with(new ops.name_scope(name, "Conj", new List<Tensor> { x }), scope => | |||
return with(ops.name_scope(name, "Conj", new List<Tensor> { x }), scope => | |||
{ | |||
return x; | |||
@@ -19,7 +19,7 @@ namespace Tensorflow | |||
string name = null, | |||
bool keep_dims = false) | |||
{ | |||
return with<ops.name_scope, (Tensor, Tensor)>(new ops.name_scope(name, "moments", new { x, axes }), scope => | |||
return with(ops.name_scope(name, "moments", new { x, axes }), scope => | |||
{ | |||
// The dynamic range of fp16 is too limited to support the collection of | |||
// sufficient statistics. As a workaround we simply perform the operations | |||
@@ -23,7 +23,7 @@ namespace Tensorflow | |||
int? seed = null, | |||
string name = null) | |||
{ | |||
return with(new ops.name_scope(name, "random_normal", new { shape, mean, stddev }), scope => | |||
return with(ops.name_scope(name, "random_normal", new { shape, mean, stddev }), scope => | |||
{ | |||
var shape_tensor = _ShapeTensor(shape); | |||
var mean_tensor = ops.convert_to_tensor(mean, dtype: dtype, name: "mean"); | |||
@@ -53,7 +53,7 @@ namespace Tensorflow | |||
int? seed = null, | |||
string name = null) | |||
{ | |||
return with(new ops.name_scope(name, "random_uniform", new { shape, minval, maxval }), scope => | |||
return with(ops.name_scope(name, "random_uniform", new { shape, minval, maxval }), scope => | |||
{ | |||
name = scope; | |||
var tensorShape = _ShapeTensor(shape); | |||
@@ -41,7 +41,7 @@ namespace Tensorflow | |||
if( y is Tensor tr) | |||
dtype = tr.dtype.as_base_dtype(); | |||
var namescope = new ops.name_scope(null, name, new { x, y }); | |||
var namescope = ops.name_scope(null, name, new { x, y }); | |||
return with(namescope, scope => | |||
{ | |||
Tensor result = null; | |||
@@ -87,7 +87,7 @@ namespace Tensorflow | |||
_create_slots(var_list); | |||
var update_ops = new List<Operation>(); | |||
return with(new ops.name_scope(name, Name), scope => | |||
return with(ops.name_scope(name, Name), scope => | |||
{ | |||
name = scope; | |||
_prepare(); | |||
@@ -98,7 +98,7 @@ namespace Tensorflow | |||
continue; | |||
var scope_name = var.op.name; | |||
with(new ops.name_scope("update_" + scope_name), scope2 => | |||
with(ops.name_scope("update_" + scope_name), scope2 => | |||
{ | |||
update_ops.Add(processor.update_op(this, grad)); | |||
}); | |||
@@ -79,7 +79,7 @@ namespace Tensorflow | |||
Tensor save_tensor = null; | |||
Operation restore_op = null; | |||
return with(new ops.name_scope(name, "save", saveables.Select(x => x.op).ToArray()), scope => | |||
return with(ops.name_scope(name, "save", saveables.Select(x => x.op).ToArray()), scope => | |||
{ | |||
name = scope; | |||
@@ -17,7 +17,7 @@ namespace Tensorflow | |||
private static Tensor op_helper<T>(string default_name, RefVariable x, T y) | |||
{ | |||
var tensor1 = x.value(); | |||
return with(new ops.name_scope(null, default_name, new { tensor1, y }), scope => { | |||
return with(ops.name_scope(null, default_name, new { tensor1, y }), scope => { | |||
var tensor2 = ops.convert_to_tensor(y, tensor1.dtype.as_base_dtype(), "y"); | |||
return gen_math_ops.add(tensor1, tensor2, scope); | |||
}); | |||
@@ -118,7 +118,7 @@ namespace Tensorflow | |||
ops.init_scope(); | |||
var values = init_from_fn ? new object[0] : new object[] { initial_value }; | |||
with(new ops.name_scope(name, "Variable", values), scope => | |||
with(ops.name_scope(name, "Variable", values), scope => | |||
{ | |||
name = scope; | |||
if (init_from_fn) | |||
@@ -132,7 +132,7 @@ namespace Tensorflow | |||
List = new AttrValue.Types.ListValue() | |||
}; | |||
attr.List.S.Add(ByteString.CopyFromUtf8($"loc:{true_name}")); | |||
with(new ops.name_scope("Initializer"), scope2 => | |||
with(ops.name_scope("Initializer"), scope2 => | |||
{ | |||
_initial_value = (initial_value as Func<Tensor>)(); | |||
_initial_value = ops.convert_to_tensor(_initial_value, name: "initial_value", dtype: dtype); | |||
@@ -39,7 +39,7 @@ namespace Tensorflow | |||
VariableAggregation aggregation= VariableAggregation.NONE) | |||
{ | |||
string full_name = !string.IsNullOrEmpty(this._name) ? this._name + "/" + name : name; | |||
return with(new ops.name_scope(null), scope => | |||
return with(ops.name_scope(null), scope => | |||
{ | |||
if (dtype == TF_DataType.DtInvalid) | |||
dtype = _dtype; | |||
@@ -20,7 +20,7 @@ namespace Tensorflow | |||
private VariableScope _scope; | |||
private string _default_name; | |||
private object _values; | |||
private ops.name_scope _current_name_scope; | |||
private ops.NameScope _current_name_scope; | |||
private bool _auxiliary_name_scope; | |||
private PureVariableScope _cached_pure_variable_scope; | |||
private bool? _reuse; | |||
@@ -68,7 +68,7 @@ namespace Tensorflow | |||
private VariableScope _enter_scope_uncached() | |||
{ | |||
ops.name_scope current_name_scope; | |||
ops.NameScope current_name_scope; | |||
PureVariableScope pure_variable_scope = null; | |||
VariableScope entered_pure_variable_scope; | |||
@@ -82,14 +82,14 @@ namespace Tensorflow | |||
if(!string.IsNullOrEmpty(name_scope)) | |||
// Hack to reenter | |||
name_scope += "/"; | |||
current_name_scope = new ops.name_scope(name_scope); | |||
current_name_scope = ops.name_scope(name_scope); | |||
} | |||
if (_name != null || _scope != null) | |||
{ | |||
var name_scope = _name == null ? _scope._name.Split('/').Last() : _name; | |||
if (name_scope != null || current_name_scope != null) | |||
current_name_scope = new ops.name_scope(name_scope); | |||
current_name_scope = ops.name_scope(name_scope); | |||
current_name_scope.__enter__(); | |||
var current_name_scope_name = current_name_scope; | |||
_current_name_scope = current_name_scope; | |||
@@ -106,7 +106,7 @@ namespace Tensorflow | |||
} | |||
else | |||
{ | |||
current_name_scope = new ops.name_scope(_default_name); | |||
current_name_scope = ops.name_scope(_default_name); | |||
current_name_scope.__enter__(); | |||
string current_name_scope_name = current_name_scope; | |||
_current_name_scope = current_name_scope; | |||
@@ -7,10 +7,14 @@ namespace Tensorflow | |||
{ | |||
public partial class ops | |||
{ | |||
public static NameScope name_scope(string name, | |||
string default_name = "", | |||
object values = null) => new NameScope(name, default_name, values); | |||
/// <summary> | |||
/// Returns a context manager that creates hierarchical names for operations. | |||
/// </summary> | |||
public class name_scope : IPython | |||
public class NameScope : IPython | |||
{ | |||
public string _name; | |||
public string _default_name; | |||
@@ -20,7 +24,7 @@ namespace Tensorflow | |||
public string old_stack = ""; | |||
private object _g_manager; | |||
public name_scope(string name, string default_name = "", object values = null) | |||
public NameScope(string name, string default_name = "", object values = null) | |||
{ | |||
_name = name; | |||
_default_name = default_name; | |||
@@ -58,7 +62,7 @@ namespace Tensorflow | |||
/// __enter__() | |||
/// </summary> | |||
/// <param name="ns"></param> | |||
public static implicit operator string(name_scope ns) | |||
public static implicit operator string(NameScope ns) | |||
{ | |||
return ns._name_scope; | |||
} | |||
@@ -15,7 +15,7 @@ namespace TensorFlowNET.UnitTest | |||
[TestMethod] | |||
public void NestedNameScope() | |||
{ | |||
with(new ops.name_scope("scope1"), scope1 => | |||
with(new ops.NameScope("scope1"), scope1 => | |||
{ | |||
name = scope1; | |||
Assert.AreEqual("scope1", g._name_stack); | |||
@@ -24,7 +24,7 @@ namespace TensorFlowNET.UnitTest | |||
var const1 = tf.constant(1.0); | |||
Assert.AreEqual("scope1/Const:0", const1.name); | |||
with(new ops.name_scope("scope2"), scope2 => | |||
with(new ops.NameScope("scope2"), scope2 => | |||
{ | |||
name = scope2; | |||
Assert.AreEqual("scope1/scope2", g._name_stack); | |||