forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.py.cs
More file actions
76 lines (67 loc) · 2.8 KB
/
variables.py.cs
File metadata and controls
76 lines (67 loc) · 2.8 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;
namespace Tensorflow
{
public class variables
{
/// <summary>
/// Returns all variables created with `trainable=True`
/// </summary>
/// <returns></returns>
public static object trainable_variables()
{
return ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES);
}
/// <summary>
/// Returns all variables and `SaveableObject`s that must be checkpointed.
/// </summary>
/// <param name="scope"></param>
/// <returns></returns>
public static VariableV1[] _all_saveable_objects(string scope = "")
{
var all = new List<VariableV1>();
var collection = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope);
if(collection != null)
all.AddRange(collection as List<VariableV1>);
collection = ops.get_collection(ops.GraphKeys.SAVEABLE_OBJECTS, scope);
if (collection != null)
all.AddRange(collection as List<VariableV1>);
return all.ToArray();
}
/// <summary>
/// Returns global variables.
/// </summary>
/// <param name="scope">
/// (Optional.) A string. If supplied, the resulting list is filtered
/// to include only items whose `name` attribute matches `scope` using
/// `re.match`. Items without a `name` attribute are never returned if a
/// scope is supplied. The choice of `re.match` means that a `scope` without
/// special tokens filters by prefix.
/// </param>
/// <returns>A list of `Variable` objects.</returns>
public static List<VariableV1> global_variables(string scope = null)
{
var result = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope);
return result == null ? new List<VariableV1>() : result as List<VariableV1>;
}
/// <summary>
/// Returns an Op that initializes a list of variables.
/// </summary>
/// <param name="var_list">List of `Variable` objects to initialize.</param>
/// <param name="name">Optional name for the returned operation.</param>
/// <returns>An Op that run the initializers of all the specified variables.</returns>
public static Operation variables_initializer(VariableV1[] var_list, string name = "init")
{
if (var_list.Length > 0)
return control_flow_ops.group(var_list.Select(x => x.initializer).ToArray(), name);
else
return gen_control_flow_ops.no_op(name: name);
}
public static Tensor global_variables_initializer()
{
throw new NotImplementedException();
}
}
}