Skip to content

Commit 316a0eb

Browse files
committed
Update samples for new API
1 parent d842e3e commit 316a0eb

File tree

10 files changed

+53
-69
lines changed

10 files changed

+53
-69
lines changed

samples/graphs/basic/main.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ const tf = require('tensorflow');
22

33
console.log('Tensor Test');
44

5-
var tensor = tf.Tensor.create([0.5, 42.0]);
5+
var tensor = tf.tensor([0.5, 42.0]);
66
console.log(tensor.shape);
7-
let data = tensor.toValue();
8-
console.log(data);
9-
tensor.delete();
7+
console.log(tensor.value);
108

119
let items =
1210
[
@@ -18,25 +16,16 @@ let items =
1816
[5,6], [7,8]
1917
]
2018
]
21-
var tensor2 = tf.Tensor.create(items);
19+
var tensor2 = tf.tensor(items);
2220
console.log(tensor2.shape);
23-
let data2 = tensor2.toValue();
24-
console.log(data2);
21+
console.log(tensor2.value);
2522

2623

2724
console.log('Graph Test');
2825

29-
let graph = tf.Graph.fromGraphDef('./graph.proto')
30-
graph.loadOperations({c1: 'c1', c2: 'c2', result: 'result'});
31-
console.log(graph);
32-
graph.delete();
33-
26+
let graph = tf.graph('./graph.proto');
27+
let session = graph.createSession();
28+
let result = session.run(null, 'result');
29+
console.log(result);
3430

35-
console.log('Session Test');
36-
37-
let session = tf.Session.fromGraphDef('./graph.proto', true);
38-
session.graph.loadOperations({ result: 'result' });
39-
let tensors = session.run(null, ['result'], null);
40-
console.log(tensors.result.toValue());
41-
tensors.result.delete();
42-
session.delete();
31+
graph.delete();

