Repository navigation
Expand file tree
/
Copy pathVariableScope.cs
More file actions
60 lines (55 loc) · 1.96 KB
/
Copy pathVariableScope.cs
File metadata and controls
60 lines (55 loc) · 1.96 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
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
{
public bool use_resource { get; set; }
private _ReuseMode _reuse;
public bool resue;
private TF_DataType _dtype;
string _name;
public string name => _name;
public string _name_scope { get; set; }
public string original_name_scope => _name_scope;
public VariableScope(bool reuse,
string name = "",
string name_scope = "",
TF_DataType dtype = TF_DataType.TF_FLOAT)
{
_name = name;
_name_scope = name_scope;
_reuse = _ReuseMode.AUTO_REUSE;
_dtype = dtype;
}
public RefVariable get_variable(_VariableStore var_store,
string name,
TensorShape shape = null,
TF_DataType dtype = TF_DataType.DtInvalid,
object initializer = null, // IInitializer or Tensor
bool? trainable = null,
VariableSynchronization synchronization = VariableSynchronization.Auto,
VariableAggregation aggregation= VariableAggregation.None)
{
string full_name = !string.IsNullOrEmpty(this._name) ? this._name + "/" + name : name;
return with(ops.name_scope(null), scope =>
{
if (dtype == TF_DataType.DtInvalid)
dtype = _dtype;
return var_store.get_variable(full_name,
shape: shape,
dtype: dtype,
initializer: initializer,
reuse: resue,
trainable: trainable,
synchronization: synchronization,
aggregation: aggregation);
});
}
}
}