Cheat Sheets of Python Libraries Tensorflow
Cheat Sheets of Python Libraries Tensorflow
jalajthanaki / cheat_sheets_of_python_libraries
1 contributor
Importing
The line to import tensorflow by convention is as follows:
import tensorflow as tf
Placeholders (inputs)
A placeholder is a value to input on a TensorFlow computation. It cannot be evaluated, as it must be fed a value using a
feed_dict .
Variables
Variables are useful to hold and update parameters. Unlike placeholders, variables are initialized with some value and can be
updated through the computation. They are in-memory buffers containing tensors.
Initialization
A variable initializer must be run before other ops in the model can be run. Exists an operation that runs all variable
initilizations: tf.initialize_all_variables() .
https://github.com/jalajthanaki/cheat_sheets_of_python_libraries/blob/master/8_tensorflow/tensorflow.md 1/3
11/4/2017 cheat_sheets_of_python_libraries/tensorflow.md at master · jalajthanaki/cheat_sheets_of_python_libraries · GitHub
b = tf.Variable(tf.zeros([200]), name='b')
...
# add an op to initialize the variables
init_op = tf.initialize_all_variables()
# Later, launch the model, initialize the variables, do some work, save the
# variables to disk.
with tf.Session() as sess:
sess.run(init_op)
# Do some work with the model.
..
# Save the variables to disk.
save_path = saver.save(sess, "/tmp/model.ckpt")
print("Model saved in file: %s" % save_path)
# Later, launch the model, use the saver to restore variables from disk, and
# do some work with the model.
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "/tmp/model.ckpt")
print("Model restored.")
https://github.com/jalajthanaki/cheat_sheets_of_python_libraries/blob/master/8_tensorflow/tensorflow.md 2/3
11/4/2017 cheat_sheets_of_python_libraries/tensorflow.md at master · jalajthanaki/cheat_sheets_of_python_libraries · GitHub
# Do some work with the model
...
https://github.com/jalajthanaki/cheat_sheets_of_python_libraries/blob/master/8_tensorflow/tensorflow.md 3/3