patlevin / tfjs-to-tf

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

google.protobuf.json_format.ParseError: Message type "tensorflow.GraphDef" has no field named "class_name" #28

Closed msyazwan closed 3 years ago

msyazwan commented 3 years ago

Hi,

I'm trying to convert my tfjs model (downloaded from Teachable Machine) to tf model with .pb format.

I ran the command below and get the following error.

_google.protobuf.json_format.ParseError: Message type "tensorflow.GraphDef" has no field named "classname".

(venv) C:\Users\moham\Desktop\fastapi>tfjs_graph_converter .\tfjs_model\model.json .\tfjs2tf_model\my_model --output_format tf_saved_model
TensorFlow.js Graph Model Converter

Graph model:    .\tfjs_model\model.json
Output:         .\tfjs2tf_model\my_model
Target format:  tf_saved_model

Converting.... Traceback (most recent call last):
  File "c:\users\moham\desktop\fastapi\venv\lib\site-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 "c:\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\moham\Desktop\fastapi\venv\Scripts\tfjs_graph_converter.exe\__main__.py", line 7, in <module>
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\converter.py", line 214, in pip_main
    main([' '.join(sys.argv[1:])])
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\converter.py", line 225, in main
    convert(argv[0].split(' '))
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\converter.py", line 199, in convert
    compat_mode=args.compat_mode)
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\api.py", line 418, in graph_model_to_saved_model
    compat_mode)
  File "c:\users\moham\desktop\fastapi\venv\lib\site-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 "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\api.py", line 263, in _convert_graph_model_to_graph
    graph_def = _convert_graph_def(topology)
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\tfjs_graph_converter\api.py", line 130, in _convert_graph_def
    return ParseDict(message_dict, tf.compat.v1.GraphDef())
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\google\protobuf\json_format.py", line 454, in ParseDict
    parser.ConvertMessage(js_dict, message)
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\google\protobuf\json_format.py", line 485, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "c:\users\moham\desktop\fastapi\venv\lib\site-packages\google\protobuf\json_format.py", line 599, 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']
patlevin commented 3 years ago

Your model is 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')

Since this is the second time within just a few days this came up, I'll leave this open anyway and change the error message in the converter accordingly to avoid confusion in the future.

msyazwan commented 3 years ago

Your model is 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')

Since this is the second time within just a few days this came up, I'll leave this open anyway and change the error message in the converter accordingly to avoid confusion in the future.

Thank you so much!