Skip to content

Instantly share code, notes, and snippets.

@sariabod
Last active March 10, 2020 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sariabod/39a0e6309a6a7a4e89f46ce839043688 to your computer and use it in GitHub Desktop.
Save sariabod/39a0e6309a6a7a4e89f46ce839043688 to your computer and use it in GitHub Desktop.
Example Normalize to Imagenet
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