Seeing as computation / 1 of 6
Images as tensors
What you’ll learn
- Explain the main idea of “Images as tensors” in your own words.
- Trace a concrete example and identify the assumptions behind it.
- Apply the principle in a practice problem and recognize a common failure.
The idea, intuitively
A digital image is an array of measured intensities. A color image usually has height, width, and channel dimensions. A model sees numeric values, so preprocessing defines the connection between the file and its input tensor.
Begin with the numeric image representation and the exact target the model must predict. Image classification, detection, and segmentation use different labels and evaluation rules. Changes in lighting, camera, geography, and resolution can create distribution shifts even when the subject appears unchanged to a person.
Under the hood
An 8-bit RGB pixel has three integers from 0 to 255. Converting to floating point and normalizing must match the training convention. Resizing may alter aspect ratios or erase small features.
RGB and BGR channel order are not interchangeable without conversion.
A worked example
A 224×224 RGB image contains 150,528 channel values, before batching.
Multiply height × width × channels: 224 × 224 × 3 = 150,528. In height–width–channel order, a single image has shape [224, 224, 3]. Stacking 8 images adds a leading batch dimension: [8, 224, 224, 3]. If your model expects channels first, reorder the axes so the shape becomes [8, 3, 224, 224].
How to use this way of thinking
Inspect inputs after preprocessing, not only the original files. Visualize labels and predictions together. Evaluate small objects, rare classes, and unfamiliar capture conditions separately. If a transformation changes the label meaning, it is not a valid augmentation for that task.
Try it yourself
Convert an 8-bit value of 128 to the [0,1] range.
Key takeaways
- 300
- RGB and BGR channel order are not interchangeable without conversion.
- Check the assumptions with a small example before applying this idea to a larger system.
Check your understanding
Use feedback to learn. Quiz scores and lesson completion are tracked separately.
Go to lesson completionFurther reading
Original papers and reference material for this school. External resources may be in English and require internet access.
Stanford CS231n notes (opens a new tab)Hugging Face Diffusers documentation (opens a new tab)Finish this lesson
Mark this lesson complete when you’re ready to continue.