Macan

TensorFlow Computational Graph / Placeholder 본문

AI

TensorFlow Computational Graph / Placeholder

Macan 2017. 11. 7. 10:49





1.  그래프 빌드


2. 그래프 실행 


3. 결과 반환  알고리즘을 가지고 있다.



>>> import tensorflow as tf

/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6

  return f(*args, **kwds)

>>> node1 = tf.constant(1.0, tf.float32)

>>> node2 = tf.constant(22.0)

>>> node3 = tf.add(node1, node2)

>>> print(node1, node2, node3)   -- 1.그래프 빌드

Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32) Tensor("Add:0", shape=(), dtype=float32)

      - 그냥 출력 시 결과값이 나오는게 아니라 하나의 그래프를 표현(tansor)

>>> sess = tf.Session()

>>> print(sess.run([node1, node2])) - Tensorflow의 세션을 만들어 실행시켜줌.  -- 2. 그래프 실행

[1.0, 22.0] - 결과값  -- 3. 결과값 반환

>>> print(sess.run(node3)) 

23.0




Placeholder


>>> a = tf.placeholder(tf.float32)

>>> b = tf.placeholder(tf.float32)

>>> adder_node = a+b

>>> print(sess.run(adder_node, feed_dict={a : 21, b: 5.5}))

26.5

>>> print(sess.run(adder_node, feed_dict={a:[1,2], b: [3,4]}))

[ 4.  6.]

'AI' 카테고리의 다른 글

TensorFlow Hello World !  (0) 2017.11.06
What is ML ?  (0) 2017.11.06
Comments