Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint的解决方案
在Tensorflow下使用SSD模型训练自己的数据集时,经过查找很多博客资料,已经成功训练出来了自己的模型,但就是在测试自己模型效果的时候,出现了如下错误。
2019-10-27 14:47:12.862573: W tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
Traceback (most recent call last):
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
return fn(*args)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.NotFoundError: Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
[[{{node save/RestoreV2}}]]
[[{{node save/RestoreV2}}]] During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1276, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run
feed_dict_tensor, options, run_metadata)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
run_metadata)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]]
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]] Caused by op 'save/RestoreV2', defined at:
File "ssd_notebook.py", line 53, in <module>
saver = tf.train.Saver()
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 832, in __init__
self.build()
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 844, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 881, in _build
build_save=build_save, build_restore=build_restore)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 513, in _build_internal
restore_sequentially, reshape)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 332, in _AddRestoreOps
restore_sequentially)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 580, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 1572, in restore_v2
name=name)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
op_def=op_def)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1801, in __init__
self._traceback = tf_stack.extract_stack() NotFoundError (see above for traceback): Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]]
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]] During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1286, in restore
names_to_keys = object_graph_key_mapping(save_path)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1591, in object_graph_key_mapping
checkpointable.OBJECT_GRAPH_PROTO_KEY)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 370, in get_tensor
status)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "ssd_notebook.py", line 54, in <module>
saver.restore(isess, ckpt_filename)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1292, in restore
err, "a Variable name or other graph key that is missing")
tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable nameor 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 ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]]
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]] Caused by op 'save/RestoreV2', defined at:
File "ssd_notebook.py", line 53, in <module>
saver = tf.train.Saver()
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 832, in __init__
self.build()
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 844, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 881, in _build
build_save=build_save, build_restore=build_restore)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 513, in _build_internal
restore_sequentially, reshape)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 332, in _AddRestoreOps
restore_sequentially)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 580, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/ops/gen_io_ops.py", line 1572, in restore_v2
name=name)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
op_def=op_def)
File "/opt/anaconda3/envs/dlipy3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1801, in __init__
self._traceback = tf_stack.extract_stack() 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 ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]]
[[node save/RestoreV2 (defined at ssd_notebook.py:53) ]]
在查找资料的过程中,出现了很多波折,百度上基本没有同样的错误,
最开始使用的代码是:
ckpt_filename = '../train_model/model.ckpt-1000'
尝试过很多种方法,比如下面这种方法,改了后还是报同样的错误。
ckpt_filename = tf.train.latest_checkpoint('../train_model/model.ckpt-1000')
还有说模型没有完全保存,经过很多次训练,发现模型确实是成功保存了的。
还说是按照这个英文意思来解决,就是这个Key在ckpt文件里面没有。经查找资料用如下代码查看ckpt文件里面的key。
import os
from tensorflow.python import pywrap_tensorflow current_path = '****/SSD_small_object_detection/'
model_dir = os.path.join(current_path, 'train_model')
checkpoint_path = os.path.join(model_dir,'model.ckpt-1000') # 保存的ckpt文件名,不一定是这个
# Read data from checkpoint file
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
# Print tensor name and values
for key in var_to_shape_map:
print("tensor_name: ", key)
# print(reader.get_tensor(key)) # 打印变量的值,对我们查找问题没啥影响,打印出来反而影响找问题
确实得到了一点结果,如下图所示:
就算得到了结果,但是代码太复杂,本身也看不太懂,就想着实在没办法的话就尝试Debug下代码,但是我相信前面的步骤没有问题,然后终于发现了解决方法。
于是我在我自己的代码中将saver的定义改变一下
saver = tf.train.import_meta_graph("../train_model/model.ckpt-1000.meta")
错误成功解决。
Key ssd_300_vgg/block3_box/L2Normalization/gamma not found in checkpoint的解决方案的更多相关文章
- Redis百亿级Key存储方案(转)
1 需求背景 该应用场景为DMP缓存存储需求,DMP需要管理非常多的第三方id数据,其中包括各媒体cookie与自身cookie(以下统称supperid)的mapping关系,还包括了supperi ...
- Redis百亿级Key存储方案
1 需求背景 该应用场景为DMP缓存存储需求,DMP需要管理非常多的第三方id数据,其中包括各媒体cookie与自身cookie(以下统称supperid)的mapping关系,还包括了supperi ...
- 【Spark调优】大表join大表,少数key导致数据倾斜解决方案
[使用场景] 两个RDD进行join的时候,如果数据量都比较大,那么此时可以sample看下两个RDD中的key分布情况.如果出现数据倾斜,是因为其中某一个RDD中的少数几个key的数据量过大,而另一 ...
- 热点Key问题的发现与解决
热点问题概述 产生原因 热点问题产生的原因大致有以下两种: 用户消费的数据远大于生产的数据(热卖商品.热点新闻.热点评论.明星直播). 在日常工作生活中一些突发的的事件,例如:双十一期间某些热门商品的 ...
- 谈一谈NOSQL的应用,Redis/Mongo
1.心路历程 上年11月份来公司了,和另外一个同事一起,做了公司一个移动项目的微信公众号,然后为了推广微信公众号,策划那边需要我们做一些活动,包括抽奖,投票.最开始是没有用过redis的,公司因为考虑 ...
- iOS开发之使用Runtime给Model类赋值
本篇博客算是给网络缓存打个基础吧,本篇博客先给出简单也是最容易使用的把字典转成实体类的方法,然后在给出如何使用Runtime来给Model实体类赋值.本篇博客会介绍一部分,主要是字典的key与Mode ...
- zabbix使用介绍
zabbix自定义监控项 1.创建主机组,可以根据redis.mysql.web等创建对于的主机组 2.创建主机 3.创建Screens 4.自定义监控项 zabbix_agentd.conf配置文件 ...
- 《OD学hive》第六周20160731
一.hive的压缩 1. hadoop的压缩 1)为什么需要压缩 MapReduce的性能瓶颈:网络IO.磁盘IO 数据量:对于MapReduce的优化,最主要.根本就是要能够减少数据量 Combin ...
- NOSQL的应用,Redis/Mongo
NOSQL的应用,Redis/Mongo 1.心路历程 上年11月份来公司了,和另外一个同事一起,做了公司一个移动项目的微信公众号,然后为了推广微信公众号,策划那边需要我们做一些活动,包括抽奖,投票. ...
随机推荐
- MyCat教程六:全局序列号-全局主键的自增长
前面我们介绍了MyCat的分库分表操作,那么同一张表中的数据会被保存在不同的数据库中,那么这就涉及到了主键维护的问题,此时肯定不能使用单个数据库中id自增的方式来处理了,这时我们就可以通过MyCa ...
- Constructing Roads POJ - 2421
题目链接:https://vjudge.net/problem/POJ-2421 思路:一些村庄,建一些路,使得所有村庄能相连,而且使得所有路长度之和最短. 题目说了,有些村庄之间已经建了路,说明有些 ...
- 构建n位元的格雷码
二进制格雷码的生成 1.什么是格雷码 Gray Code是一个数列集合,每个数使用二进制来表示,假设使用n位元来表示每个数字,那么任两个数之间只有一个位元值不同.log2(16)=4 例如: 生成4位 ...
- linux(10)uwsgi???
[uwsgi] Django-related settings the base directory (full path) #指定项目的绝对路径的第一层路径!!!!!!!!!!!!!!!!!!!!! ...
- MyBatis学习笔记-1 Idea配置MyBatis
一.创建工程 1.创建Java项目,勾选Java EE,Next,修改名称,Finish 2.在WEB-INF下创建两个文件夹classes和lib,分别用作输出文件目录和库文件目录 3.File-P ...
- DNS解析过程--笔试答题版
在运维笔试的时候,回答DNS解析的过程,不能写一大堆,一是不美观,二是浪费时间,应该怎么写呢?我觉得这样写比较好. 1.客户端:chche----hosts 2.DNS服务器:cache---递归-- ...
- 【使用篇二】SpringBoot整合Servlet(1)
两种方式: 通过注解扫描完成 Servlet组件的注册 通过方法完成 Servlet组件的注册 一.通过注解扫描完成 Servlet 组件的注册 1. 编写Servlet类 /** * SpringB ...
- CF306C White, Black and White Again
CF306C White, Black and White Again 洛谷评测传送门 题目描述 Polycarpus is sure that his life fits the descripti ...
- 弗洛伊德算法(Floyd )
package com.rao.graph; /** * @author Srao * @className Floyd * @date 2019/12/11 18:43 * @package com ...
- String的拼接
1.直接定义字符串变量的时候赋值,如果表达式右边只有字符串常量,那么就是把变量存放在常量池里面. 2.new出来的字符串是存放在堆里面. 3.对字符串进行拼接操作,也就是做"+"运 ...