AutoML使用Tensorflow生成的加载模型会引发“未注册'Op类型'ParseExampleV2”

问题描述 投票:0回答:1

因此,基本上,我试图加载使用带有张量流的AutoML表训练的模型。训练模型后,可以将其导出到Google Storage测试和使用->用户模型->容器。在本地下载后,模型文件在我的文件系统中如下所示:

    model/
    ├── assets
    │   ├── 14_vocab
    │   ├── 15_vocab
    │   ...
    │   ├── 7_vocab
    │   └── 8_vocab
    ├── saved_model.pb
    └── variables
        ├── variables.data-00000-of-00001
        └── variables.index

我试图以几种方式加载模型

尝试1

使用tensorflow==2.0,我尝试像这样导入模型:

   import tensorflow as tf

   loaded = tf.saved_model.load("./model/")

这给了我以下错误:


    tensorflow.python.framework.errors_impl.NotFoundError: Op type not registered 'ParseExampleV2' in binary running on hostname. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.

尝试2

使用tensorflow==1.13tensorflow==1.14tensorflow==1.15,我尝试了以下代码段:

   import tensorflow as tf

   with tf.Session(graph=tf.Graph()) as sess:
       tf.saved_model.loader.load(
           sess, [tf.saved_model.tag_constants.SERVING], "./model/"
       )

   # Also tried it this way
   from tensorflow.contrib import predictor

   loaded = predictor.from_saved_model("./model/", signature_def_key='predict')

这会引发类似的错误:

    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    <ipython-input-69-d51c805f9e16> in <module>
          1 with tf.Session(graph=tf.Graph()) as sess:
          2     tf.saved_model.loader.load(
    ----> 3         sess, [tf.saved_model.tag_constants.SERVING], PATH_TO_MODEL
          4     )

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
        322               'in a future version' if date is None else ('after %s' % date),
        323               instructions)
    --> 324       return func(*args, **kwargs)
        325     return tf_decorator.make_decorator(
        326         func, new_func, 'deprecated',

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in load(sess, tags, export_dir, import_scope, **saver_kwargs)
        267   """
        268   loader = SavedModelLoader(export_dir)
    --> 269   return loader.load(sess, tags, import_scope, **saver_kwargs)
        270 
        271 

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in load(self, sess, tags, import_scope, **saver_kwargs)
        418       `MetagraphDef` proto of the graph that was loaded.
        419     """
    --> 420     with sess.graph.as_default():
        421       saver, _ = self.load_graph(sess.graph, tags, import_scope,
        422                                  **saver_kwargs)

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in load_graph(self, graph, tags, import_scope, **saver_kwargs)
        348     """
        349     meta_graph_def = self.get_meta_graph_def_from_tags(tags)
    --> 350     with graph.as_default():
        351       return tf_saver._import_meta_graph_with_return_elements(  # pylint: disable=protected-access
        352           meta_graph_def, import_scope=import_scope, **saver_kwargs)

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/training/saver.py in _import_meta_graph_with_return_elements(meta_graph_or_file, clear_devices, import_scope, return_elements, **kwargs)
       1455                                             return_elements=None,
       1456                                             **kwargs):
    -> 1457   """Import MetaGraph, and return both a saver and returned elements."""
       1458   if context.executing_eagerly():
       1459     raise RuntimeError("Exporting/importing meta graphs is not supported when "

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/meta_graph.py in import_scoped_meta_graph_with_return_elements(meta_graph_or_file, clear_devices, graph, import_scope, input_map, unbound_inputs_col_name, restore_collections_predicate, return_elements)
        804       dictionary of all the `Variables` imported into the name scope,
        805       list of `Operation` or `Tensor` objects from the `return_elements` list).
    --> 806 
        807   Raises:
        808     ValueError: If the graph_def contains unbound inputs.

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
        505                 'in a future version' if date is None else ('after %s' % date),
        506                 instructions)
    --> 507       return func(*args, **kwargs)
        508 
        509     doc = _add_deprecated_arg_notice_to_docstring(

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/importer.py in import_graph_def(graph_def, input_map, return_elements, name, op_dict, producer_op_list)
        397 
        398   if producer_op_list is not None:
    --> 399     # TODO(skyewm): make a copy of graph_def so we're not mutating the argument?
        400     _RemoveDefaultAttrs(op_dict, producer_op_list, graph_def)
        401 

    ~/anaconda3/envs/tf/lib/python3.7/site-packages/tensorflow/python/framework/importer.py in _RemoveDefaultAttrs(op_dict, producer_op_list, graph_def)
        157   for node in graph_def.node:
        158     # Remove any default attr values that aren't in op_def.
    --> 159     if node.op in producer_op_dict:
        160       op_def = op_dict[node.op]
        161       producer_op_def = producer_op_dict[node.op]

    KeyError: 'ParseExampleV2'

显然,缺少一个名为ParseExampleV2的Op,它已由AutoML的Tables创建的模型使用,但我找不到加载它的方法。

tensorflow的GitHub存储库中有一个文件提到了此操作:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/example_parser_configuration.py

我尝试导入tensorflow.python.util,但似乎没有加载此Op ...有人知道为什么会发生这种情况吗?

python tensorflow google-cloud-automl
1个回答
0
投票

抱歉给您带来的不便。从AutoML表导出的模型只能与提供的模型服务器容器一起运行。

有关如何运行模型服务器容器的信息,请遵循此处的教程:https://cloud.google.com/automl-tables/docs/model-export

© www.soinside.com 2019 - 2024. All rights reserved.