Created
September 3, 2017 08:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, do you have any examples to train the VGG16 from scratch, ie with new dataset?