【发布时间】:2019-03-28 22:44:33
【问题描述】:
我正在尝试使用 python 和 Keras 做一个图像分类器,但我遇到了以下错误:
ValueError: Error when checking model input: the list of Numpy arrays that
you are passing to your model is not the size the model expected. Expected
to see 1 array(s), but instead got the following list of 1816 arrays:
我尝试将 x_train 更改为 numpy 数组,但仍然出现错误:
ValueError: Error when checking input: expected conv2d_13_input to have 4
dimensions, but got array with shape (1816, 1)
这是我的代码的一部分:
def read_and_process_image(imagesTrain):
x_train = []
y_train = []
for trImage in imagesTrain:
x_train.append(cv2.imread(trImage, cv2.IMREAD_COLOR))
if 'A' in trImage:
y_train.append(0)
elif 'B' in trImage:
y_train.append(1)
return x_train, y_train
x_train, y_train = read_and_process_image(train_imgs)
modelo.fit(x_train,y_train,batch_size=50,epochs=7,verbose=1)
我没有显示整个代码,所以它不会填满整个窗口,但是有人知道如何解决这个问题吗?
【问题讨论】:
-
期望 'y_train' 有 4 个维度,但它有 2 个。您只是在附加零和一。