forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathops.name_scope.cs
More file actions
76 lines (64 loc) · 2.14 KB
/
ops.name_scope.cs
File metadata and controls
76 lines (64 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tensorflow.Eager;
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 NameScope : IPython
{
public string _name;
public string _default_name;
public object _values;
public Context _ctx;
public string _name_scope;
public string old_stack = "";
private object _g_manager;
public NameScope(string name, string default_name = "", object values = null)
{
_name = name;
_default_name = default_name;
_values = values;
// _ctx = new Context();
}
public void __enter__()
{
_name = _name == null ? _default_name : _name;
Graph g = null;
if (_values is List<Tensor> vList)
g = _get_graph_from_inputs(vList.ToArray());
else if (_values is Tensor[] vArray)
g = _get_graph_from_inputs(vArray);
if (g == null)
g = get_default_graph();
old_stack = g._name_stack;
_name_scope = g.name_scope(_name);
}
public void Dispose()
{
var g = get_default_graph();
g._name_stack = old_stack;
// Console.WriteLine($"name_scope: {g._name_stack} -> {old_stack}");
}
public void __exit__()
{
}
/// <summary>
/// __enter__()
/// </summary>
/// <param name="ns"></param>
public static implicit operator string(NameScope ns)
{
return ns._name_scope;
}
}
}
}