making exe file : #! /usr/bin/python3
tensorflow command : https://blog.naver.com/ins_soul80
using editor : jupyter notebook
sess
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.global_variables_initializer()
writer = tf.summary.FileWriter('/tmp/log', graph = tf.get_default_graph())
with tf.Session() as sess:
sess.run(init_op)
print(sess.run(state))
for _ in range(3):
sess.run(update)
sess.run(update)
print(sess.run(state))
placeholder
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.multiply(input1, input2)
with tf.Session() as sess:
res = sess.run([output], {input1:[7.], input2:[3.]})
print(res)
SK code
book p.88 -> Skeleton Code
and p.90 -> you have to draw the algorithm graph(weight and bias ans output)
Session exam using SK code
import tensorflow as tf
import numpy as np
x_data = np.random.rand(100).astype('f')
y_data = x_data * .1 + .3
W = tf.Variable(tf.random_uniform([1], -1., 1.))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
#Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
sess.close()
#learns best fit is W: [0.1], b: [0.3]
this week, we're using NVIDIA TX2 board for linux, so hard to type hangul. And also, we're useing textook.