0

我想执行我的图形模型,但我遇到了困难。代码是:

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 in _run(self, handle, fetches, feed_dict, options, run_metadata)
1067 subfeed_t = self.graph.as_graph_element(subfeed, allow_tensor=True, -> 1068 allow_operation=False) 1069 例外为 e:

D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py in as_graph_element(self, obj, allow_tensor, allow_operation) 2707
with self._lock: -> 2708 return self._as_graph_element_locked(obj, allow_tensor, allow_operation ) 2709

D:\AnacondaIDE\lib\site-packages\tensorflow\python\framework\ops.py in _as_graph_element_locked(self, obj, allow_tensor, allow_operation) 2749 ”存在。操作,%s,不存在于“ -> 2750 “图形。” % (repr(name), repr(op_name))) 2751 尝试:

KeyError:“名称‘x:0’指的是不存在的张量。操作‘x’在图中不存在。”

在处理上述异常的过程中,又出现了一个异常:

() 22 # feed_dict = {x: epoch_x, y: epoch_y} 23 ---> 24 sess.run(optimizer, 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 in run(self, fetches, feed_dict, options, run_metadata) 893 try: 894 result = self._run(None, fetches, feed_dict, options_ptr , --> 895 run_metadata_ptr) 896 if run_metadata: 897 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

D:\AnacondaIDE\lib\site-packages\tensorflow\python\client\session.py in _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 (last last call last) in () 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。追加(sess.run(accr,feed_dict = {x:epoch_x,y:epoch_y}))

NameError:名称“x”未定义

请注意,print(features.shape)产量:

(4000, 6000, 3)

我正在使用 Tensorflow-gpu (1.3.0)。

4

1 回答 1

3

在 feed dict 中不应该有引号,但键应该是指向您要提供的占位符的 python 变量。

例如,如果在声明占位符时,您有类似

pl_ = tf.placeholder(...., name='placeholder_1')

那么你应该运行这个

sess.run(...., feed_dict={pl_: value})

而不是这个

sess.run(..., feed_dict={'placeholder_1': value})
于 2017-11-30T08:57:49.560 回答