Skip to content

Instantly share code, notes, and snippets.

@devmnj
Created June 16, 2023 10:46
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 devmnj/c0c1e5975c252a6dd87753c696d931df to your computer and use it in GitHub Desktop.
Save devmnj/c0c1e5975c252a6dd87753c696d931df to your computer and use it in GitHub Desktop.
Function for load image from url for classification (Keras) - Python
def loadImage(url):
response = requests.get(url)
img_bytes = BytesIO(response.content)
img = Image.open(img_bytes)
img = img.convert('L')
# img = img.convert('1')
# img = img.convert('RGB')
img = img.resize((28, 28), Image.NEAREST)
img = keras.utils.img_to_array(img)
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment