当前位置:网站首页>Keras保存训练过程中的最好模型
Keras保存训练过程中的最好模型
2022-07-23 05:38:00 【我是女生,我不做程序媛】
以xDeepFM为例
保存模型参数
from deepctr.models import xDeepFM
model = xDeepFM(...)
model.compile(...)
model.fit(...)
# save_weights
model.save_weights('... .h5')
读取h5模型
model = xDeepFM(...)
# load_weights
model.load_weights('... .h5')
由于h5文件保存的是模型参数,因此模型结构需要自己手动构建,如果需要保存模型结构,可以使用json文件保存模型结构。
保存最优模型权重
上述方法保存的是所有epoch训练后的最后一次结果,但不一定是最优值,因此可以使用checkpoint保存最优权重。
model = xDeepFM(...)
model.compile(...)
# checkpoint
checkpoint = tf.keras.callbacks.ModelCheckpoint(filepath='... .h5', monitor='val_loss', verbose=1, save_best_only=True, mode = 'min')
callback_list = [checkpoint]
model.fit(...,callbacks = callback_list )
ModelCheckpoint的参数中,filepath即保存的h5文件,monitor是监控的指标,一般为val_loss,val_acc等,mode指定保存最大值还是最小值,具体解释可参考官方文档。
边栏推荐
- mysql语法(纯语法)
- What does resource pooling and resource pooling mean?
- Gerrit 使用操作手册
- LearnOpenGL - Introduction
- 8. Surface geometry
- [information system project manager] Chapter VI recheck schedule management knowledge structure
- 好玩的代码雨,在线分享给大家~-
- Mysql-8.0.28 user operation or user permission Operation
- C1--Vivado配置VS Code文本编辑器环境2022-07-21
- Cadence (IX) 17.4 rules and spacing settings
猜你喜欢

Notifier Nordic fire engine power supply maintenance and daily maintenance

对比redis的RDB、AOF模式的优缺点

Mysql database foundation

Markdown常用语法记录

【系统问题】.NET Framework 3.5 安装错误

SPR:SUPERVISED PERSONALIZED RANKING BASED ON PRIOR KNOWLEDGE FOR RECOMMENDATION

讲师征集令 | Apache DolphinScheduler Meetup分享嘉宾,期待你的议题和声音!

项目部署(简版)

6. Barycentric coordinate interpolation and graphics rendering pipeline

Cadence (IX) 17.4 rules and spacing settings
随机推荐
【无标题】
Cadence learning path (VIII) PCB placement components
Shardingsphere sub database and table scheme
字典创建与复制
Déploiement du projet (version abrégée)
WebSocket长连接
支付宝DTS架构
人脸识别神经网络实现
DWI图像 从DICOM Tag识别 b value 的方法
項目部署(簡版)
Notes and Thoughts on the red dust of the sky (IV) invalid mutual value
Filter in MATLAB
视、音频分开的网站内容如何合并?批量下载代码又该如何编写?
MySQL syntax (pure syntax)
Murata power maintenance switch server power maintenance and main functional features
Xssgame games (XSS learning) level1-15
Single sign on - how to unify the expiration time of session between authentication server and client
7. Texture mapping
With only 5000 lines of code, AI renders 100 million landscape paintings on v853
【无标题】