코드부
import tensorflow as tf
# 그래프 노드 정의후 출력
node1 = tf.constant(4.0) #암시적으로 float32 로 선언
node2 = tf.constant(3.0)
print("생성된 그래프 각각 출력 : ",node1,node2)
# 그래프를 생성후 실행하지 않았기 때문에 노드에 대한 설명만이 출력된다.
# 세션을 열어 그래프 실행
sess = tf.Session()
print("그래프 실행(각각 출력 ) : ",sess.run([node1,node2]))
# 노드 값을 덧셈
node3 = tf.add(node1,node2)
print("덧셈 그래프 출력 : ",node3)
print("덧셈 그래프 실행후 출력 : ", sess.run(node3))
sess.close()
출력부
생성된 그래프 각각 출력 : Tensor("Const_2:0", shape=(), dtype=float32) Tensor("Const_3:0", shape=(), dtype=float32)
그래프 실행(각각 출력 ) : [4.0, 3.0]
덧셈 그래프 출력 : Tensor("Add_1:0", shape=(), dtype=float32)
덧셈 그래프 실행후 출력 : 7.0