gpt4 book ai didi

machine-learning - ValueError : Error when checking model target: expected dense_4 to have shape (None, 4) 但得到形状为 (13252, 1) 的数组

转载 作者:行者123 更新时间:2023-11-30 08:32:58 25 4
gpt4 key购买 nike

嗨,有人知道为什么会发生此错误吗?这是错误

ValueError: Error when checking model target: expected dense_4 to have   shape (None, 4) but got array with shape (13252, 1)

这是代码:

from keras.models import Sequential
from keras.layers import *

model = Sequential()
model.add(Cropping2D(cropping=((0,0), (50,20)), input_shape=(160 ,320, 3))) #(None, 90, 320, 3)
model.add(Lambda(lambda x: x/127.5 - 1.))
model.add(Convolution2D(32, 3, 3,)) #(None, 88, 318, 32)
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3)) #(None, 86, 316, 32)
model.add(Activation('relu'))
model.add(Flatten()) #(None, 869632)
model.add(Dense(128)) #(None, 128)
model.add(Activation('relu'))
model.add(Dense(4)) #(None, 4)
print(model.summary())

model.compile(loss='mse', optimizer='adam')
model.fit(X, y, validation_split=0.2, batch_size=32, nb_epoch=3, verbose=1)

输入形状为(X):

(13252, 160, 320, 3)

和(y):

(13252,)

最佳答案

由于您的网络有四个输出,因此您的y必须是 N x 4 矩阵,而不是长度为 N 的向量。要么更改 y,要么将最后一层更改为密集(1)

关于machine-learning - ValueError : Error when checking model target: expected dense_4 to have shape (None, 4) 但得到形状为 (13252, 1) 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42235611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com