0

グラフモデルを実行したいが問題がある。コードは次のとおりです。sess.run()を実行中にエラーが発生しました

epoch_x, epoch_y = features, labels 
sess.run(optimizer, feed_dict = {"x:0": epoch_x, "y:0": epoch_y}) 

とエラーがある:

--------------------------------------------------------------------------- KeyError Traceback (most recent call last) 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 except Exception as 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 "exist. The operation, %s, does not exist in the " -> 2750 "graph." % (repr(name), repr(op_name))) 2751 try:

KeyError: "The name 'x:0' refers to a Tensor which does not exist. The operation, 'x', does not exist in the graph."

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) in() 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 except Exception as e: 1070 raise TypeError('Cannot interpret feed_dict key as Tensor: ' -> 1071 + e.args[0]) 1072 1073 if isinstance(subfeed_val, ops.Tensor):

TypeError: Cannot interpret feed_dict key as Tensor: The name 'x:0' refers to a Tensor which does not exist. The operation, 'x', does not exist in the graph.

私はまた、次のステートメントを試してみました:

sess.run(optimizer, feed_dict = {"x": epoch_x, "y": epoch_y}) 

その後、エラーがある:

--------------------------------------------------------------------------- NameError Traceback (most recent call last) in() 22 # feed_dict = {x: epoch_x, y: epoch_y} 23 ---> 24 sess.run(optimizer, 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: name 'x' is not defined

print(features.shape)は次のようになります。

(4000, 6000, 3)

私はTensorflow-gpu(1.3.0)を使用しています。

+2

はあなたが引用符を削除しようとした持っているを実行する必要がある場合、すなわち: 'sess.run(オプティマイザ、feed_dict = {x:epoch_x、y:epoch_y})'のように[tensorflow docs](https:// www。 tensorflow.org/versions/r0.12/api_docs/python/io_ops/placeholders)? – Ksyqo

+2

プレースホルダを定義するコードを投稿してください – asakryukin

+0

@Ksyqo qoutesは問題でした.Pietroの答えは前にプレースホルダを宣言していなかったので助けになりました。 –

答えて

3

フィードディクテーションには引用符は必要ありませんが、キーはフィードするプレースホルダを指すPython変数である必要があります。例えば

、あなたが

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

のようなものを持っているあなたのプレースホルダを宣言するとき、あなたはこの

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

とNOT THIS

sess.run(..., feed_dict={'placeholder_1': value}) 
関連する問題