Skip to content

Instantly share code, notes, and snippets.

@arjun921
Created September 13, 2020 15:56
Show Gist options
  • Save arjun921/7cc4891c481f50f4733bdf65d6359ff7 to your computer and use it in GitHub Desktop.
Save arjun921/7cc4891c481f50f4733bdf65d6359ff7 to your computer and use it in GitHub Desktop.
Tensorflow 2.0 predict from image URL
import numpy as np
from tensorflow.keras.preprocessing import image
from tensorflow.keras.utils import get_file
img_url = 'paste-url-here'
random_string_for_file_name = 'test_image'
img = image.load_img(get_file(random_string_for_file_name,img_url),target_size=(150,150))
img_arr = image.img_to_array(img)
img_arr = np.expand_dims(img_arr, axis=0)
images = np.vstack([img_arr])
classes = model.predict(images, batch_size=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment