Невозможно импортировать мета-граф с помощью tf.train.import_meta_graph. Имя '' относится к операции, не входящей в граф - PullRequest
1 голос
/ 29 января 2020
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

Я не могу импортировать мета-график. Даже если я определю tf.placeholder (name = "data", shape = (None, 64), dtype = tf.float32), ошибка произойдет для следующего слоя. Я пытался использовать TF2.0 также. Но та же проблема существует.

Код для воспроизведения проблемы

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)

Файлы контрольных точек прикреплены в model.zip .

StackTrace

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."

1 Ответ

0 голосов
/ 09 февраля 2020

Вы должны удалить graph=tf.Graph(), иначе import_meta_graph импортирует его в неправильный график.

...