【问题标题】:change the optimizer of the model and restore the original model from the checkpoint, but there is an error happened更改模型的优化器并从检查点恢复原始模型,但发生错误
【发布时间】:2019-06-11 14:26:39
【问题描述】:

我训练模型,称为模型 A。然后,我更改优化器并通过模型 A 的检查点初始化模型。但是发生了错误。 因为要保存新模型的所有变量,所以没有使用import_meta_graph('**.ckpt'),也没有在tf.train.Saver()中设置变量。 我该如何解决这个问题?

saver = tf.train.Saver(max_to_keep=args.num_snapshot) 
saver.restore(sess, tf.train.get_checkpoint_state(path).model_checkpoint_path)

有错误日志:

NotFoundError (see above for traceback): Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
Key OptimizeLoss/fully_connected_11/biases/Adam not found in checkpoint
[[node save/RestoreV2 (defined at ***.py:130) ]]

【问题讨论】:

    标签: python-3.x tensorflow


    【解决方案1】:

    您可能正在寻找下一行代码:

    restore_vars = (list(set(tf.get_collection_ref(tf.GraphKeys.GLOBAL_VARIABLES))
        .intersection(tf.train.list_variables(checkpoint_dir))))
    
    saver = tf.train.Saver(variables_can_be_restored)
    

    相关话题讨论here

    从检查点恢复后,您也可以尝试使用原始优化器和change the optimizer 进行恢复。

    【讨论】:

    • 但是如果你这样做,我在新模型中创建的变量将无法保存。我想保存新模型中的所有变量。
    • @CongMa 您使用此保护程序一次来恢复权重,然后创建一个不同的保护程序来保存所有内容
    猜你喜欢
    • 2018-05-24
    • 2018-01-14
    • 2018-06-18
    • 1970-01-01
    • 2018-10-04
    • 2023-03-25
    • 1970-01-01
    • 2021-04-21
    • 2015-01-17
    相关资源
    最近更新 更多