C.W.K.
Stream
Lesson 01 of 07 · published

Tensor가 뭐야?

~11 min · tensor, rank, shape, dtype

Level 0Level 0
0 XP0/78 lessons0/17 achievements
0/100 XP to next level100 XP to go0% complete

제일 먼저 잡고 가야 할 객체

neural network의 모든 input, 모든 model weight, 모든 gradient, 모든 activation — 다 tensor야. architecture 얘기 들어가기 전에, tensor가 뭔지 + 뭐가 아닌지 먼저 박아두자.

Tensor는 scalar, vector, matrix를 임의의 차원으로 일반화한 거. 차원 수가 rank (order 또는 ndim이라고도 함):

  • Rank 0 — scalar. shape (). 예: 4.5.
  • Rank 1 — vector. shape (n,). 예: [1.0, 2.0, 3.0].
  • Rank 2 — matrix. shape (rows, cols). 예: 28×28 grayscale image, shape (28, 28).
  • Rank 3 — 예: RGB image, shape (height, width, 3).
  • Rank 4 — deep learning에서 흔함. batch of images, shape (batch, height, width, channels).

모든 tensor는 세 가지 핵심 속성을 가져 — shape (차원), dtype (데이터 타입), values. dtype이 저장 정밀도 결정 — neural network weight는 float32, label/index는 int32/int64, mask는 bool.

이게 왜 중요하냐면: TF 코드의 runtime 에러 대부분이 shape mismatch야. pipeline 매 단계, layer 매 통과 후의 shape를 술술 읽을 수 있게 되면 디버깅 속도가 완전 달라져.

Code

Creating tensors of each rank·python
import tensorflow as tf

scalar = tf.constant(4.0)
print(scalar.shape, scalar.ndim)   # () 0

vector = tf.constant([1.0, 2.0, 3.0])
print(vector.shape, vector.ndim)   # (3,) 1

matrix = tf.constant([[1, 2, 3], [4, 5, 6]])
print(matrix.shape, matrix.ndim)   # (2, 3) 2

rgb_image = tf.constant([[[255, 0, 0], [0, 255, 0]],
                         [[0, 0, 255], [255, 255, 0]]])
print(rgb_image.shape)             # (2, 2, 3)

batch = tf.zeros([32, 224, 224, 3])
print(batch.shape, batch.ndim)     # (32, 224, 224, 3) 4

External links

Exercise

실제 데이터 타입 세 개 골라 — audio waveform, 주택 데이터 CSV row, 비디오 클립. 각각 TF model에 넣을 때 rank, shape (차원 이름 포함), dtype 적어 봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.