Я пытаюсь визуализировать прогноз VGG-16 для изображения кошки. Вычислить 5 лучших баллов (5 классов с максимальной вероятностью). Для каждого из этих 5 баллов вывести соответствующую метку и соответствующую вероятность. .
from keras.applications.vgg16 import preprocess_input
from keras.preprocessing import image
# load the image from cat class and resize it
img = image.load_img('cat.jpg', target_size=(224, 224))
# convert to numpy array of (224, 224, 3)
x = image.img_to_array(img)
# add empty dimention for tensor flow (1,224,224,3)
x = np.expand_dims(x, axis = 0)
# perform mean removal as in the original VGG16 network
x = preprocess_input(x)
# make the prediction using VGG16
output = model.predict(x)
print('model prediction output', output)
# plot the prediction
plt.plot(output[0], '-')
plt.show()
# decode the prediction
from keras.applications.vgg16 import decode_predictions
top5 = decode_predictions(output)
for _, label, proba in top5[0]:
print(label, 'with probability', proba)
Я получаю эту ошибку, любая помощь будет оценена
Файл "C: \ Users \ mwaqa \ Desktop \ Spyder \ E8 Q2,3,4 , 5.py ", строка 75, в plt.plot (вывод, '-')
Файл" c: \ users \ mwaqa \ miniconda3 \ lib \ site-packages \ matplotlib \ pyplot.py ", строка 2789, в сюжете нет None else {}), ** kwargs)
Файл" c: \ users \ mwaqa \ miniconda3 \ lib \ site-packages \ matplotlib \ axes_axes.py " строка 1665, в строках графика = [* self._get_lines (* args, data = data, ** kwargs)]
Файл "c: \ users \ mwaqa \ miniconda3 \ lib \ site-packages \ matplotlib \ axes_base.py ", строка 225, в __call__
yield из self._plot_args (this, kwargs)
Файл" c: \ users \ mwaqa \ miniconda3 \ lib \ site-packages \ matplotlib \ axes_base.py ", строка 391, в _plot_arg sx, y = self._xy_from_xy (x, y)
Файл "c: \ users \ mwaqa \ miniconda3 \ lib \ site-packages \ matplotlib \ axes_base.py", строка 273, в _xy_from_xy " shape {} и {} ". format (x.shape, y.shape))
ValueError: x и y не могут быть больше 2-D, но имеют формы (1,) и (1, 224, 224, 3)