tensorflow踩坑

Key regression/Variable not found in checkpoint.........

1、首先是自己定义的参数变量是否和保存的参数变量的类型是一致的

2、在文件下面是否有一个叫做chockpoint的东西存在

3、最后如果运行多次出现NotFoundError (see above for traceback): Key Variable_4 not found in checkpoint     [[Node: save_2/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT,这种情况,请使用tf.reset_default_graph(),还有就是这句话要放在前面一点。

4、还有就是保存好了模型,如果使用的是spyder请先关闭,之后在尝试读入模型如果以上都无法解决你的问题,请删除模型之后,重新写入,再载入试试。
5、

saver.restore(sess,"./mnist/data/convolutional.ckpt")

改成 

module_file =  tf.train.latest_checkpoint('mnist/data/convolutional.ckpt')
with tf.Session() as sess:
   sess.run(tf.global_variables_initializer())
   if module_file is not None:
      saver.restore(sess, module_file)

这几种方法分情况可用,具体的还是要看自己的模型,tf.estimator默认会在模型的保存路径下自动索引checkpiont里面的模型,这部分要注意。

猜你喜欢

转载自blog.csdn.net/chanbo8205/article/details/85928687