Skip to content

Instantly share code, notes, and snippets.

@dcshapiro
Last active November 28, 2017 00:41
Show Gist options
  • Save dcshapiro/8173777d2d5192621bd5adff783f2eeb to your computer and use it in GitHub Desktop.
Save dcshapiro/8173777d2d5192621bd5adff783f2eeb to your computer and use it in GitHub Desktop.
%%time
img_path = "superintelligence-book-cover.png"
from keras.applications.vgg19 import VGG19
from keras.models import Model
from keras.preprocessing import image
from keras.applications.vgg19 import preprocess_input, decode_predictions
import numpy as np
model_vgg19 = VGG19(weights='imagenet')
model = Model(input=model_vgg19.input, output=model_vgg19.get_layer('predictions').output)
img = image.load_img(img_path, target_size=(224, 224))
x_i = preprocess_input(np.expand_dims(image.img_to_array(img), axis=0))
block4_pool_features = model.predict(x_i)
features=(decode_predictions(block4_pool_features,top=0)[0])
print(features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment