Tensorflow 无法使用tf.train.import_meta_graph导入元图,名称为'';指不在图形中的操作

Tensorflow 无法使用tf.train.import_meta_graph导入元图,名称为'';指不在图形中的操作,tensorflow,tensorflow-serving,returnn,Tensorflow,Tensorflow Serving,Returnn,我无法导入元图。 即使我定义了tf.placeholder(name=“data”,shape=(None,64),dtype=tf.float32),下一层也会出现错误。 我还尝试使用tf2.0。但也有同样的问题 重现问题的代码 OS Platform and Distribution: Ubuntu 18.04 tf.VERSION = 1.13.1 tf.GIT_VER

我无法导入元图。 即使我定义了tf.placeholder(name=“data”,shape=(None,64),dtype=tf.float32),下一层也会出现错误。 我还尝试使用tf2.0。但也有同样的问题

重现问题的代码

OS Platform and Distribution: Ubuntu 18.04

tf.VERSION = 1.13.1                                                            
tf.GIT_VERSION = b'v1.13.1-0-g6612da8951'                                      
tf.COMPILER_VERSION = b'v1.13.1-0-g6612da8951'
Python version: 3.6.10
GCC/Compiler version (if compiling from source): 4.8.5
CUDA/cuDNN version: 10.2
GPU model and memory: Nvidia Tesla V100, 16gb
检查点文件附加在中

堆栈跟踪

import tensorflow as tf

model_dir="./model"   # change this line to the directory where checkpoint and models are saved
checkpoint = tf.train.get_checkpoint_state(model_dir)
input_checkpoint = checkpoint.model_checkpoint_path
clear_devices = True

with tf.Session(graph=tf.Graph()) as sess:
    saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=clear_devices)
回溯(最近一次呼叫最后一次):
文件“import_meta_graph.py”,第11行,在
saver=tf.train.import_meta_图形(输入检查点+'.meta',清除设备=清除设备)
文件“/home/ubuntu/tf1.13/lib/python3.6/site packages/tensorflow/python/training/saver.py”,第1435行,在导入元图中
元图形或文件,清除设备,导入范围,**kwargs)[0]
文件“/home/ubuntu/tf1.13/lib/python3.6/site packages/tensorflow/python/training/saver.py”,第1457行,在带有返回元素的“导入”元图中
**夸尔格)
文件“/home/ubuntu/tf1.13/lib/python3.6/site packages/tensorflow/python/framework/meta_graph.py”,第852行,在import_scoped_meta_graph_中,带有返回元素
ops.prepend_name_scope(值,scope_to_prepend_to_name))
文件“/home/ubuntu/tf1.13/lib/python3.6/site packages/tensorflow/python/framework/ops.py”,第3478行,在as_graph_元素中
返回self.\u as\u graph\u element\u locked(对象、允许张量、允许操作)
文件“/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”,第3538行,位于图元素中
“图形”。%repr(名称))
KeyError:“名称‘data’指的是不在图形中的操作。”

您应该删除
graph=tf.graph()
,否则
import\u meta\u graph
会将其导入错误的图形。

您应该删除
graph=tf.graph()
,否则
import\u meta\u graph
会将其导入错误的图形。

我也在没有会话的情况下尝试过。在这种情况下,alsoI也在没有会话的情况下尝试了相同的错误。在这种情况下,同样的错误也存在
Traceback (most recent call last):
  File "import_meta_graph.py", line 11, in <module>
    saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=clear_devices)
  File "/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1435, in import_meta_graph
    meta_graph_or_file, clear_devices, import_scope, **kwargs)[0]
  File "/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1457, in _import_meta_graph_with_return_elements
    **kwargs))
  File "/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/framework/meta_graph.py", line 852, in import_scoped_meta_graph_with_return_elements
    ops.prepend_name_scope(value, scope_to_prepend_to_names))
  File "/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3478, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "/home/ubuntu/tf1.13/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3538, in _as_graph_element_locked
    "graph." % repr(name))
KeyError: "The name 'data' refers to an Operation not in the graph."