首页 > 其他 > 详细

模型权重记录与恢复

时间:2021-07-23 17:17:54      阅读:18      评论:0      收藏:0      [点我收藏+]

 

 

import tensorflow

logdir = ./logs
checkpoint_path = ./checkpoint/Titanic.{epoch:02d}-{val_loss:.2f}.ckpt #路径为当前目录下的checkpoint子目录,后边为命名规则
callbacks = [tf.keras.callbacks.TensorBoard(log_dir = logdir, histogram_freq = 2), #参数一:日志文件目录, 参数二:直方图频率为2
             tf.keras.callbacks.ModelCheckpoint(filepath = checkpoint_path, save_weights_only = True, verbose = 1, period = 5)]
                                                #参数一:ckpt文件的路径,参数二:仅保存模型的权重,参数三:保存时的输出信息,参数四:周期

 

logdir = ./logs
checkpoint_path = ./checkpoint/Titanic.{epoch:02d}-{val_loss:.2f}.ckpt
checkpoint_dir = os.path.dirname(checkpoint_path) #去掉文件名,返回目录
latest = tf.train.latest_checkpoint(checkpoint_dir) #找到最新的checkpoint
model.load_weights(latest) #加载权重

 

模型权重记录与恢复

原文:https://www.cnblogs.com/WTSRUVF/p/15049447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!