what is tensor?

  • 어떻게 바라보아도 그 본질이 변하지 않는 것 (어떤 좌표계로 보더라도 변하지 않는 것)
  • https://www.tensorflow.org/guide/tensor?hl=ko “텐서는 일관된 유형(dtype이라고 불림)을 가진 다차원 배열입니다.”
  • Rank : tensor의 차원 단위

 

Tensorflow

  • 구글에서 개발한 파이썬 기반 머신러닝 프레임워크
  • 텐서(tensor)를 기본 자료구조로 하여 그것의 흐름으로써 수치연산해주는 라이브러리 → 데이터 플로우 그래프

데이터 플로우 그래프(Data Flow Graph)

  • 노드 : 덧셈, 곱셈 등 텐서를 처리하는 연산
  • 엣지 : 방향에 따른 텐서의 흐름(화살표)

 

a = tf.constant(5, name='a')
b = tf.constant(3, name='b')

<tf.Tensor: shape=(), dtype=int32, numpy=5>
<tf.Tensor: shape=(), dtype=int32, numpy=3>

 

c = tf.multiply(a, b, name='c')
d = tf.add(a, b, name='d')
e = tf.add(c, d, name='e')

<tf.Tensor: shape=(), dtype=int32, numpy=15>
<tf.Tensor: shape=(), dtype=int32, numpy=8>
<tf.Tensor: shape=(), dtype=int32, numpy=23>

 

# 텐서플로우 구버전 (session 정의 후 실행)
# sess = tf.Session()
# print(sess.run(e))

tf.print(e)

23

 

 

keras

  • tensorflow 위에서 동작하는 딥러닝 라이브러리
  • 2021년 6월 업데이트: Tensorflow 2.6 부터 tensorflow 패키지에서 분리, from tensorflow import keras 가 아닌 import keras 를 사용하게 될 것

왼쪽과 같이 keras를 활용해 간단한 모델을 구현하거나 오른쪽과 같이 tensorflow로 직접 모델을 구현할 수 있음

복사했습니다!