使用youtube给出的原始模型,它在使用mnist时效果很好,但是我想转换为数据库。
我正在使用模型:
def base_model():
model =Sequential()
model.add(Dense(3, input_dim=3, kernel_initializer='normal',activation='relu'))
model.add(Dense(second_layer, input_dim=3, kernel_initializer='normal',activation='relu'))
model.add(Dense(third_layer, input_dim=second_layer, kernel_initializer='normal',activation='relu'))
model.add(Dense(num_classes, kernel_initializer='normal',activation='softmax', name='preds'))
model = base_model()
model.summary()
model.fit(X_train,y_train, validation_data=(X_test,y_test), epochs=5,batch_size=100,verbose=2)
scores = model.evaluate(X_test,y_test,verbose=2)
print("Erro de : %.2f%%" % (100-scores[1]*100))
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['acc'])
return model
我训练模型后,出现此错误:
ValueError:检查输入时出错:预期density_36_input具有 2维,但数组的形状为(374,1,3)
我想像下面这样转换一个数组:
array([[[0.3529358 , 0.32940674, 0.23529053]],
[[0.32940674, 0.23529053, 0.11764526]],
[[0.23529053, 0.11764526, 0.08235168]],
...,
[[0.7529373 , 0.76470184, 0.7411728 ]],
[[0.76470184, 0.7411728 , 0.7529373 ]],
[[0.7411728 , 0.7529373 , 0.7411728 ]]], dtype=float32)
into this one:
array([[[0.3529358 , 0.32940674, 0.23529053],
[0.32940674, 0.23529053, 0.11764526],
[0.23529053, 0.11764526, 0.08235168]],
...,
[[0.7529373 , 0.76470184, 0.7411728 ],
[0.76470184, 0.7411728 , 0.7529373 ],
[0.7411728 , 0.7529373 , 0.7411728 ]]], dtype=float32)