Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions examples/addition/addition.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# TODO: Stop using v1 compatibility
import tensorflow.compat.v1 as tf
import tensorflow as tf

# check tensorflow version is 2.x
tf_major_version = tf.__version__.split('.')[0]
assert tf_major_version == '2'

tf.disable_eager_execution()
x = tf.placeholder(tf.int32, name = 'x')
y = tf.placeholder(tf.int32, name = 'y')
z = tf.add(x, y, name = 'z')
@tf.function
def add(x, y):
tf.add(x, y, name='z')

tf.variables_initializer(tf.global_variables(), name = 'init')
x = tf.TensorSpec((), dtype=tf.dtypes.int32, name='x')
y = tf.TensorSpec((), dtype=tf.dtypes.int32, name='y')

definition = tf.Session().graph_def
concrete_function = add.get_concrete_function(x, y)
directory = 'examples/addition'
tf.train.write_graph(definition, directory, 'model.pb', as_text=False)
tf.io.write_graph(concrete_function.graph, directory, 'model.pb', as_text=False)
Binary file modified examples/addition/model.pb
Binary file not shown.