제일 먼저 잡고 가야 할 객체
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를 술술 읽을 수 있게 되면 디버깅 속도가 완전 달라져.