简体   繁体   English

检查时出错:预期density_3_input具有2维,但数组的形状为(28,28,1)

[英]Error when checking : expected dense_3_input to have 2 dimensions, but got array with shape (28, 28, 1)

I am writing a neuron for determining the handwritten figures 我正在写一个神经元来确定手写图形

import numpy as np
from keras.utils import np_utils
from keras.models import model_from_json
from keras.preprocessing import image
import matplotlib.pyplot as plt

json_file = open("mnist_model.json", "r")
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights("mnist_model.h5")


loaded_model.compile(loss= "categorical_crossentropy", optimizer="adam", metrics=["accuracy"])


img_path ="5.png"
img = image.load_img(img_path, target_size=(28,28), grayscale=True)
plt.imshow(img, cmap='gray')
plt.show

x =image.img_to_array(img)
x = 255 - x 
x/= 255
np.expand_dims(x, axis=0)
prediction = loaded_model.predict(x)
prediction = np_utils.categorical_pobabs_to_classes(prediction)
print(prediction)

All I did was teach her to use it, but then the problem got out: 1.The result is a graph and an error ValueError: Error when checking : expected dense_3_input to have 2 dimensions, but got array with shape (28, 28, 1) in Line ´img = image.load_img(img_path, target_size=(28,28), grayscale=True)´ 我所做的只是教她使用它,但是问题出了:1.结果是一个图形,并显示一个错误ValueError: Error when checking : expected dense_3_input to have 2 dimensions, but got array with shape (28, 28, 1)在“ img = image.load_img(img_path,target_size =(28,28),grayscale = True)”行中

I think your fault is in this line 我认为你的错在于

np.expand_dims(x, axis=0)

it should be: 它应该是:

x = np.expand_dims(x, axis=0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:检查输入时出错:预期density_16_input具有2维,但数组的形状为(60000,28,28) - ValueError: Error when checking input: expected dense_16_input to have 2 dimensions, but got array with shape (60000, 28, 28) ValueError:检查输入时出错:预期density_1_input具有2维,但数组的形状为(60000,28,28) - ValueError: Error when checking input: expected dense_1_input to have 2 dimensions, but got array with shape (60000, 28, 28) ValueError:检查输入时出错:预期dense_10_input有2维,但得到的数组形状为(60000、28、28) - ValueError: Error when checking input: expected dense_10_input to have 2 dimensions, but got array with shape (60000, 28, 28) ValueError:检查输入时出错:预期 dense_3_input 的形状为 (33,) 但得到的数组形状为 (34,) - ValueError: Error when checking input: expected dense_3_input to have shape (33,) but got array with shape (34,) ValueError:检查时出错:预期conv2d_1_input具有形状(28,28,1),但数组的形状为(58000,28,28) - ValueError: Error when checking : expected conv2d_1_input to have shape (28, 28, 1) but got array with shape (58000, 28, 28) 如何解决:ValueError:检查输入时出错:期望flatten_input具有3个维,但数组的形状为(28,28) - How to fix: ValueError: Error when checking input: expected flatten_input to have 3 dimensions, but got array with shape (28, 28) 检查输入时出错:预期 conv2d_17_input 有 4 个维度,但得到形状为 (28, 28, 1) 的数组 - Error when checking input: expected conv2d_17_input to have 4 dimensions, but got array with shape (28, 28, 1) 如何解决问题“检查输入时出错:期望flatten_7_input具有形状(28,28)但形状为(28,3)的数组” - How to fix problem 'Error when checking input: expected flatten_7_input to have shape (28, 28) but got array with shape (28, 3)' 检查输入时出错:预期conv2d_1_input具有形状(28,28,1),但具有形状(3,224,224)的数组 - Error when checking input: expected conv2d_1_input to have shape (28, 28, 1) but got array with shape (3, 224, 224) 检查输入时出错:预期lstm_28_input具有形状(5739,8),但得到形状为(1,8)的数组 - Error when checking input: expected lstm_28_input to have shape (5739, 8) but got array with shape (1, 8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM