图像像素处理 正反向,使像素呈高斯分布:
SQUEEZENET_MEAN = np.array([0.485, 0.456, 0.406], dtype=np.float32)
SQUEEZENET_STD = np.array([0.229, 0.224, 0.225], dtype=np.float32)
def preprocess_image(img):
"""
Preprocess an image for squeezenet.
Subtracts the pixel mean and divides by the standard deviation.
"""
return (img.astype(np.float32) / 255.0 - SQUEEZENET_MEAN) / SQUEEZENET_STD
def deprocess_image(img, rescale=False):
"""Undo preprocessing on an image and convert back to uint8."""
img = (img * SQUEEZENET_STD + SQUEEZENET_MEAN)
if rescale:
vmin, vmax = img.min(), img.max()
img = (img - vmin) / (vmax - vmin)
return np.clip(255 * img, 0.0, 255.0).astype(np.uint8)