我想针对各种优化器(sgd、rmsprop、adam、adamax 等)检查我的模型的性能所以我定义了一个 keras 顺序模型,然后我这样做epochs = 50print('--sgd start---')model.compile(optimizer='sgd', loss='mse', metrics=['accuracy'])checkpointer_sgd = ModelCheckpoint(filepath='my_model_sgd.h5', verbose=1, save_best_only=True)history_sgd = model.fit(X_train, y_train, validation_split=0.2,epochs=epochs, batch_size=32, callbacks=[checkpointer_sgd],verbose=1)print('--sgd end---')print('--------------------------------------------')print('--rmsprop start---')model.compile(optimizer='rmsprop', loss='mse', metrics=['accuracy'])checkpointer_rmsprop = ModelCheckpoint(filepath='my_model_rmsprop.h5', verbose=1, save_best_only=True)history_rmsprop = model.fit(X_train, y_train, validation_split=0.2, epochs=epochs, batch_size=32, callbacks=[checkpointer_rmsprop],verbose=1)print('--rmsprop end---')我对所有优化器都这样做(在上面的代码中只提到了 sgd 和 rmsprop),然后执行语句。所以现在发生的是第一个优化器从低准确度开始,然后随着更多时期的发生而提高准确度。但是下一个优化器从已经很高的精度开始。上面的代码是正确的还是我每次编译之前都需要重置模型请参阅下面不同优化器的第一个 epoch 输出--sgd start---Train on 1712 samples, validate on 428 samplesEpoch 1/501712/1712 [==============================] - 46s 27ms/step - loss: 0.0510 - acc: 0.2985 - val_loss: 0.0442 - val_acc: 0.6986--rmsprop start---Train on 1712 samples, validate on 428 samplesEpoch 1/501712/1712 [==============================] - 46s 27ms/step - loss: 0.0341 - acc: 0.5940 - val_loss: 0.0148 - val_acc: 0.6963--adagrad start---Train on 1712 samples, validate on 428 samplesEpoch 1/501712/1712 [==============================] - 44s 26ms/step - loss: 0.0068 - acc: 0.6951 - val_loss: 0.0046 - val_acc: 0.6963--adadelta start---Train on 1712 samples, validate on 428 samplesEpoch 1/501712/1712 [==============================] - 52s 30ms/step - loss: 8.0430e-04 - acc: 0.8125 - val_loss: 9.4660e-04 - val_acc: 0.7850
添加回答
举报
0/150
提交
取消