01An image is a tensor
To a computer an image is a grid of numbers. A colour image of height H and width W has three channels (red, green, blue), so it's a 3-D array of shape H Γ W Γ 3, usually with 8-bit integers from 0 (dark) to 255 (bright). A 224 Γ 224 RGB image holds 224 Γ 224 Γ 3 = 150,528 numbers.
Conventions matter in code:
- NumPy, OpenCV and PIL use HWC (height, width, channels). PyTorch uses CHW, and a batch is NCHW.
- OpenCV loads images as BGR, not RGB β a classic source of "the model works in training but not on camera images".
transforms.ToTensor()converts HWC uint8 [0, 255] into CHW float [0, 1].