How can I convert a TensorFlow graph .pb file using tensorflowjs_converter?

1k Views Asked by At

when I am trying to convert my frozen model using tensorflowjs_converter I am getting this error:

macbook-pro-6:tesla james$ tensorflowjs_converter --input_format=tf_frozen_model --output_node_names='MobilenetV1/Predictions/Reshape_1' --saved_model_tags=serve /retrained_graph.pb /web_model

(example taken from their github: https://github.com/tensorflow/tfjs-converter)

This is the error I get back:

Using TensorFlow backend.
Traceback (most recent call last):
  File "/Users/james/anaconda/bin/tensorflowjs_converter", line 7, in <module>
    from tensorflowjs.converters.converter import main
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/__init__.py", line 21, in <module>
    from tensorflowjs import converters
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/converters/__init__.py", line 22, in <module>
    from tensorflowjs.converters.keras_tfjs_loader import deserialize_keras_model
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflowjs/converters/keras_tfjs_loader.py", line 25, in <module>
    import keras
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/backend/__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "/Users/james/anaconda/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 15, in <module>
    from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/node_def_pb2.py", line 15, in <module>
    from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 15, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 15, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
  File "/Users/james/anaconda/lib/python2.7/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 22, in <module>
    serialized_pb=_b('\n/tensorflow/core/framework/resource_handle.proto\x12\ntensorflow\"r\n\x13ResourceHandleProto\x12\x0e\n\x06\x64\x65vice\x18\x01 \x01(\t\x12\x11\n\tcontainer\x18\x02 \x01(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x11\n\thash_code\x18\x04 \x01(\x04\x12\x17\n\x0fmaybe_type_name\x18\x05 \x01(\tBn\n\x18org.tensorflow.frameworkB\x0eResourceHandleP\x01Z=github.com/tensorflow/tensorflow/tensorflow/go/core/framework\xf8\x01\x01\x62\x06proto3')
TypeError: __new__() got an unexpected keyword argument 'serialized_options'

The way I created this .pb file was using the tensorflow for poets image classifier. It works fine in Python (I can train and create the .pb file, and even make predictions from images. I want to convert this to using nodejs and tensorflowjs, but I cant seem to convert the .pb file into the format needed for tensorflowjs.

I decided to muck around and remove the parameters and if I just use this command: tensorflowjs_converter --help it throws the same error as above, wth?

1

There are 1 best solutions below

0
On

Please try the below code.

pip install -U protobuf

By updating the protobuf you will be able to resolve the above issue.