Skip to content

Instantly share code, notes, and snippets.

@kentsommer
Created March 21, 2017 01:14
Show Gist options
  • Save kentsommer/48e43bf7badd7243849d01ba1e76e3cf to your computer and use it in GitHub Desktop.
Save kentsommer/48e43bf7badd7243849d01ba1e76e3cf to your computer and use it in GitHub Desktop.
classification test
from keras.applications.inception_v3 import *
from keras.preprocessing import image
from keras.applications.imagenet_utils import decode_predictions
from keras import backend as K
import numpy as np
model = InceptionV3(weights='imagenet')
img_path = 'apple.jpg'
img = image.load_img(img_path, target_size=(299, 299))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
print('Predicted:', decode_predictions(preds))
@wenouyang
Copy link

Hi, I have been testing this test.py, but I got the following error message, I am using theano (0.9.0) along with keras(2.0.3). Would you like to share any hint what can cause the problem?

raceback (most recent call last):
File "test.py", line 7, in
model = InceptionV3(weights='imagenet')
File "/tmp/lib/python3.5/site-packages/keras/applications/inception_v3_nourl.py", line 388, in InceptionV3
model.load_weights(weights_path)
File "/tmp/lib/python3.5/site-packages/keras/engine/topology.py", line 2500, in load_weights
load_weights_from_hdf5_group(f, self.layers)
File "/tmp/lib/python3.5/site-packages/keras/engine/topology.py", line 2911, in load_weights_from_hdf5_group
' elements.')
ValueError: Layer #0 (named "conv2d_1" in the current model) was found to correspond to layer convolution2d_1 in the save file. However the new layer conv2d_1 expects 1 weights, but the saved weights have 2 elements.

@preet01
Copy link

preet01 commented May 29, 2018

Install the latest keras version. The problem is solved over there

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