Keras中利用训练好的vgg16预测图片类型

代码:
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
from keras.applications import imagenet_utils
import numpy as np

model = VGG16(weights='imagenet')

img_path = 'E:\\timg.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)

features = model.predict(x)
print('Predicted:', imagenet_utils.decode_predictions(features, top=3)[0])
输出结果:预测结果是pizza,82%的概率
E:\phthon35\python.exe I:/catsVSdogs1-master/catsVSdogs1-master/file01/ImagesPredict.py

Predicted: [('n07873807', 'pizza', 0.82579499), ('n07583066', 'guacamole', 0.029104929), ('n07880968', 'burrito', 0.018119223)]

Process finished with exit code 0


你可能感兴趣的:(Keras中利用训练好的vgg16预测图片类型)