当前位置:网站首页>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指定保存最大值还是最小值,具体解释可参考官方文档。
边栏推荐
- 【系统问题】.NET Framework 3.5 安装错误
- A usage exploration of entitymanagerfactory and entitymanager
- 8、曲面几何
- vim常用命令总结
- MySQL-8.0.28 用户操作 or 用户权限操作
- Deploy storageclass trample record
- Mysql-8.0.28 user operation or user permission Operation
- Thing JS notes
- 十年架构五年生活-01毕业之初
- Master slave synchronization step read / write separation + self encountered error sharing
猜你喜欢
随机推荐
Web server failed to start. Port 8080 was already in use.
Murata power maintenance switch server power maintenance and main functional features
JDBC database connection pool
CountDownLatch的用法
Usage of countdownlatch
Single sign on - how to unify the expiration time of session between authentication server and client
Detailed explanation of structure
Markdown常用语法记录
项目流程总结
pygame实现飞机大战游戏
Shardingsphere sub database and table scheme
分页、过滤
MySQL statement queries all child nodes of a level node
字典创建与复制
mysql语法(纯语法)
項目部署(簡版)
[Social Media Marketing] new idea of going to sea: WhatsApp business replaces Facebook
Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?
比特,比特,字節,字的概念與區別
MySQL-8.0.28 用户操作 or 用户权限操作







![[ROS advanced chapter] Lesson 8 syntax explanation of URDF file](/img/ad/038d088d5cd17784d3e2d7291bb750.jpg)

