【发布时间】:2021-05-22 17:44:05
【问题描述】:
这是我的代码,但预测功能不起作用
from keras.applications.vgg16 import VGG16
from keras.utils.vis_utils import plot_model
#Keras will download the weight files from the Internet and store them in the ~/.keras/models directory.
model = VGG16()
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.applications.vgg16 import preprocess_input
# load an image from file
image = load_img('output.png', target_size=(224, 224))
# convert the image pixels to a numpy array
image = img_to_array(image)
# reshape data for the model
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
# prepare the image for the VGG model
image = preprocess_input(image)
from keras.applications.vgg16 import decode_predictions
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
# predict the probability across all output classes
yhat = model.predict(image)
# 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))
img = Image.open('output.png')
plt.imshow(img)
我该怎么办?? wekfjeojocwjcopjcoekcopejcpoekcpwekcpejoejocijewjwrjwihujviruhviuhr
【问题讨论】:
-
您可能希望将错误代码粘贴为纯文本(而不是屏幕截图),以便人们更轻松地为您提供帮助。
标签: python tensorflow keras