samples/graphs/basic/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"tensorflow": "^0.6.5"
3+
"tensorflow": "^0.7.0"
44
},
55
"scripts": {
66
"presample": "python graph.py",

samples/graphs/json/main.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ var graphDef = {
5757
node: [ const1, const2, add ]
5858
}
5959

60-
let session = tf.Session.fromGraphDef(graphDef, { sum: 'sum' });
60+
let graph = tf.graph(graphDef);
61+
let session = graph.createSession();
62+
6163
let results = session.run(null, ['sum'], null);
6264

63-
console.log(results.sum.toValue());
64-
results.sum.delete();
65-
session.delete();
65+
console.log(results.sum.value);
66+
67+
graph.delete();

samples/graphs/json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"tensorflow": "^0.6.5"
3+
"tensorflow": "^0.7.0"
44
},
55
"scripts": {
66
"sample": "node main.js"

samples/graphs/matrix/graph.proto

-45 Bytes
Binary file not shown.

samples/graphs/matrix/graph.proto.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565
}
6666
},
67-
"name": "Variable/initial_value",
67+
"name": "var3/initial_value",
6868
"op": "Const"
6969
},
7070
{
@@ -84,20 +84,20 @@
8484
]
8585
}
8686
},
87-
"shared_name": {
87+
"container": {
8888
"s": ""
8989
},
90-
"container": {
90+
"shared_name": {
9191
"s": ""
9292
}
9393
},
94-
"name": "Variable",
94+
"name": "var3",
9595
"op": "VariableV2"
9696
},
9797
{
9898
"input": [
99-
"Variable",
100-
"Variable/initial_value"
99+
"var3",
100+
"var3/initial_value"
101101
],
102102
"attr": {
103103
"validate_shape": {
@@ -106,7 +106,7 @@
106106
"_class": {
107107
"list": {
108108
"s": [
109-
"bG9jOkBWYXJpYWJsZQ=="
109+
"bG9jOkB2YXIz"
110110
]
111111
}
112112
},
@@ -117,31 +117,31 @@
117117
"type": "DT_INT32"
118118
}
119119
},
120-
"name": "Variable/Assign",
120+
"name": "var3/Assign",
121121
"op": "Assign"
122122
},
123123
{
124124
"input": [
125-
"Variable"
125+
"var3"
126126
],
127127
"attr": {
128128
"_class": {
129129
"list": {
130130
"s": [
131-
"bG9jOkBWYXJpYWJsZQ=="
131+
"bG9jOkB2YXIz"
132132
]
133133
}
134134
},
135135
"T": {
136136
"type": "DT_INT32"
137137
}
138138
},
139-
"name": "Variable/read",
139+
"name": "var3/read",
140140
"op": "Identity"
141141
},
142142
{
143143
"input": [
144-
"^Variable/Assign"
144+
"^var3/Assign"
145145
],
146146
"name": "init",
147147
"op": "NoOp"
@@ -168,7 +168,7 @@
168168
{
169169
"input": [
170170
"computation/MatMul",
171-
"Variable/read"
171+
"var3/read"
172172
],
173173
"attr": {
174174
"T": {

samples/graphs/matrix/graph.proto.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ node {
4545
}
4646
}
4747
node {
48-
name: "Variable/initial_value"
48+
name: "var3/initial_value"
4949
op: "Const"
5050
attr {
5151
key: "dtype"
@@ -72,7 +72,7 @@ node {
7272
}
7373
}
7474
node {
75-
name: "Variable"
75+
name: "var3"
7676
op: "VariableV2"
7777
attr {
7878
key: "container"
@@ -107,10 +107,10 @@ node {
107107
}
108108
}
109109
node {
110-
name: "Variable/Assign"
110+
name: "var3/Assign"
111111
op: "Assign"
112-
input: "Variable"
113-
input: "Variable/initial_value"
112+
input: "var3"
113+
input: "var3/initial_value"
114114
attr {
115115
key: "T"
116116
value {
@@ -121,7 +121,7 @@ node {
121121
key: "_class"
122122
value {
123123
list {
124-
s: "loc:@Variable"
124+
s: "loc:@var3"
125125
}
126126
}
127127
}
@@ -139,9 +139,9 @@ node {
139139
}
140140
}
141141
node {
142-
name: "Variable/read"
142+
name: "var3/read"
143143
op: "Identity"
144-
input: "Variable"
144+
input: "var3"
145145
attr {
146146
key: "T"
147147
value {
@@ -152,15 +152,15 @@ node {
152152
key: "_class"
153153
value {
154154
list {
155-
s: "loc:@Variable"
155+
s: "loc:@var3"
156156
}
157157
}
158158
}
159159
}
160160
node {
161161
name: "init"
162162
op: "NoOp"
163-
input: "^Variable/Assign"
163+
input: "^var3/Assign"
164164
}
165165
node {
166166
name: "computation/MatMul"
@@ -190,7 +190,7 @@ node {
190190
name: "computation/result"
191191
op: "Add"
192192
input: "computation/MatMul"
193-
input: "Variable/read"
193+
input: "var3/read"
194194
attr {
195195
key: "T"
196196
value {

samples/graphs/matrix/graph.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def build_graph():
2323
with tf.Graph().as_default() as graph:
2424
var1 = tf.placeholder(dtype=tf.int32, shape=[2,2], name='var1')
2525
var2 = tf.placeholder(dtype=tf.int32, shape=[2,1], name='var2')
26-
var3 = tf.Variable(initial_value=[[1],[1]], dtype=tf.int32)
26+
var3 = tf.Variable(initial_value=[[1],[1]], dtype=tf.int32, name='var3')
2727

28-
init = tf.variables_initializer(tf.global_variables(), name='init')
28+
tf.variables_initializer(tf.global_variables(), name='init')
2929

3030
with tf.name_scope('computation'):
31-
result = tf.add(tf.matmul(var1, var2), var3, name='result')
31+
tf.add(tf.matmul(var1, var2), var3, name='result')
3232

3333
return graph
3434

samples/graphs/matrix/main.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
const tf = require('tensorflow');
22

3-
let session = tf.Session.fromGraphDef('./graph.proto',
4-
{
5-
init: 'init',
6-
var1: 'var1',
7-
var2: 'var2',
8-
result: 'computation/result'
9-
});
3+
let graph = tf.graph('./graph.proto');
4+
let session = graph.createSession();
105

116
session.run(null, null, 'init');
127

13-
let a = tf.Tensor.create([[2,2],[4,4]], tf.Types.int32);
14-
let b = tf.Tensor.create([[3],[5]], tf.Types.int32);
15-
let result = session.run({ var1: a, var2: b }, 'result');
16-
console.log(result.toValue());
8+
let a = tf.tensor([[2,2],[4,4]], tf.Types.int32);
9+
let b = tf.tensor([[3],[5]], tf.Types.int32);
1710

18-
a.delete();
19-
b.delete();
20-
result.delete();
11+
let outputs = session.run({ var1: a, var2: b }, ['var3', 'computation/result']);
12+
console.log(outputs.var3.value)
13+
console.log(outputs['computation/result'].value);
2114

22-
session.delete();
15+
graph.delete();

samples/graphs/matrix/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"tensorflow": "^0.6.5"
3+
"tensorflow": "^0.7.0"
44
},
55
"scripts": {
66
"presample": "python graph.py",

0 commit comments

Comments
 (0)