FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/test/TensorFlowNET.UnitTest/TrainSaverTest.cs at master · irripro/TensorFlow.NET · GitHub
irripro
/
TensorFlow.NET
Public
forked from
SciSharp/TensorFlow.NET
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.UnitTest
/
TrainSaverTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (84 loc) · 3.27 KB
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.UnitTest
/
TrainSaverTest.cs
Copy path
File metadata and controls
103 lines (84 loc) · 3.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using
Microsoft
.
VisualStudio
.
TestTools
.
UnitTesting
;
using
System
;
using
Tensorflow
;
using
static
Tensorflow
.
Binding
;
namespace
TensorFlowNET
.
UnitTest
{
[
TestClass
]
public
class
TrainSaverTest
{
public
void
ExportGraph
(
)
{
var
v
=
tf
.
Variable
(
0
,
name
:
"my_variable"
)
;
var
sess
=
tf
.
Session
(
)
;
tf
.
train
.
write_graph
(
sess
.
graph
,
"/tmp/my-model"
,
"train1.pbtxt"
)
;
}
public
void
ImportGraph
(
)
{
using
(
var
sess
=
tf
.
Session
(
)
)
{
var
new_saver
=
tf
.
train
.
import_meta_graph
(
"C:/tmp/my-model.meta"
)
;
}
//tf.train.export_meta_graph(filename: "linear_regression.meta.bin");
// import meta
/*tf.train.import_meta_graph("linear_regression.meta.bin");
var cost = graph.OperationByName("truediv").output;
var pred = graph.OperationByName("Add").output;
var optimizer = graph.OperationByName("GradientDescent");
var X = graph.OperationByName("Placeholder").output;
var Y = graph.OperationByName("Placeholder_1").output;
var W = graph.OperationByName("weight").output;
var b = graph.OperationByName("bias").output;*/
/*var text = JsonConvert.SerializeObject(graph, new JsonSerializerSettings
{
Formatting = Formatting.Indented
});*/
}
public
void
ImportSavedModel
(
)
{
tf_with
(
Session
.
LoadFromSavedModel
(
"mobilenet"
)
,
sess
=>
{
}
)
;
}
public
void
ImportGraphDefFromPbFile
(
)
{
var
g
=
new
Graph
(
)
;
var
status
=
g
.
Import
(
"mobilenet/saved_model.pb"
)
;
}
public
void
Save1
(
)
{
var
w1
=
tf
.
Variable
(
0
,
name
:
"save1"
)
;
var
init_op
=
tf
.
global_variables_initializer
(
)
;
// Add ops to save and restore all the variables.
var
saver
=
tf
.
train
.
Saver
(
)
;
using
(
var
sess
=
tf
.
Session
(
)
)
{
sess
.
run
(
init_op
)
;
// Save the variables to disk.
var
save_path
=
saver
.
save
(
sess
,
"/tmp/model1.ckpt"
)
;
Console
.
WriteLine
(
$
"Model saved in path:
{
save_path
}
"
)
;
}
}
public
void
Save2
(
)
{
var
v1
=
tf
.
get_variable
(
"v1"
,
shape
:
new
TensorShape
(
3
)
,
initializer
:
tf
.
zeros_initializer
)
;
var
v2
=
tf
.
get_variable
(
"v2"
,
shape
:
new
TensorShape
(
5
)
,
initializer
:
tf
.
zeros_initializer
)
;
var
inc_v1
=
v1
.
assign
(
v1
+
1.0f
)
;
var
dec_v2
=
v2
.
assign
(
v2
-
1.0f
)
;
// Add an op to initialize the variables.
var
init_op
=
tf
.
global_variables_initializer
(
)
;
// Add ops to save and restore all the variables.
var
saver
=
tf
.
train
.
Saver
(
)
;
using
(
var
sess
=
tf
.
Session
(
)
)
{
sess
.
run
(
init_op
)
;
// o some work with the model.
inc_v1
.
op
.
run
(
)
;
dec_v2
.
op
.
run
(
)
;
// Save the variables to disk.
var
save_path
=
saver
.
save
(
sess
,
"/tmp/model2.ckpt"
)
;
Console
.
WriteLine
(
$
"Model saved in path:
{
save_path
}
"
)
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL