2016-05-10 6 views
4

最適化中にモデルの状態を保存する最良の方法が何であるか疑問に思っていました。私はこれをやりたいので、しばらくそれを実行して保存し、しばらくしてからやり直すことができます。私は重みを保存する関数とJSONとしてモデルを保存する別の関数があることを知っています。学習中は、モデルの重みとパラメータの両方を保存する必要があります。これには、運動量や学習率などのパラメータが含まれます。モデルと重量の両方を同じファイルに保存する方法はありますか?私は、ピックルを使用するのは良い習慣とはみなされないと読んでいます。また、控えめな人のモメンタムは、モデルJSONまたはウェイトに含まれますか?ケラス、最適化時に状態を保存する最良の方法

答えて

2

重みとアーキテクチャを含むtarアーカイブと、model.optimizer.get_state()によって返されるオプティマイザ状態を含むpickleファイルを作成できます。

+0

'はAttributeError:「アダムのオブジェクトが属性を持っていないが「 –

+0

@MatthewKleinsmithをget_state'':私はこれを書いたので、APIが変更されている可能性があります。 –

+0

うん、それは起こる。私のコメントは純粋に情報的なものでした。 –

0
from keras.models import load_model 

model.save('my_model.h5') # creates a HDF5 file 'my_model.h5' 
del model # deletes the existing model 

# returns a compiled model 
# identical to the previous one 
model = load_model('my_model.h5') 

You can use model.save(filepath) to save a Keras model into a single HDF5 file which will contain:

  • the architecture of the model, allowing to re-create the model
  • the weights of the model
  • the training configuration (loss, optimizer)
  • the state of the optimizer, allowing to resume training exactly where you left off.

You can then use keras.models.load_model(filepath) to reinstantiate your model. load_model will also take care of compiling the model using the saved training configuration (unless the model was never compiled in the first place).

KerasのFAQ:How can I save a Keras model?

関連する問題