windows10下默认路径:C:\Users\To Kill a MockinBird\.keras\models;
Linux下默认路径:/root/.keras/
3.2 Jupyter新建python程序,通过API调用VGG模型
3.3 调用VGG模型对图片类型进行分类,代码如下:
# 加载VGG16模型
model = VGG16()
from keras.preprocessing.image import load_img
# 加载图像资源,图像默认存储路径:C:\Users\To Kill a MockinBird\dots.jpg
image = load_img('dots.jpg', target_size=(224, 224))
from keras.preprocessing.image import img_to_array
# 将图片像素转换为numpy数组
image = img_to_array(image)
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
from keras.applications.vgg16 import preprocess_input
# prepare the image for the VGG model
image = preprocess_input(image)
# predict the probability across all output classes
yhat = model.predict(image)
from keras.applications.vgg16 import decode_predictions
# convert the probabilities to class labels
label = decode_predictions(yhat)
# retrieve the most likely result, e.g. highest probability
label = label[0][0]
# print the classification
print('分类结果:%s (%.2f%%)' % (label[1], label[2]*100))
3.4 点击“运行”执行VGG卷积神经图像分类
(注:图像存储路径默认在:C:\Users\To Kill a MockinBird\dots.jpg)