Basics Flashcards
How do you create a session?
sess = tf.Session()
What do you need to do to use TensorFlow in Python?
import tensorflow as tf
How do you create a constant in TensorFlow?
a = tf.constant(3.0, dtype=tf.float32)
How do you run a TensorFlow session?
sess.run([node1, node2])
How can you print a session to the prompt?
print(sess.run([node1, node2])
How do you add values in TensorFlow?
c = a + b c = tf.add(a, b)
How do you add inputs to TensorFlow?
a = tf.placeholder(tf.float32) b = ft.placeholder(tf.float32) c = a + b sess.run(c, {a: 3, b: 4}) will give 7 to print to the console use print(sess.run(c, {a: 3, b: 4}))
How do you multiply a and b in TensorFlow
c = a * b
How can you stack node in TensorFlow?
c = a + b d = c * 3
How do you create a variable in TensorFlow?
W = tf.Variable([0.3], dtype=tf.float32)
Create a linear model with TensorFlow
W = tf.Variable([0.3], dtype=tf.float32) b = tf.Variable([-0.3], dtype=tf.float32) x = tf.placeholder(tf.float32) linear_model = W * x + b
How do you initialize variables in TensorFlow?
init = tf.global_variables_initializer()
sess.run(init)
How can you add the contents of a vector V together in TensorFlow?
total = tf.reduce_sum(V)
Write a MSD error function in TensorFlow.
y = tf.placeholder(tf.float32) squared_deltas = tf.square(linear_model - y) loss = tf.reduce_sum(squared_deltas)
to run the model and print the output use something like
print( sess.run( loss, { x: [1, 2, 3, 4], y: [0, -1, -2, -3] } ) )
How can you set the value of a variable in TensorFlow?
fixW = tf.assign(W, [-1.0])
sess.run(fixW)
How do you setup a gradient descent optimizer in TensorFlow?
optim = tf.train.GradientDescentOptimizer(0.01) train = optim.minimize(loss)
How do you run the TensorFlow optimizer once its setup?
sess.run(init) # reset values to defaults.
for i in range(1000):
sess.run(train, {x: [1, 2, 3, 4], y: [0, -1, -2, -3]})
print(sess.run([W, b]))
How do you check if a file is executable?
ls -la
How can you make a file executable?
chmod +x fname