当前位置:网站首页>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指定保存最大值还是最小值,具体解释可参考官方文档。
边栏推荐
- Partial usage of C #
- JDBC的学习以及简单封装
- [information system project manager] Chapter VI recheck schedule management knowledge structure
- 使用cmd安装pygame
- mysql语法(纯语法)
- Two strategies for building AI products / businesses (by Andrew ng)
- Filter in MATLAB
- 項目部署(簡版)
- A usage exploration of entitymanagerfactory and entitymanager
- mysql invalid conn排查
猜你喜欢

开发必备之Idea使用

Basic concepts of software testing

web调用接口上传图片到七牛云

Epidemic period plus midlife crisis - three months wandering at the crossroads

Dynamic memory management

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

mysql invalid conn排查

PMP practice once a day | don't get lost in the exam -7.22

【文献调研】在Pubmed上搜索特定影响因子期刊上的论文
![[Anaconda environmental management and package management]](/img/cc/9f15282eabf0eee5e9f28b4f62f1e2.png)
[Anaconda environmental management and package management]
随机推荐
The 12th Blue Bridge Cup embedded design and development project
Leetcode daily question (1946. largest number after varying substring)
Pytorch (V) -- pytorch advanced training skills
3.Flask 中的线程
CountDownLatch的用法
Activiti工作流使用之流程结构介绍
pycharm占用c盘
分页、过滤
C#的partial用法
比特,位,字节,字的概念与区别
An accident caused by MySQL misoperation, and "high availability" is not working well
JDBC数据库连接池
超级简单的人脸识别api 只需几行代码就可以实现人脸识别
[Social Media Marketing] new idea of going to sea: WhatsApp business replaces Facebook
cuda10.0配置pytorch1.7.0+monai0.9.0
Dictionary creation and copying
Project deployment (simplified version)
联合主键和索引
Notes and Thoughts on the red dust of the sky (III) as long as the conditions are sufficient, the results will come naturally
Redis数据库和项目框架