Skip to content

Instantly share code, notes, and snippets.

@GiulioCMSanto
Created September 22, 2019 19:50
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 GiulioCMSanto/cbeab60f5fe981d67738998c2643d9f4 to your computer and use it in GitHub Desktop.
Save GiulioCMSanto/cbeab60f5fe981d67738998c2643d9f4 to your computer and use it in GitHub Desktop.
Classifying Flowers With Transfer Learning
def process_image(image):
''' Scales, crops, and normalizes a PIL image for a PyTorch model,
returns an Numpy array
'''
# TODO: Process a PIL image for use in a PyTorch model
#Loading image with PIL (https://pillow.readthedocs.io/en/latest/reference/Image.html)
im = Image.open(image)
#Notice: te very same transformation applied to the test/validation data will be applied here
process = transforms.Compose([transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406],
[0.229, 0.224, 0.225])])
return process(im)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment