-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
557b427
commit 11b3f6b
Showing
13 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ download/ | |
*.pb | ||
*.dll | ||
*.lib | ||
tmp.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env dub | ||
/+ dub.json: | ||
{ | ||
"dependencies": { | ||
"tfd": {"path": "../.."} | ||
} | ||
} | ||
+/ | ||
import tfd : newGraph; | ||
|
||
void main() | ||
{ | ||
with (newGraph) { | ||
auto a = placeholder!int("a"); | ||
auto b = constant(3, "b"); | ||
// TODO(karita): provide name "add" by identity | ||
auto add = a + b; | ||
write("add-d.bin"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import tensorflow.compat.v1 as tf | ||
|
||
with tf.Session() as sess: | ||
a = tf.placeholder(tf.int32, (), "a") | ||
b = tf.constant(3) | ||
c = tf.identity(a + b, "add") | ||
tf.io.write_graph(sess.graph_def, ".", "add-py.bin", as_text=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env dub | ||
/+ dub.json: | ||
{ | ||
"dependencies": { | ||
"tfd": {"path": "../.."} | ||
} | ||
} | ||
+/ | ||
import std.stdio : writeln; | ||
import std.file : read; | ||
import tfd : newGraph, tensor; | ||
|
||
void main() | ||
{ | ||
with (newGraph) { | ||
// TODO(karita): pbtxt support. | ||
load(read("add-py.bin")); | ||
auto a = operationByName("a"); | ||
auto add = operationByName("add"); | ||
|
||
const t = session.run([add], [a: 1.tensor])[0].tensor; | ||
assert(t.scalar!int == 1 + 3); | ||
writeln(t.scalar!int); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import tensorflow.compat.v1 as tf | ||
|
||
with tf.Session() as sess: | ||
with open("add-d.bin", "rb") as f: | ||
graph_def = tf.GraphDef() | ||
graph_def.ParseFromString(f.read()) | ||
|
||
tf.import_graph_def(graph_def) | ||
graph = tf.get_default_graph() | ||
for op in graph.get_operations(): | ||
print(op.name) | ||
|
||
a = graph.get_tensor_by_name("import/a:0") | ||
add = graph.get_tensor_by_name("import/add:0") | ||
result = sess.run(add, {a: 1}) | ||
print(result) | ||
assert(result == 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module tfd.c_api.linux_; | ||
module tfd.c_api.linux; | ||
version (linux): | ||
|
||
import core.stdc.config; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/// Tensorflow C API header generated by dpp. | ||
/// NOTE: module name linux will be " 1" (https://github.com/atilaneves/dpp/issues/258) | ||
module tfd.c_api.linux_; | ||
module tfd.c_api.linux; | ||
version (linux): | ||
#include <tensorflow/c/c_api.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters