模型权重记录与恢复
作者:互联网
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) #加载权重
标签:权重,记录,模型,checkpoint,ckpt,参数,logdir,tf,path 来源: https://www.cnblogs.com/WTSRUVF/p/15049447.html