TensorflowJS converted model throwing "Cannot read property 'producer' of undefined" error

Hi all, I was following this tutorial below, and tried converting the saved model (tf SavedModel) to TensorflowJS format (model.json) using tensorflow_converter. Reason I am doing this rather than running MobileBERT directly from tfhub on TensorflowJS is because I plan to train this model on my own dataset.

https://www.tensorflow.org/text/tutorials/classify_text_with_bert

The conversion works, and I loaded my converted in Javascript using tf.loadGraphModel. However doing so I am met with an error “TypeError: Cannot read property ‘producer’ of undefined" on browser console”. I did my Googling and found out it was due to the usage of Functional apis. Some said using tf.loadLayersModel work, but when I tried it gave me error saying “could be due to the Keras Functional api usage”.

Any ideas how I can convert that to be runnable on browser? I am not too sure how I can change the Functional api usage to Sequential etc as I am pretty new to it.

Welcome to the community and thanks for posting your question. Let me check and get back to you what may be causing this. In the meantime do you have your code hosted anywhere so we can replicate the error and inspect it eg Glitch.com or Codepen.io?

Thank you! Sorry for the late response, had internet issue yesterday.

I have uploaded my training script, TFJS script and my models into my Github repo here:
https://github.com/jonathanlawhh/tfjs-producer

Nothing fancy and nothing much changed from both TFJS and BERT tutorial, except for the data loading part in Python.

Hello again! Sorry for slight delay. Was discussing with our wider team to figure out what to do here.

Looking at the codelab you linked to it seems to be using hub.kerasLayer which we do not support currently.

The team asked me if you could open a new issue using the following link to help us to track this:

Depending what you are trying to do precisely here you may find my other learning paths on text classification for TFJS useful here:

Path 1: Get started with comment-spam detection  |  Google for Developers
Path 2: Go further with comment spam detection  |  Google for Developers

Thank you.

Hi Jason, no worries.

Thank you for looking into it, I have opened a new issue accordingly here:
https://github.com/tensorflow/tfjs/issues/5409

The 2 path you shared has definitely helped me a lot! Will be trying it out to understand more.
Thank you once again

1 Like

Most welcome and good luck with your future hacking! Look forward to seeing your future creations - do share with us what you end up making if you are able :slight_smile: