Skip to content

apply_saved_models for Tensorflow 2.7 models #282

@agrimabahl

Description

@agrimabahl

Hi 👋

My application uses the apply_saved_models api within tf-transform to run inference on tensorflow models.
For a TF2 model from tf-hub, when running apply_saved_models I get the following error -

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-30-594dff228f07> in <module>()
     19       constant_graph_def,
     20       input_map=inputs,
---> 21       return_elements=output_tensor_names + loaded_initializer_op_names)
     22

/usr/local/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
    550                 'in a future version' if date is None else ('after %s' % date),
    551                 instructions)
--> 552       return func(*args, **kwargs)
    553
    554     doc = _add_deprecated_arg_notice_to_docstring(

/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/importer.py in import_graph_def(***failed resolving arguments***)
    410       return_elements=return_elements,
    411       name=name,
--> 412       producer_op_list=producer_op_list)
    413
    414

/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/importer.py in _import_graph_def_internal(graph_def, input_map, return_elements, validate_colocation_constraints, name, producer_op_list)
    492   options = scoped_options.options
    493   _PopulateTFImportGraphDefOptions(options, prefix, input_map, return_elements,
--> 494                                    validate_colocation_constraints)
    495
    496   # _ProcessNewOps mutates the new operations. _mutation_lock ensures a

/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/importer.py in _PopulateTFImportGraphDefOptions(options, prefix, input_map, return_elements, validate_colocation_constraints)
    227       src_name, src_idx = _ParseTensorName(input_src)
    228       src_name = compat.as_str(src_name)
--> 229       dst_output = input_dst._as_tf_output()  # pylint: disable=protected-access
    230       c_api.TF_ImportGraphDefOptionsAddInputMapping(options, src_name, src_idx,
    231                                                     dst_output)

/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in _as_tf_output(self)
   1330   def _as_tf_output(self):
   1331     raise NotImplementedError(
-> 1332         "_as_tf_output not supported when eager execution is enabled.")
   1333
   1334   def eval(self, feed_dict=None, session=None):

NotImplementedError: _as_tf_output not supported when eager execution is enabled.

is there an alternative API more suited to TF2 models since apply_saved_models can only be used with TF2 behavior disabled and TF2 does not support GraphDefs.

Thank you!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions