Last active
March 10, 2020 00:05
-
-
Save sariabod/39a0e6309a6a7a4e89f46ce839043688 to your computer and use it in GitHub Desktop.
Example Normalize to Imagenet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import numpy as np | |
image = Image.open('sample.jpg') | |
#resize | |
image = image.resize((50,50)) | |
#show resized | |
image.show() | |
#imagenet stats | |
mean=[0.485, 0.456, 0.406] | |
std=[0.229, 0.224, 0.225] | |
#convert to array | |
pixels = np.asarray(image).astype('float32') | |
#normalize | |
pixels = (pixels - mean) / std | |
#to visualize what changed | |
normalized_image = Image.fromarray(np.uint8(pixels)) | |
normalized_image.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment