In [20]:
from keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
from keras.preprocessing import image
import numpy as np

In [2]:
model = VGG16?

In [3]:
model = VGG16(include_top=True, weights='imagenet')


Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5
553467904/553467096 [==============================] - 49s    

In [27]:
img_path = '0.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)
print(x.shape)
print(np.mean(x), np.min(x), np.max(x))


(1, 224, 224, 3)
-14.9529 -123.68 151.061

In [14]:
%matplotlib inline
import matplotlib.pyplot as plt

In [24]:
plt.imshow(x[0])


Out[24]:
<matplotlib.image.AxesImage at 0x7f9be9858e10>

In [25]:
result = model.predict(x)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-25-ae07b2745649> in <module>()
----> 1 result = model.predict(x)

/home/christiaan/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in predict(self, x, batch_size, verbose)
   1199         x = standardize_input_data(x, self.input_names,
   1200                                    self.internal_input_shapes,
-> 1201                                    check_batch_dim=False)
   1202         if self.stateful:
   1203             if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0:

/home/christiaan/anaconda3/lib/python3.5/site-packages/keras/engine/training.py in standardize_input_data(data, names, shapes, check_batch_dim, exception_prefix)
    111                             ' to have shape ' + str(shapes[i]) +
    112                             ' but got array with shape ' +
--> 113                             str(array.shape))
    114     return arrays
    115 

ValueError: Error when checking : expected input_1 to have shape (None, 224, 224, 3) but got array with shape (1, 500, 500, 3)

In [19]:
result.shape


Out[19]:
(1, 1000)

In [22]:
print('Predicted:', decode_predictions(result, top=3)[0])


Predicted: [('n01968897', 'chambered_nautilus', 0.18836045), ('n01910747', 'jellyfish', 0.17890556), ('n03724870', 'mask', 0.1336593)]