본문 바로가기

Deep Learning

TensorFlow의 설치 및 기본적인 operations

Tensorflow

  • Deep learning libraries 중 tensorflow가 가장 많은 사람들이 사용함
  • data flow graph를 사용해서 numerical computation이 가능한 라이브러리
  • python 사용

Data Flow Graph

 

  • 그래프 : Node, Edge로 구성됨
  • Node : 하나의 연산 (+, - 등)
  • Edge : 데이터 (tensors)

Installing Tensorflow (MacOX 기준)

  • sudo su -
  • pw 입력
  • pip install --upgrade tensorflow

제대로 설치되었는지 확인하는 방법

  • python3 : 파이썬 실행
  • import tensorflow as tf : tf라는 이름으로 tensorflow import
  • tf.__version__ : tensorflow 버전 확인

Tensorflow Mechanics

  • Tool을 이용해 그래프를 설계 및 빌드
  • sess.run(op, feed_dict={x:x_data})을 이용해 그래프 실행
  • 그 결과로 그래프의 값이 업데이트 및 리턴됨

Rank : 몇 차원 array인지

 

Rank Math entity Python example
0 Scalar (magnitude only) s = 483
1 Vector (magnitude & direction) v = [1,2,3]
2 Matrix (table) m = [[1,2,3], [4,5,6]]
3 3-Tensor (cube) t = [[[2],[4]], [[6],[8]], [[10], [12]]]
n n-Tensor ...

 

Shape : 각 element에 몇 개씩 들어있는지

ex) t = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]   ->   (3 3) 또는 [3,3]으로 표현

 

Rank Shape Dimension number Example
0 [] 0-D A 0-D tensor. A scalar.
1 [D0] 1-D A 1-D tensor with shape [5].
2 [D0, D1] 2-D A 2-D tensor with shape [3,4].
3 [D0, D1, D2] 3-D A 3-D tensor with shape[1,4,3].
n [D0, D1, ... Dn-1] n-D ...

 

Data type

 

Data type Python type
DT_FLOAT tf.float32
DT_DOUBLE tf.float64
DT_INT8 tf.int8
DT_INT16 tf.int16
DT_INT32 tf.int32
DT_INT64 tf.int64

 

※ inflearn 모두를 위한 딥러닝 강좌를 듣고 정리한 내용입니다.