File size: 487 Bytes
078ce08 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import numpy as np
# Preprocessing functions
def normalize_batch(images):
"""Performs channel-wise z-score normalization"""
return (images - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225])
def denormalize_batch(images, should_clip=True):
"""Denormalize the images for prediction"""
images = (images * np.array([0.229, 0.224, 0.225])) + np.array([0.485, 0.456, 0.406])
if should_clip:
images = np.clip(images, 0, 1)
return images
|