问题描述
我正在使用Keras库,只是在尝试初始化VGG16模型,而且我收到关于所有输入不是该图元素的错误.我正在使用Tensorflow后端.
I'm working with the Keras library and I'm simply trying to initialize the VGG16 model, and I'm getting an error about all the inputs not being an element of this graph. I am using a Tensorflow backend.
输入:
from keras.applications.vgg16 import VGG16
model = VGG16()
输出:
文件",第1行,在 runfile('C:/Users/joshu/Documents/Code/Testing/vgg_tester.py',wdir ='C:/Users/joshu/Documents/Code/Testing')
File "", line 1, in runfile('C:/Users/joshu/Documents/Code/Testing/vgg_tester.py', wdir='C:/Users/joshu/Documents/Code/Testing')
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py", 运行文件中的第880行 execfile(文件名,命名空间)
File "C:\Users\joshu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py", 第102行,在execfile中 exec(compile(f.read(),文件名,'exec'),命名空间)
File "C:\Users\joshu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
文件"C:/Users/joshu/Documents/Code/Testing/vgg_tester.py",第11行 在 型号= VGG16()
File "C:/Users/joshu/Documents/Code/Testing/vgg_tester.py", line 11, in model = VGG16()
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ applications \ vgg16.py", VGG16中的第163行 model.load_weights(weights_path)
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\applications\vgg16.py", line 163, in VGG16 model.load_weights(weights_path)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ engine \ topology.py", 第2708行,在load_weights中 self.load_weights_from_hdf5_group(f)
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2708, in load_weights self.load_weights_from_hdf5_group(f)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ engine \ topology.py", 第2794行,在load_weights_from_hdf5_group中 K.batch_set_value(weight_value_tuples)
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2794, in load_weights_from_hdf5_group K.batch_set_value(weight_value_tuples)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py", 第1860行,在batch_set_value中 get_session().run(assign_ops,feed_dict = feed_dict)
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 1860, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py", 第121行,在get_session中 _initialize_variables()
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 121, in get_session _initialize_variables()
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py", _initialize_variables中的第273行 sess.run(tf.variables_initializer(uninitialized_variables))
File "C:\Users\joshu\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 273, in _initialize_variables sess.run(tf.variables_initializer(uninitialized_variables))
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ client \ session.py", 778行,正在运行 run_metadata_ptr)
File "C:\Users\joshu\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 778, in run run_metadata_ptr)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ client \ session.py", _run中的第969行 fetch_handler = _FetchHandler(self._graph,fetches,feed_dict_string)
File "C:\Users\joshu\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 969, in _run fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ client \ session.py", 第408行,在 init 中 self._fetch_mapper = _FetchMapper.for_fetch(提取)
File "C:\Users\joshu\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 408, in init self._fetch_mapper = _FetchMapper.for_fetch(fetches)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ client \ session.py", 第238行,在for_fetch中 返回_ElementFetchMapper(fetches,contraction_fn)
File "C:\Users\joshu\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 238, in for_fetch return _ElementFetchMapper(fetches, contraction_fn)
文件 "C:\ Users \ joshu \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ client \ session.py", 第274行,在 init 中 '张量. (%s)'%(fetch,str(e)))
File "C:\Users\joshu\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 274, in init 'Tensor. (%s)' % (fetch, str(e)))
ValueError:无法获取参数 被解释为张量. (操作名称:"init_11"操作:"NoOp" 输入:"^ block1_conv1_W_8/Assign"输入:"^ block1_conv1_b_8/Assign" 输入:"^ block1_conv2_W_8/Assign"输入:"^ block1_conv2_b_8/Assign" 输入:"^ block2_conv1_W_8/分配"输入:"^ block2_conv1_b_8/分配" 输入:"^ block2_conv2_W_8/分配"输入:"^ block2_conv2_b_8/分配" 输入:"^ block3_conv1_W_8/Assign"输入:"^ block3_conv1_b_8/Assign" 输入:"^ block3_conv2_W_8/分配"输入:"^ block3_conv2_b_8/分配" 输入:"^ block3_conv3_W_8/分配"输入:"^ block3_conv3_b_8/分配" 输入:"^ block4_conv1_W_8/Assign"输入:"^ block4_conv1_b_8/Assign" 输入:"^ block4_conv2_W_8/Assign"输入:"^ block4_conv2_b_8/Assign" 输入:"^ block4_conv3_W_8/Assign"输入:"^ block4_conv3_b_8/Assign" 输入:"^ block5_conv1_W_8/Assign"输入:"^ block5_conv1_b_8/Assign" 输入:"^ block5_conv2_W_8/Assign"输入:"^ block5_conv2_b_8/Assign" 输入:"^ block5_conv3_W_8/Assign"输入:"^ block5_conv3_b_8/Assign" 输入:"^ fc1_W_4/Assign"输入:"^ fc1_b_4/Assign"输入: "^ fc2_W_4/分配"输入:"^ fc2_b_4/分配"输入: 输入"^ predictions_W_4/Assign":输入"^ predictions_b_4/Assign": "^ cond_153/switch_f"不是该图的元素.)
ValueError: Fetch argument cannot be interpreted as a Tensor. (Operation name: "init_11" op: "NoOp" input: "^block1_conv1_W_8/Assign" input: "^block1_conv1_b_8/Assign" input: "^block1_conv2_W_8/Assign" input: "^block1_conv2_b_8/Assign" input: "^block2_conv1_W_8/Assign" input: "^block2_conv1_b_8/Assign" input: "^block2_conv2_W_8/Assign" input: "^block2_conv2_b_8/Assign" input: "^block3_conv1_W_8/Assign" input: "^block3_conv1_b_8/Assign" input: "^block3_conv2_W_8/Assign" input: "^block3_conv2_b_8/Assign" input: "^block3_conv3_W_8/Assign" input: "^block3_conv3_b_8/Assign" input: "^block4_conv1_W_8/Assign" input: "^block4_conv1_b_8/Assign" input: "^block4_conv2_W_8/Assign" input: "^block4_conv2_b_8/Assign" input: "^block4_conv3_W_8/Assign" input: "^block4_conv3_b_8/Assign" input: "^block5_conv1_W_8/Assign" input: "^block5_conv1_b_8/Assign" input: "^block5_conv2_W_8/Assign" input: "^block5_conv2_b_8/Assign" input: "^block5_conv3_W_8/Assign" input: "^block5_conv3_b_8/Assign" input: "^fc1_W_4/Assign" input: "^fc1_b_4/Assign" input: "^fc2_W_4/Assign" input: "^fc2_b_4/Assign" input: "^predictions_W_4/Assign" input: "^predictions_b_4/Assign" input: "^cond_153/switch_f" is not an element of this graph.)
推荐答案
我拉开了VGG16代码,文档提到了
I pulled open the VGG16 code and the docs mentioned having
包含在keras配置JSON文件中.添加似乎可以解决问题.
included in the keras config JSON file. Adding that seemed to fix the problem.
不确定与以下内容之间的区别:
Not sure the difference between that and:
但两者似乎都起作用.
这篇关于ValueError:获取参数< tf.Operation'init_8'type = NoOp>不能解释为张量.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!