tensorflow: KeyError: 'ParallelInterleaveDataset' in Tf >= 1.13 (mkl/gpu)

OS Platform and Distribution - Linux Ubuntu 16.04) TensorFlow installed from Anaconda dist 3.6. TensorFlow version 1.13-mkl / 1.13-gpu Python version: Python 3.6.6 :: Anaconda, Inc.

Describe the current behavior* There is an import error on tf.train.import_meta_graph() while importing one of the models from the model zoo / coral_ready model. The import works fine on 1.12 but not >= 1.13 ver Describe the expected behavior The model should be otherwise loaded with the placeholder and graph Code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. The model was taken from here - [Model Link] (http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03.tar.gz) Model Website

Other info / logs

Traceback (most recent call last):
  File "ssd_test.py", line 6, in <module>
    model = Importers.ImportMeta(dir_path=model_dir, quantizer='LINEAR')
  File "/home/local/SRI/e32640/Documents/aiquantizer/Importers.py", line 89, in __init__
    self.import_graph()
  File "/home/local/SRI/e32640/Documents/aiquantizer/Importers.py", line 118, in import_graph
    clear_devices=True)
  File "/home/local/SRI/e32640/anaconda3/envs/tf13-gpu/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/local/SRI/e32640/anaconda3/envs/tf13-gpu/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1457, in _import_meta_graph_with_return_elements
    **kwargs))
  File "/home/local/SRI/e32640/anaconda3/envs/tf13-gpu/lib/python3.6/site-packages/tensorflow/python/framework/meta_graph.py", line 806, in import_scoped_meta_graph_with_return_elements
    return_elements=return_elements)
  File "/home/local/SRI/e32640/anaconda3/envs/tf13-gpu/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/local/SRI/e32640/anaconda3/envs/tf13-gpu/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 399, in import_graph_def
    _RemoveDefaultAttrs(op_dict, producer_op_list, graph_def)
  File "/home/local/SRI/e32640/anaconda3/envs/tf13-gpu/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", line 159, in _RemoveDefaultAttrs
    op_def = op_dict[node.op]
KeyError: 'ParallelInterleaveDataset'

UPDATE [1]: The following code snippet is used for importing the model downloaded from the model zoo

model_dir = 'ssd_mobilenet_v2/'
meta = glob.glob(model_dir + "*.meta")[0]
ckpt = meta.replace('.meta', '').strip()

graph = tf.Graph()
with graph.as_default():
    with tf.Session() as sess:
        reader = tf.train.import_meta_graph(meta, clear_devices=True)
        reader.restore(sess, ckpt)
        writer = tf.summary.FileWriter(logdir=model_dir, graph=tf.get_default_graph())  # write to event
        writer.flush()
        vari = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
        for var in vari:
            print(var.name, "\n")

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (12 by maintainers)

Most upvoted comments

@jdcast @jsimsa I had the same issue, but somehow fixed it by the following code on TF 1.14.0. I hope this would be helpful to you.

import os

from google.protobuf import text_format
import tensorflow as tf


def read_meta_graph_file(filename):
    # https://github.com/tensorflow/tensorflow/blob/87989f69597d6b2d60de8f112e1e3cea23be7298/tensorflow/python/framework/meta_graph.py#L670  # NOQA
    meta_graph_def = tf.MetaGraphDef()
    if not tf.gfile.Exists(filename):
        raise IOError("File %s does not exist." % filename)
    file_content = tf.gfile.GFile(filename, "rb").read()
    try:
        meta_graph_def.ParseFromString(file_content)
        return meta_graph_def
    except Exception:
        pass

    try:
        text_format.Merge(file_content.decode("utf-8"), meta_graph_def)
    except text_format.ParseError as e:
        raise IOError("Cannot parse file %s: %s." % (filename, str(e)))

    return meta_graph_def


