模型权重记录与恢复

 

 

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) #加载权重

 

模型权重记录与恢复

上一篇:二进制部署K8S集群(二十)K8s服务暴露之NodePort型Service


下一篇:vue 任意组件间通信-全局事件总线(GlobalEventBus)