使用 Tensorflow 生成的 AutoML 加载模型会引发"Op type not registered 'ParseExampleV2"



所以基本上我正在尝试加载使用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的操作,它已被 AutoML 的表创建的模型使用,但我找不到加载它的方法。

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

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

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

有关如何运行模型服务器容器,请按照此处的教程进行操作:https://cloud.google.com/automl-tables/docs/model-export

根据@helin-wang的评论,我看了一下谷歌提供的Docker镜像。它运行一个进行预测的tensorflow-server和一个tornado服务器来提供它。

我可以确认每次都失败tfjs_converttfjs_wizard转换。

BigQuery ML ML 现在支持 AutoML Tables 集成(测试版(

相关内容

最新更新