TensorFlow Python
(TensorFlow) 연습1
kjun.kr
2017. 10. 11. 23:47
728x90
아래 내용의 코딩이 있어 실행해 봤다.
작업시간이 조금 걸린다. 그래픽카드가 1050ti 라서 ㅜㅠ
코드내용
import tensorflow as tf
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
import numpy as np
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1+0.3
W = tf.Variable(tf.random_uniform([1],-1.0,1.0))
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)
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
참고.. (주석)
728x90