In [2]:
from __future__ import print_function
import tensorflow as tf
In [3]:
# apt-get install graphviz
# pip install graphviz
from tfdot import tfdot
In [4]:
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)
In [5]:
tfdot()
Out[5]:
In [6]:
sess = tf.Session()
print(sess.run(product))
sess.close()
In [8]:
with tf.Session() as sess:
print(sess.run(product))
In [10]:
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
with tf.device("/cpu:0"):
m1 = tf.constant([[3., 3.]])
m2 = tf.constant([[2.],[2.]])
pd = tf.matmul(m1, m2)
print(sess.run(pd))
In [11]:
sess = tf.InteractiveSession()
In [12]:
product.eval()
Out[12]:
In [13]:
pd.eval()
Out[13]:
In [14]:
state = tf.Variable(0, name="counter")
one = tf.constant(1)
new_value = tf.add(state, one)
update = tf.assign(state, new_value)
init_op = tf.initialize_all_variables()
In [15]:
tfdot()
Out[15]:
In [17]:
init_op.run()
# state.run() # variables do not run
print(state.eval())
In [18]:
for _ in range(300):
update.eval()
In [19]:
state.eval()
Out[19]:
In [20]:
sess.run([update]*10)
Out[20]:
In [21]:
# will back to here later
# tf.ops.reset_default_graph()
# sess.close()
# sess = tf.InteractiveSession()
In [22]:
weights = tf.Variable(tf.random_normal([784, 200], stddev=0.35), name='weights')
w2 = tf.Variable(weights.initialized_value(), name ='w2')
w_twice = tf.Variable(weights.initialized_value()*0.2, name="w_twice")
In [23]:
tfdot()
Out[23]:
In [24]:
init_op = tf.initialize_all_variables()
init_op.run()
In [25]:
weights.eval()
Out[25]:
In [27]:
for v in tf.all_variables():
print(v.name, v)
In [28]:
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.mul(input1, input2)
output.eval(feed_dict={input1: [9.], input2: [4.]})
Out[28]:
In [29]:
tfdot()
Out[29]:
In [ ]: