patlevin / tfjs-to-tf

A TensorFlow.js Graph Model Converter
MIT License
138 stars 18 forks source link

json_format.ParseError while converting Tfjs graph model into tensorflow saved model #27

Closed AjayrajSingh closed 3 years ago

AjayrajSingh commented 3 years ago

I run this code: !tfjs_graph_converter /content/ /content/model.pb --output_format=tf_saved_model

and getting this error I'm getting: TensorFlow.js Graph Model Converter

Graph model: /content/ Output: /content/model.pb Target format: tf_saved_model

Converting.... Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/google/protobuf/json_format.py", line 528, in _ConvertFieldValuePair [f.json_name for f in message_descriptor.fields])) google.protobuf.json_format.ParseError: Message type "tensorflow.GraphDef" has no field named "class_name". Available Fields(except extensions): ['node', 'versions', 'version', 'library']

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/tfjs_graph_converter", line 8, in sys.exit(pip_main()) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/converter.py", line 214, in pip_main main([' '.join(sys.argv[1:])]) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/converter.py", line 225, in main convert(argv[0].split(' ')) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/converter.py", line 199, in convert compat_mode=args.compat_mode) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/api.py", line 418, in graph_model_to_saved_model compat_mode) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/api.py", line 294, in load_graph_model_and_signature return _convert_graph_model_to_graph(model_json, model_path, compat_mode) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/api.py", line 263, in _convert_graph_model_to_graph graph_def = _convert_graph_def(topology) File "/usr/local/lib/python3.6/dist-packages/tfjs_graph_converter/api.py", line 130, in _convert_graph_def return ParseDict(message_dict, tf.compat.v1.GraphDef()) File "/usr/local/lib/python3.6/dist-packages/google/protobuf/json_format.py", line 454, in ParseDict parser.ConvertMessage(js_dict, message) File "/usr/local/lib/python3.6/dist-packages/google/protobuf/json_format.py", line 485, in ConvertMessage self._ConvertFieldValuePair(value, message) File "/usr/local/lib/python3.6/dist-packages/google/protobuf/json_format.py", line 596, in _ConvertFieldValuePair raise ParseError(str(e)) google.protobuf.json_format.ParseError: Message type "tensorflow.GraphDef" has no field named "class_name". Available Fields(except extensions): ['node', 'versions', 'version', 'library']

[Using Google Colab][Converting Teachable machine pose model to Tensorflow Saved Model]

patlevin commented 3 years ago

Make sure your model isn't a TFJS layer model. This converter only supports TFJS graph models as input.

You can load and save TFJS layer models directly without using a converter like so:

import tensorflowjs as tfjs

model = tfjs.converters.load_keras_model('./content/')
model.save('./content/saved_model')

Did this solve the issue?

AjayrajSingh commented 3 years ago

Yeah, this magically solved my problem, I wasn't aware that it was a layer model. Thank you very much for your help and this awesome tool.