A TensorFlow.js Graph Model Converter


11 Versions


Minor Patch Release Changes

Users reported errors when trying to convert Keras models (#27, #28). This patch addresses these issues by checking the model format prior to parsing and converting it. If the detected format differs from the expected TFJS graph model format, a (hopefully) more helpful error message is displayed instead of a stack trace, e.g.:

> tfjs_graph_converter keras-model.json /home/user/models/ --output_format=tf_saved_model
> TensorFlow.js Graph Model Converter

Graph model:    keras-model.json
Output:         /home/user/models/
Target format:  tf_saved_model

Converting.... Error: The model is a KERAS layers-model.
This converter only handles GRAPH models.
You can load and convert Keras models directly (using Python):

        import tensorflowjs as tfjs

        model = tfjs.converters.load_keras_model("keras-model.json")"/home/user/models")

Via pypi: pip install -U tfjs-graph-converter

From source directory: pip install .


Minor Bugfix Release Bugfixes
  • Tensorflow log message spamming wasn't suppressed as it's supposed to
  • enabled CUDA GPU could cause the converter to freeze mid-conversion
  • source code: some type hints were missing or wrong

Via pypi: pip install -U tfjs-graph-converter

From source directory: pip install .


TFJS Graph Model Converter 1.4.0

This release adds a new flag for improved model compatibility with TensorflowJS for NodeJS. Converted models that have int64 inputs aren't supported by tf.node. Using the new flag --compat_mode, the converted model will now convert the input datatype to be compatible with TFJS ≤v2.4.0.

  • New flag --compat_mode / -c for TFJS compatibility
Fixed Issues
  • Fixed issue #23

Use pip install -U tfjs-graph-converter to install or upgrade to the current version


TFJS Graph Converter 1.3.1

This is a minor patch that fixes an issue with certain models that would prevent these models to be converted.

  • Fixed issue #21 by supporting models with mismatching tensor data and graph nodes (e.g. toxicity)

To update an existing installation you can use

pip install -U tfjs-graph-model-converter




Bug Fixes

This release fixes an issue (#15) with signature generation if the model doesn't contain signature meta data and uses dynamic tensor dimensions.


Some models (e.g. posenet/resnet50) don't contain signature meta data. In this case, the converter tries to "guess" the correct model signature.

This works by identifying inputs and outputs and selecting the tensor dimensions accordingly. Unfortunately, due to a coding error, unspecified (i.e. dynamic) dimensions where ignored instead of written as "-1" as per TF conventions. This lead to a mismatch in (output-) tensor dimensions.

Another minor issue arose from naming. While models with proper signature meta data used the tensor name (e.g. including channel id) as key, SavedModel signatures usually don't include the channel id. This has been fixed as well, so even if the signature is taken directly from the model itself, any channel ids will be removed.


This release fixes a compatibility issue with the latest versions (v2.2 and v2.3) of tensorflow (see #14).



Bug Fixes
  • Specifying SavedModel-tags on the command line resulted in tags being broken into individual letters

Big thanks to PapaEcureuil for finding the bug and submitting the fix!


Version 1.0 Release 🎉

This is a big one. First of all, thanks to the feedback I received, this package can now be found on PyPi. Installing via pip install tfjs-graph-converter is now possible 👍

Breaking Changes
  • package name changed from tfjs_graph_converter to tfjs-graph-converter; make sure to use pip uninstall tfjs_graph_converter before upgrading to this release
  • Added support for models that use PReLU activation
  • Added additional graph optimisation (since models may now be rewritten)
  • Added complete suite of unit tests covering all public functions
  • Updated the documentation to include most modules
  • Package now available on PyPi
  • Extended API to include functions for wrapping loaded models in TF2 functions
Bug fixes
  • Reverted a change that altered the return value of load_graph_model() from tf.Graph to GraphDef protocol message, which caused problems for some users
  • Fixed a bug in node naming that could have lead to failed conversions