ps:keras如何保存每一个epoch的权重?写个博客记录一下,顺便给有相同困扰的朋友一个参考。
直接上示例:
from keras.callbacks import ModelCheckpoint
filepath = "H:/model/weights_{epoch:03d}-{val_acc:.4f}.h5" checkpoint = ModelCheckpoint( filepath=filepath, monitor='val_accuracy', save_best_only=False, verbose=1, save_weights_only=False, period=1 ) history = lstmNet.fit(x_train,y_train, epochs=15,validation_data=(x_test,y_test), validation_freq=1,callbacks=[checkpoint])
主要是这三步,其中filepath是保存路径,这是官网给出的方法,save_best_only和save_weights_only设置为False,否则只保存最佳模型或者只保存参数,最后一定要记得在fit函数中调用callbacks。