# https://raw.githubusercontent.com/tensorflow/tensorflow/87989f69597d6b2d60de8f112e1e3cea23be7298/tensorflow/core/ops/compat/ops_history.v1.pbtxt  # NOQA
# EDIT HERE
_CONVERSION = {
    'ParallelInterleaveDataset': 'ExperimentalParallelInterleaveDataset',
    'MapAndBatchDatasetV2': 'ExperimentalMapAndBatchDataset',
}


def _rename_op(s):
    for k, v in _CONVERSION.items():
        if k in s:
            return s.replace(k, v)
    return s


def convert(input_file, output_file):
    meta_graph_def = read_meta_graph_file(input_file)
    for node in meta_graph_def.graph_def.node:
        node.name = _rename_op(node.name)
        node.op = _rename_op(node.op)
        node.input[:] = [_rename_op(s) for s in node.input]
    tf.io.write_graph(meta_graph_def,
                      os.path.dirname(output_file),
                      os.path.basename(output_file),
                      as_text=False)


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--meta_file", required=True)
    parser.add_argument("--output_file", required=True)
    parser.add_argument("--check", action="store_true")
    args = parser.parse_args()
    convert(args.meta_file, args.output_file)
    if args.check:
        _saver = tf.train.import_meta_graph(args.output_file)

I know this is an old issue, but would anyone know what the correct conversion would be for ExperimentalFunctionBufferingResource? I can’t find it in the file linked.

I’m trying to import a checkpoint trained in V1.12 into V2.8.

@jdcast @jsimsa I had the same issue, but somehow fixed it by the following code on TF 1.14.0. I hope this would be helpful to you.

import os

from google.protobuf import text_format
import tensorflow as tf


def read_meta_graph_file(filename):
    # https://github.com/tensorflow/tensorflow/blob/87989f69597d6b2d60de8f112e1e3cea23be7298/tensorflow/python/framework/meta_graph.py#L670  # NOQA
    meta_graph_def = tf.MetaGraphDef()
    if not tf.gfile.Exists(filename):
        raise IOError("File %s does not exist." % filename)
    file_content = tf.gfile.GFile(filename, "rb").read()
    try:
        meta_graph_def.ParseFromString(file_content)
        return meta_graph_def
    except Exception:
        pass

    try:
        text_format.Merge(file_content.decode("utf-8"), meta_graph_def)
    except text_format.ParseError as e:
        raise IOError("Cannot parse file %s: %s." % (filename, str(e)))

    return meta_graph_def


# https://raw.githubusercontent.com/tensorflow/tensorflow/87989f69597d6b2d60de8f112e1e3cea23be7298/tensorflow/core/ops/compat/ops_history.v1.pbtxt  # NOQA
# EDIT HERE
_CONVERSION = {
    'ParallelInterleaveDataset': 'ExperimentalParallelInterleaveDataset',
    'MapAndBatchDatasetV2': 'ExperimentalMapAndBatchDataset',
}


def _rename_op(s):
    for k, v in _CONVERSION.items():
        if k in s:
            return s.replace(k, v)
    return s


def convert(input_file, output_file):
    meta_graph_def = read_meta_graph_file(input_file)
    for node in meta_graph_def.graph_def.node:
        node.name = _rename_op(node.name)
        node.op = _rename_op(node.op)
        node.input[:] = [_rename_op(s) for s in node.input]
    tf.io.write_graph(meta_graph_def,
                      os.path.dirname(output_file),
                      os.path.basename(output_file),
                      as_text=False)


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--meta_file", required=True)
    parser.add_argument("--output_file", required=True)
    parser.add_argument("--check", action="store_true")
    args = parser.parse_args()
    convert(args.meta_file, args.output_file)
    if args.check:
        _saver = tf.train.import_meta_graph(args.output_file)

In tensorflow 1.12, also has the problem. How could I give a workaround. Thanks!

Do you mean FixedLengthRecordDatasetV2? That operation has not been renamed, so I suspect that is a different issue. Please create a separate issue with details on how to reproduce the error.