Skip to content

Instantly share code, notes, and snippets.

@Thimira
Created September 3, 2017 08:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Thimira/6dc1da782b0dca43485958dbee12a757 to your computer and use it in GitHub Desktop.
Save Thimira/6dc1da782b0dca43485958dbee12a757 to your computer and use it in GitHub Desktop.
How to use the ResNet50 model from Keras Applications trained on ImageNet to make a prediction on an image.
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np
model = ResNet50(weights='imagenet')
img_path = 'Data/Jellyfish.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
print('Predicted:', decode_predictions(preds, top=3)[0])
@NG-Bullseye
Copy link

I cant import ResNet50

Unresolved reference 'ResNet50'
Unresolved reference 'preprocess_input'
Unresolved reference 'decode_predictions'

thank you for your Help

@NG-Bullseye
Copy link

from keras.applications import ResNet50
from keras.applications.densenet import preprocess_input, decode_predictions
from keras.utils import load_img,img_to_array
import numpy as np

model = ResNet50(weights='imagenet')

img_path = 'Data/Jellyfish.jpg'
img = load_img(img_path, target_size=(224, 224))
x = img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

preds = model.predict(x)

decode the results into a list of tuples (class, description, probability)

print('Predicted:', decode_predictions(preds, top=3)[0])

@snajme
Copy link

snajme commented Jul 10, 2023

this was very helpful! many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment