I've saved a model I created with Python Tensorflow. Is it possible to load this with Tensorflow.js?
Save
tf.saved_model.save(translator, 'ipa_translator',
signatures={'serving_default': translator.tf_translate})
Load
reloaded = tf.saved_model.load('ipa_translator')
result = reloaded.tf_translate(input_text)
I've found Tensorflow import_saved_model which looks like it'll handle the conversion, but I can't figure out how it's meant to be used.
I also tried following this guide, but got errors about mismatching model types.
There appears to be a wizard script pip3 install tensorflowjs[wizard]
, when I try to install it I get no matches found: tensorflowjs[wizard]
This is the model that I want to convert if that helps: https://colab.research.google.com/drive/16ge-HE2RZ6TmG9_zS2_L4dLKOO00mVRB?usp=sharing
I would appreciate any guidance at all on getting this running.
Looks like the some of the issues I was having were to do with incompatibilities between some of the libraries.
I set up a new Poetry environment. While installing tensorflow
and tensorflowjs
it flagged up some version issues with dependencies.
After I downgraded tensorflow
to 2.11
I was able to install tensorflowjs and the wizard. I had to wrap the wizard lib name in quotes so that it was recognised poetry add -D "tensorflowjs[wizard]"
.
I could then run tensorflowjs_wizard
in the terminal and follow the steps to complete the conversion.
Here's the poetry set up that worked for me.
pyproject.toml
[tool.poetry]
name = "eng_to_ipa_model"
version = "0.1.0"
[tool.poetry.dependencies]
python = ">=3.9,<3.11"
tensorflow = "2.11"
[tool.poetry.group.dev.dependencies]
tensorflowjs = {extras = ["wizard"], version = "^4.4.0"}
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
The final piece of the puzzle was about using Tensorflow v1 api, I had to migrate the script to v2, which was painful to say the least.