Skip to content

Instantly share code, notes, and snippets.

@malnakli
Created November 1, 2018 13:06
Show Gist options
  • Save malnakli/f6efb2474e071f27a381e58864b30931 to your computer and use it in GitHub Desktop.
Save malnakli/f6efb2474e071f27a381e58864b30931 to your computer and use it in GitHub Desktop.
from urllib import request
from PIL import Image
image_url = "https://cdn.shopify.com/s/files/1/2029/4253/products/[email protected]"
image_path = f"tmp/{image_url.split('/')[-1]}"
# download image
with request.urlopen(url=image_url, timeout=10) as response:
data = response.read()
with open(image_path, 'wb') as f:
f.write(data)
# convert image to grayscale.
image = Image.open(image_path).convert('L')
# resize the image to 28 28 to make sure it is similar to our dataset
image.thumbnail((28,28))
image = preprocess_image(np.array(image))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment