import numpy as np
import keras
from keras.preprocessing import image
from keras.applications.inception_v3 import InceptionV3
from keras.applications.inception_v3 import preprocess_input, decode_predictions
model = keras.applications.inception_v3.InceptionV3()
img = image.load_img("lionNN.jpg", target_size=(299, 299))
img
x = image.img_to_array(img)
print(x.shape)
x = np.expand_dims(x, axis=0)
print(x.shape)
(299, 299, 3) (1, 299, 299, 3)
x = preprocess_input(x)
predictions = model.predict(x)
predicted_classes = decode_predictions(predictions, top=9)
for imagenet_id, name, likelihood in predicted_classes[0]:
print(name,':', likelihood)
lion : 0.9088954 collie : 0.0037420776 chow : 0.0013897745 leopard : 0.0013692076 stopwatch : 0.00096159696 cheetah : 0.0008766686 Arabian_camel : 0.0006716717 tiger : 0.00063297455 hyena : 0.00061666104