import os import tensorflow as tf x = tf.placeholder(tf.float32, name='x') y = tf.placeholder(tf.float32, name='y') w = tf.Variable(tf.random_uniform([1], -1.0, 1.0), name='w') b = tf.Variable(tf.zeros([1]), name='b') y_hat = w * x + b loss = tf.reduce_mean(tf.square(y_hat - y)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss, name='train') init = tf.initialize_variables(tf.all_variables(), name='init') definition = tf.Session().graph_def directory = os.path.dirname(os.path.realpath(__file__)) tf.train.write_graph(definition, directory, 'regression.pb', as_text=False)