检查模型输入时出错:预期flatten_input_8有4个维度

时间:2017-03-13 18:36:05

标签: python deep-learning keras

运行此代码时出现以下错误:

  

检查模型输入时出错:预期flatten_input_8为4   尺寸,但得到形状的阵列(3167,1)

我的代码:

lines=[]

with open('train_data/driving_log.csv') as csvFile:
    reader= csv.reader(csvFile)
    for line in reader:
        lines.append(line)



images=[]
measurements=[]
for line in lines:
    source_path=line[0]
    file_name= source_path.split('/')[-1]
    current_path= 'train_path/IMG/' + file_name
    image= cv2.imread(current_path)
    images.append(image)
    measurement=float(line[3])
    measurements.append(measurement)

X_train=np.array(images)
y_train=np.array(measurements)

model= Sequential()
model.add(Flatten(input_shape=(160,320,3)))
model.add(Dense(1))
model.compile(loss='mse',optimizer='adam')
model.fit(X_train,y_train,validation_split=0.2,shuffle=True)
model.save('model.h5')

知道我的代码有什么问题吗?请帮我解决这个问题,谢谢

0 个答案:

没有答案