![](/img/trans.png)
[英]What is the difference between these two ways of building a model in keras?
[英]What is the difference between these two ways of saving keras machine learning model weights?
我看到了兩種保存 keras 模型權重的方法。
第一種方式;
checkpointer = ModelCheckpoint(filepath="weights.hdf5", verbose=1, save_best_only=True)
model.fit(x_train, y_train,
nb_epoch=number_of_epoch,
batch_size=128,
verbose=1,
validation_data=(x_test, y_test),
callbacks=[reduce_lr, checkpointer],
shuffle=True)
第二種方式;
model.save_weights("model_weights.h5")
這兩種方式有什么區別? 在裝載之間的預測性能的任何差異weights.hdf5
和model_weights.h5
?
不,在性能方面沒有區別。 這些只是保存模型的方式和時間的兩種不同方式。 使用model.save_weights
需要在您想要保存模型時特別調用此函數,例如在完成訓練或部分訓練之后。 如果您仍在開發模型,使用ModelCheckpoint
會方便得多。 使用這種方式, keras
可以在每個訓練 epoch 后保存您模型的檢查點,以便您可以恢復不同的模型; 或者您可以設置save_best_only=True
以便keras
只有在性能提高時才會覆蓋最新的檢查點,以便您以性能最佳的模型結束。
總結一下:這只是做兩種不同事情的兩種不同方式。 這取決於您的用例和需求,什么是最好的。
正如這里從根本上解釋的那樣reference.wolfram.com/language/ref/format/HDF5.html
HDF
是分層數據格式的首字母縮寫詞。HDF5
是 HDF 版本 5。
Import["file.h5"]
導入一個 HDF5 文件,返回存儲在文件中的數據集的名稱。
在 Keras 文檔中; 正如你在這里看到的keras.io/api/models/model_saving_apis/
model.save('my_model.h5') # creates a HDF5 file 'my_model.h5'
在 Tensorflow 文檔中; 正如你在這里看到的tensorflow.org/tutorials/keras/save_and_load
# Save the entire model to a HDF5 file.
# The '.h5' extension indicates that the model should be saved to HDF5.
model.save('my_model.h5')
從根本上講,它們是同一回事。 他們不能創造任何差異。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.