본문 바로가기

AI/Deep Learning

[모두를 위한 딥러닝(Sung Kim)|ch.1-2] TensorFlow의 설치 및 기본적인 operations

 

  • What is Data FLow Graph?

Graph : Node(정점)와 Edge(간선)로 연결된 것

 

data flow graph

하나의 operation

Edge는 data, Tensor

노드는 operation

Tensor가 돌아다닌다 하여 

Tensorflow이다

 

  • Example  tensorflow v 2.4.0 

HelloWorld.py 

1
2
3
4
5
6
7
8
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'= '2'
 
import tensorflow as tf
 
hello = tf.constant('Hello, Tensorflow!')
 
print(hello)
cs

 

Computertational_Graph.py 

-1

1
2
3
4
5
6
7
8
9
10
11
12
import tensorflow as tf
import numpy as np
 
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0)
node3 = tf.add(node1, node2)
 
print(f"node1: {node1} node2: {node2}" )
print(f"node3: {node3}" )
 
tf.print(node1, node2)
tf.print(node3)
cs

-2

v1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import tensorflow as tf
import numpy as np
 
@tf.function
def adder(a, b):
    return a + b
 
= tf.constant(1)
= tf.constant(2)
print(adder(A, B))
 
= tf.constant([1,2])
= tf.constant([3,4])
print(adder(C, D))
 
= tf.constant([[1,2,3], [4,5,6]])
= tf.constant([[2,3,4], [5,6,7]])
print(adder(E, F))
 
cs