본문 바로가기
AI/Deep Learning

딥러닝 : 01. Tensorflow의 정의

by KIha_Jung 2019. 7. 26.
01_tensorflow

1. Tensorflow 란?


tensorflow는 google에서 만든 딥러닝 프로그램을 쉽게 구현할 수 있는 라이브러리이다.

기본적인 언어를 지원하지만 python을 최우선으로 한다.
대부분의 편리한 기능들이 python library로만 구현되어 있다.
tenor란 딥러닝에서 데이터를 표현하는 방식을 뜻하고 flow는 흐름을 뜻한다. tensor의 이해가 매우 중요하다.

tensorflow의 연산은 dataflow graph로 이루어진다. 즉 텐서 형태의 데이터들이 딥러닝 모델을 구성하는 연산들의 그래프를 따라 흐르면서 연산한다고 보면 되겠다.

tensorflow는 가장 인기있는 딥러닝 라이브러리이고 딥러닝을 사용하는데 더욱 편리하게 해준다.

In [1]:
import tensorflow as tf
In [4]:
hello = tf.constant('Hello world')

sess = tf.Session()

print(sess.run(hello))
b'Hello world'
In [6]:
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0)
node3 = tf.add(node1, node2)
In [11]:
sess.run([node1, node2])
Out[11]:
[3.0, 4.0]
In [12]:
sess.run(node3)
Out[12]:
7.0

2. Tensorflow Mechanics


  1. 그래프를 우선 빌드한다
  2. Session().run(op)로 실행한다
  3. data가 update 되거나 return한다.
In [14]:
# placeholder
# 그래프를 먼저 만들어 놓고 값들을 나중에 넣어준다.
# placeholder로 node를 만들어 준다.
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = a + b

# feed_dict = {} 으로 값을 넘겨준다.
print(sess.run(adder_node, feed_dict={a:3.5, b:4.5}))
print(sess.run(adder_node, feed_dict={a:[1,3], b:[2,4]}))
8.0
[3. 7.]

tensor ranks, shapes and Type


s = 456 //ranks :1 , shape(1,1) type = int
s = [1,2]
s = [[1,2],[3,4]]

In [15]:
s1 = 442
s2 = [1,2]
s3 = [[1,2,3],[4,5,6],[5,6,7]]
In [31]:
print(sess.run(tf.shape(s1)))
print(sess.run(tf.shape(s2)))
print(sess.run(tf.shape(s3)))
[]
[2]
[3 3]
In [33]:
print(sess.run(tf.rank(s1)))
print(sess.run(tf.rank(s2)))
print(sess.run(tf.rank(s3)))
0
1
2

댓글