【发布时间】:2018-05-13 20:38:08
【问题描述】:
我想执行我的图形模型,但我遇到了困难。代码是:
epoch_x, epoch_y = features, labels
sess.run(optimizer, feed_dict = {"x:0": epoch_x, "y:0": epoch_y})
错误是:
----------------------------------- ---------------------------- KeyError Traceback(最近一次调用 最后的) D:\AnacondaIDE\lib\site-packages\tensorflow\python\client\session.py 在 _run(self、handle、fetches、feed_dict、options、run_metadata)
第1067章 允许张量=真, -> 1068 allow_operation=False) 1069 例外为 e:D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py 在 as_graph_element(self,obj,allow_tensor,allow_operation)2707
使用 self._lock: -> 2708 返回 self._as_graph_element_locked(obj,allow_tensor,allow_operation)2709D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py 在 _as_graph_element_locked(self, obj, allow_tensor, allow_operation) 2749 "存在。操作 %s 不存在 存在于“ -> 2750“图表”。 % (repr(name), repr(op_name))) 2751 尝试:
KeyError:“名称‘x:0’指的是一个不存在的张量。 图中不存在操作‘x’。”
在处理上述异常的过程中,又发生了一个异常:
TypeError Traceback(最近调用 最后)在() 22 # feed_dict = {x: epoch_x, y: epoch_y} 23 ---> 24 sess.run(优化器, feed_dict = {"x:0": epoch_x, "y:0": epoch_y}) 25 train_loss.append(sess.run(cost, feed_dict = {x: epoch_x, y: epoch_y})) 26 train_accuracy.append(sess.run(accr, feed_dict = {x: epoch_x, y: epoch_y}))
D:\AnacondaIDE\lib\site-packages\tensorflow\python\client\session.py 在运行中(self,fetches,feed_dict,options,run_metadata) 893尝试: 第894章 --> 895 run_metadata_ptr) 896 如果运行元数据: 第897章
D:\AnacondaIDE\lib\site-packages\tensorflow\python\client\session.py 在 _run(self、handle、fetches、feed_dict、options、run_metadata)
1069 例外为 e: 1070 raise TypeError('无法将 feed_dict 键解释为张量:' -> 1071 + e.args[0]) 1072 1073 if isinstance(subfeed_val, ops.Tensor):TypeError:无法将 feed_dict 键解释为张量:名称 'x:0' 指的是一个不存在的张量。操作“x”不 存在于图中。
我也试过以下说法:
sess.run(optimizer, feed_dict = {"x": epoch_x, "y": epoch_y})
那么错误是:
----------------------------------- ---------------------------- NameError Traceback(最近调用 最后)在() 22 # feed_dict = {x: epoch_x, y: epoch_y} 23 ---> 24 sess.run(优化器, feed_dict = {x: epoch_x, y: epoch_y}) 25 train_loss.append(sess.run(cost, feed_dict = {x: epoch_x, y: epoch_y})) 26 train_accuracy.append(sess.run(accr, feed_dict = {x: epoch_x, y: epoch_y}))
NameError: 名称“x”未定义
请注意,print(features.shape) 产生:
(4000, 6000, 3)
我正在使用 Tensorflow-gpu (1.3.0)。
【问题讨论】:
-
您是否尝试过删除引号,即:
sess.run(optimizer, feed_dict = {x: epoch_x, y: epoch_y})按照the tensorflow docs ? -
发布您定义占位符的代码
-
@Ksyqo qoutes 是个问题,Pietro 的回答也有帮助,因为我之前没有声明占位符。
标签: python-3.x tensorflow conv-neural-network semantic-segmentation