Skip to content

Commit

Permalink
Add ability to load ops when loading a Graph
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilk committed Jan 10, 2018
1 parent 95bc4b7 commit 5b2a165
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions samples/graphs/matrix/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const tf = require('tensorflow');

let session = tf.Session.fromGraphDef('./graph.proto', true);
session.graph.loadOperations({ result: 'computation/result' });
let session = tf.Session.fromGraphDef('./graph.proto', { result: 'computation/result' });

let outputs = session.run(null, ['result'], null);
console.log(outputs.result.toValue());
Expand Down
10 changes: 8 additions & 2 deletions src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ class Graph extends api.Reference {
return unresolvedOps;
}

static fromGraphDef(graphDefPath) {
static fromGraphDef(graphDefPath, operations) {
let protobuf = fs.readFileSync(graphDefPath);
return loadGraph(protobuf);
let graph = loadGraph(protobuf);

if (operations) {
graph.loadOperations(operations);
}

return graph;
}

// TODO: Implement loading a Graph from an in-memory JSON object representatio of a GraphDef.
Expand Down

0 comments on commit 5b2a165

Please sign in to comment.