tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.34k stars 1.92k forks source link

Cannot convert AutoML Tables model to TF.JS model #3952

Closed Ark-kun closed 1 year ago

Ark-kun commented 3 years ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior

I've exported an AutoML Tables model to TF saved model. Now I'm trying to convert the model to TF JS. I get the following error: Is there any way to convert this model?

Installing collected packages: tensorflow-hub, wcwidth, prompt-toolkit, Pygments, regex, PyInquirer, tensorflow-cpu, tensorflowjs
Successfully installed PyInquirer-1.0.3 Pygments-2.7.1 prompt-toolkit-1.0.14 regex-2020.7.14 tensorflow-cpu-2.3.0 tensorflow-hub-0.7.0 tensorflowjs-2.4.0 wcwidth-0.2.5

+ tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve /tmp/inputs/Model/data /tmp/outputs/Model/data
Traceback (most recent call last):
  File "/usr/local/bin/tensorflowjs_converter", line 8, in <module>
    sys.exit(pip_main())
  File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/converter.py", line 757, in pip_main
    main([' '.join(sys.argv[1:])])
  File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/converter.py", line 761, in main
    convert(argv[0].split(' '))
  File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/converter.py", line 699, in convert
    experiments=args.experiments)
  File "/usr/local/lib/python3.6/dist-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 481, in convert_tf_saved_model
    model = load(saved_model_dir, saved_model_tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load.py", line 603, in load
    return load_internal(export_dir, tags, options)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load.py", line 649, in load_internal
    root = load_v1_in_v2.load(export_dir, tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load_v1_in_v2.py", line 263, in load
    return loader.load(tags=tags)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load_v1_in_v2.py", line 209, in load
    signature=[])
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/wrap_function.py", line 628, in wrap_function
    collections={}),
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/wrap_function.py", line 87, in __call__
    return self.call_with_variable_creator_scope(self._fn)(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/wrap_function.py", line 93, in wrapped
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load_v1_in_v2.py", line 90, in load_graph
    meta_graph_def)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py", line 1486, in _import_meta_graph_with_return_elements
    **kwargs))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/meta_graph.py", line 799, in import_scoped_meta_graph_with_return_elements
    return_elements=return_elements)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/importer.py", line 405, in import_graph_def
    producer_op_list=producer_op_list)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/importer.py", line 497, in _import_graph_def_internal
    graph._c_graph, serialized, options)  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.NotFoundError: Converting GraphDef to Graph has failed. The binary trying to import the GraphDef was built when GraphDef version was 440. The GraphDef was produced by a binary built when GraphDef version was 518. The difference between these versions is larger than TensorFlow's forward compatibility guarantee. The following error might be due to the binary trying to import the GraphDef being too old: Op type not registered 'DecodeProtoSparseV2' in binary running on retail-product-stockout-prediction-pipeline-gcs-v765m-318467729. 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.
rthadur commented 3 years ago

@Ark-kun which auto ml tables model you are trying to convert ?

tafsiri commented 3 years ago

Hi tfjs-automl doesn't currently support tables models. https://github.com/tensorflow/tfjs/tree/2ef1c1c352843af8902e29a74b73b12417283182/tfjs-automl#installation so we could tag this as a feature request.

tafsiri commented 3 years ago

cc @rthadur (updated tags)

pyu10055 commented 3 years ago

@Ark-kun The error you have shared seems to indicate that the model is generated with a previous version of TF (GraphDef version is too low). Will you be able to export your table model to saved model using TF 2.x?

Ark-kun commented 3 years ago

https://github.com/tensorflow/tfjs/tree/2ef1c1c352843af8902e29a74b73b12417283182/tfjs-automl#installation

Unfortunately AutoML refuses to export the model to any format other than tf_saved_model.

Ark-kun commented 3 years ago

@Ark-kun The error you have shared seems to indicate that the model is generated with a previous version of TF (GraphDef version is too low). Will you be able to export your table model to saved model using TF 2.x?

I suspect the opposite. "TF_GRAPH_DEF_VERSION 440 // Updated: 2020/6/22" is TF 2.3.0 - the latest released version. While "TF_GRAPH_DEF_VERSION 518 // Updated: 2020/9/8" is not released yet.

Ark-kun commented 3 years ago

@Ark-kun which auto ml tables model you are trying to convert ?

Please help me better understand the question. I've trained the model myself. I'm not sure AutoML gives me options (apart from the dataset and training time). The model is then exported as tf_saved_model as no other format works.

pyu10055 commented 3 years ago

@Ark-kun I see the autoML is producing graph_def with the latest version of TensorFlow. You can try following, after you installed tensorflowjs pip,

  1. you can uninstall the tensorflow-cpu pip
  2. install the tf-nightly-cpu pip

Then try to convert the model again.

gaikwadrahul8 commented 1 year ago

Hi, @Ark-kun

Apologize for the delayed response and we have updated our official documentation w.r.t TensorFlow.js converter here and I would request you to please give it try with latest version of tensorflow 2.12.0 and tensorflowjs 4.4.0 and check whether your issue is resolving or not ? If issue still persists please let us know and please help us with TF saved model folder to replicate the issue from our end ?

Note: Frozen model is a deprecated format and support is added for backward compatibility purpose. Thank you!

google-ml-butler[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] commented 1 year ago

Closing as stale. Please @mention us if this needs more attention.