当前位置:网站首页>Keras saves the best model in the training process
Keras saves the best model in the training process
2022-07-23 11:14:00 【I'm a girl, I don't program yuan】
With xDeepFM For example
Save model parameters
from deepctr.models import xDeepFM
model = xDeepFM(...)
model.compile(...)
model.fit(...)
# save_weights
model.save_weights('... .h5')
Read h5 Model
model = xDeepFM(...)
# load_weights
model.load_weights('... .h5')
because h5 The file saves the model parameters , Therefore, the model structure needs to be built manually , If you need to save the model structure , Sure Use json File save model structure .
Save the optimal model weight
The above method saves all epoch The last result after training , But not necessarily the optimal value , So you can use checkpoint Save the optimal weight .
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 The parameters of the ,filepath I.e. preserved h5 file ,monitor It is the indicator of monitoring , It's usually val_loss,val_acc etc. ,mode Specify whether to save the maximum value or the minimum value , For specific explanation, please refer to Official documents .
边栏推荐
猜你喜欢

RPC与thrift入门

Activiti工作流使用之新建bpmn文件

Briefly describe the features and application scenarios of redis

pycharm占用c盘
![[pytho-flask笔记5]蓝图简单使用](/img/0a/00b259f42e2fa83d4871263cc5f184.png)
[pytho-flask笔记5]蓝图简单使用
![[Doris]配置和基本使用contens系统(有时间继续补充内容)](/img/74/21c5c0866ed6b1bb6f9a1e3755b61e.png)
[Doris]配置和基本使用contens系统(有时间继续补充内容)

项目部署(简版)

防止神经网络过拟合的五种方法

JDBC learning and simple encapsulation

With only 5000 lines of code, AI renders 100 million landscape paintings on v853
随机推荐
MySQL-8.0.28 用户操作 or 用户权限操作
Project deployment (simplified version)
Markdown common syntax records
【无标题】
请求数据获取与响应
大厂面试机器学习算法(5)推荐系统算法
Master slave synchronization step read / write separation + self encountered error sharing
JDBC database connection pool
Activiti工作流使用之项目实例
項目部署(簡版)
Copy a project /project in idea
字典创建与复制
2.启动函数返回值的剖析
大厂面试机器学习算法(6)时间序列分析
Powerbi Getting Started Guide
DWI图像 从DICOM Tag识别 b value 的方法
支付宝DTS架构
Summary of common commands of vim
【无标题】
When using cache in sprintboot, the data cannot be loaded