Course contentsShow
← AI Engineering
Lesson 1655 of 1,88640. Computer Vision DeploymentFree lesson

Image Preprocessing in Production

Handle resizing, normalization, and augmentation consistently between training and serving environments.

Image Preprocessing in Production

You'll learn how to keep image preprocessing identical between training and production to avoid subtle bugs that tank model accuracy.

The Core Idea

When you train a vision model, you apply specific transformations to images: resizing to 224×224, normalizing pixel values with ImageNet means/stds, maybe random flips for augmentation. The model learns to expect images preprocessed exactly this way. If your production serving pipeline uses different resize interpolation, forgets normalization, or applies augmentation when it shouldn't, your model sees unfamiliar inputs and accuracy plummets.

Think of it like a recipe: if you trained a chef using metric measurements but serve them ingredients in imperial units without conversion, the dishes will fail. Every pixel transformation must match.

Critical Consistency Requirements

Resizing

Use the exact same interpolation method (bilinear, bicubic, nearest) at training and serving. A model trained on cv2.INTER_LINEAR will see slightly different pixels if you serve with PIL.Image.LANCZOS.

Normalization

Apply identical mean subtraction and standard deviation scaling. If training used mean=[0.485, 0.456, 0.406], serving must use those exact values in the same order (RGB vs BGR matters!).

Augmentation

Never apply random augmentations at serving time. Flips, rotations, and color jitter are for training diversity only. Production images should use the deterministic preprocessing path—center crop, not random crop.

Pipeline Order

Execute transforms in the same sequence: resize → crop → normalize, never normalize → resize.

Key Takeaway: Training-serving preprocessing skew is a silent killer in production vision systems. Serialize your exact preprocessing pipeline alongside your model weights and validate outputs match between environments using test images.