• 周三. 1 月 15th, 2025

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

模型权重记录与恢复

admin

11 月 28, 2021
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) #加载权重
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。

发表回复