출처: 모두를위한 머신러닝 (http://hunkim.github.io/ml/)
TensorFlow : Data Flow Graph¶
Node 와 Node가 연결되어 있는 구조
- Nodes : Mathematiclal operations (어떤 값을 받아서 더한다, 곱한다 등..)
- Edges : Data arrays (Tensors !)
In [10]:
import tensorflow as tf
hello = tf.constant("Hello")
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0)
node3 = tf.add(node1, node2)
node4 = node1 + node2
print("node1:", node1)
print("node2:", node2)
print("node3:", node3)
print("node4:", node4)
Session 의 역할¶
- Tensor 는 그 자체로 object 이므로, print() 했을 시 object 정보를 출력함
- Session 을 만든후 run을 시킬 경우, 단순 변수인 tensor 는 변수를 출력하고
- 만약 어떤 연산을 하는경우 연산을 run 시킴 -> 얽혀 있는 다른 변수들이 update 됌!!
In [4]:
sess = tf.Session()
print(sess.run(hello))
print("sess.run(node1, node2):", sess.run([node1, node2]))
print("sess.run(node3):", sess.run(node3))
print("sess.run(node4):", sess.run(node4))
TensorFlow Mechanics¶
- Flow Graph 를 만든후 (node1= , node2= , ..)
- Session 을 실행 (session.run(node1))
- Graph 안의 변수 값 리턴
In [13]:
import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b
sess = tf.Session()
print(sess.run(adder_node, feed_dict={a: 3, b: 4.5})) # adder node 에 dict 형태로 a, b 값 지정
print(sess.run(adder_node, feed_dict={a: [1, 3], b: [2, 4]}))
'Dev > 딥러닝' 카테고리의 다른 글
04-2. Tensor Flow 에서 csv 파일 읽기 및 queue 사용법 (0) | 2018.08.17 |
---|---|
04-1. Tensor Flow 변수가 여러개일때 Linear regression (0) | 2018.08.17 |
03. TensorFlow Linear Regression 의 cost 최소화 구현 (0) | 2018.08.17 |
02. Tensor Flow로 linear regression 예제 (0) | 2018.08.16 |
Tensor Flow (gpu) 윈도우에서 설치하기 (0) | 2018.08.16 |
댓글