Skip to content

Instantly share code, notes, and snippets.

@Thimira
Created September 3, 2017 08:34
Show Gist options
  • Save Thimira/c369aea98c4268042425649a6a687d8f to your computer and use it in GitHub Desktop.
Save Thimira/c369aea98c4268042425649a6a687d8f to your computer and use it in GitHub Desktop.
How to use the VGG16 model from Keras Applications trained on ImageNet to make a prediction on an image.
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np
model = VGG16(weights='imagenet')
img_path = 'Data/Jellyfish.jpg'
img = image.load_img(img_path, target_size=(224, 224))
img_data = image.img_to_array(img)
img_data = np.expand_dims(img_data, axis=0)
img_data = preprocess_input(img_data)
preds = model.predict(img_data)
# decode the results into a list of tuples (class, description, probability)
print('Predicted:', decode_predictions(preds, top=3)[0])
@gledsonmelotti
Copy link

Hello, do you have any examples to train the VGG16 from scratch, ie with new dataset?

@GargaBenjo
Copy link

Do you have find?

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