|
@@ -0,0 +1,41 @@
|
|
1
|
+import tensorflow as tf
|
|
2
|
+
|
|
3
|
+# 오퍼레이션 객체를 리스트로 출력(오퍼레이션이 없다)
|
|
4
|
+print(tf.get_default_graph().get_operations())
|
|
5
|
+# []
|
|
6
|
+
|
|
7
|
+# 오퍼레이션을 생성하여 그래프에 추가한 뒤,
|
|
8
|
+# 각각의 오퍼레이션 출력텐서를 'tensor_a', 'tensor_b'가 가르킴(파이썬은 모두 객체)
|
|
9
|
+tensor_a = tf.constant(1.1, name="a")
|
|
10
|
+tensor_b = tf.constant(2.0, name="b")
|
|
11
|
+
|
|
12
|
+# tensor_c = tf.add(tensor_a, tensor_b) 와 같은 의미
|
|
13
|
+# 앞에서 정의한 상수텐서들을 연산할 오퍼레이션 추가, 해당 오퍼레이션의 출력텐서를 'tensor_c'가 가르킴
|
|
14
|
+tensor_c = tensor_a + tensor_b
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+# Tensor("a:0", shape=(), dtype=float32)
|
|
18
|
+# 1. 'a:0'는 a의 첫번째 출력텐서
|
|
19
|
+# 2. 'shape=()'는 스칼라 텐서
|
|
20
|
+# 3. 'dtype=float32'는 32비트 부동소수형
|
|
21
|
+print(tensor_a)
|
|
22
|
+print(tensor_b)
|
|
23
|
+print(tensor_c)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+print(tensor_a.op) # 텐서에 대한 오퍼레이션 정보
|
|
27
|
+print(tensor_a.op.node_def) # 텐서에 대한 오퍼레이션 정보
|
|
28
|
+print(tensor_a.op.inputs) # 상수 오퍼레이션의 입력은 출력해볼 수 없다.
|
|
29
|
+print(tensor_a.op.outputs) # 상수 오퍼레이션의 출력텐서
|
|
30
|
+
|
|
31
|
+print(tensor_c.op.inputs) # 연산 오퍼레이션은 상수 오퍼레이션과 달리 입력 텐서도 출력가능
|
|
32
|
+print(tensor_c.op.inputs[0]) # tensor_a
|
|
33
|
+print(tensor_c.op.inputs[1]) # tensor_b
|
|
34
|
+print(tensor_c.op.outputs) # 연산 오퍼레이션의 출력텐서
|
|
35
|
+print(tensor_c.op) # 텐서에 대한 오퍼레이션 정보
|
|
36
|
+
|
|
37
|
+print(tf.get_default_graph().get_operations())
|
|
38
|
+
|
|
39
|
+# tensor_c 변수가 가리키고있는 텐서 객체의 값을 연산한 뒤, 결과값을 정수로 출력
|
|
40
|
+with tf.Session() as sess:
|
|
41
|
+ print("%d" % sess.run(tensor_c))
|