So basically I am trying to load a model trained using AutoML's Tables with tensorflow. Once a model is trained, it can be exported to Google Storage going to TEST & USE -> USER YOUR MODEL -> Container. After downloading it locally, the model files look like this in my file system:
model/
├── assets
│ ├── 14_vocab
│ ├── 15_vocab
│ ...
│ ├── 7_vocab
│ └── 8_vocab
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index
I've tried to loading the model in several ways
Attempt 1
Using tensorflow==2.0, I tried importing the model like so:
import tensorflow as tf
loaded = tf.saved_model.load("./model/")
Which gives me the following error:
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.
Attempt 2
Using tensorflow==1.13, tensorflow==1.14 and tensorflow==1.15, I tried the same with the following snippet:
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')
Which raises a similar error:
---------------------------------------------------------------------------
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'
Apparently, there is a missing Op called ParseExampleV2 that's been used by the model created by AutoML's Tables, but I couldn't find a way of loading it.
There is a file in tensorflow's GitHub repository where this Op is mentioned: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/example_parser_configuration.py
I've tried importing tensorflow.python.util but it doesn't seem to load this Op... does anyone know why this could be happening?
Sorry about the inconvenience. The model exported from AutoML Tables can only run with the provided model server container.
For how to run the model server container, please follow the tutorial here: https://cloud.google.com/automl-tables/docs/model-export
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With