StoryCode

graph 및 기본 연산 샘플

인공지능,AI,학습,ML,Tensorflow, Cafee2,MLFlow/Tensorflow
반응형

[ 베스트 참조 ] https://www.youtube.com/channel/UCRyIQSBvSybbaNY_JCyg_vA



ex> 5 x 4 x 3 x 2 x 1 = ? 을 그래프로 정의



ex> 2(5 + 4) + 3(1 + 2) = ? 을 그래프로 정의

1) 그래프의 (?) 을 실행하면, 그래프 (텐서플로에서는 session 이라 부름) 를 device (cpu or gpu) 에서 심음.


2) 동작구조



3) 세션은 File 로 I/O handle 된다.


4) 그래프의 (?) = sess.run() 이다.


5) 단일 const 그래프를 연산하는 샘플

import tensorflow as tf

const = tf.constant([10, 20, 30, 40, 50], dtype=tf.float32)

sess = tf.Session()

result = sess.run (const)

print (result)


6) 다중 const 그래프를 생성하는 샘플 (디바이스로 보내기전)

import tensorflow as tf

a =tf.constant([5]);

b =tf.constant([10]);

c =tf.constant([2]);

d = a * b + c // 여기까지가 "모델을 만들었다" 고 표현함.


7) 6)세션을 디바이스로 보내 실행.

sess = tf.Session()

result = sess.run(d)

print (result)


52


반응형