Skip to main content

A tensorflowjs Graph Model Converter

Project description

TensorFlow.js Graph Model Converter

TFJS Graph Converter Logo

The purpose of this library is to import TFJS graph models into Tensorflow. This allows you to use TensorFlow.js models with Python in case you don't have access to the original formats or the models have been created in TFJS.

Disclaimer

I'm neither a Python developer, nor do I know TensorFlow or TensorFlow.js. I created this package solely because I ran into an issue when trying to convert a pretrained TensorFlow.js model into a different format. I didn't have access to the pretrained original TF model and didn't have the resources to train it myself. I soon learned that I'm not alone with this issue so I sat down and wrote this little library.

If you find any part of the code to be non-idiomatic or know of a simpler way to achieve certain things, feel free to let me know, since I'm a beginner in both Python and especially TensorFlow (used it for the very first time in this very project).

Prerequisites

  • tensorflow 2.1+
  • tensorflowjs 1.5.2+

Compatibility

The converter has been tested with tensorflowjs v1.7.2 and tensorflow v2.1. The Python version used was Python 3.7.7.

Installation

pip install tfjs-graph-converter

Usage

After the installation, you can run the packaged tfjs_graph_converter binary for quick and easy model conversion.

Positional Arguments

Positional Argument Description
input_path Path to the TFJS Graph Model directory containing the model.json
output_path For output format "tf_saved_model", a SavedModel target directory. For output format "tf_frozen_model", a frozen model file.

Options

Option Description
-h, --help Show help message and exit
--output_format Use tf_frozen_model (the default) to save a Tensorflow frozen model. tf_saved_model exports to a Tensorflow SavedModel instead.
--saved_model_tags Specifies the tags of the MetaGraphDef to save, in comma separated string format. Defaults to "serve". Applicable only if --output format is tf_saved_model
-v, --version Shows the version of the converter and its dependencies.
-s, --silent Suppresses any output besides error messages.

Alternatively, you can create your own converter programs using the module's API. The API is required to accomplish more complicated tasks, like packaging multiple TensorFlow.js models into a single SavedModel.

Example

To convert a TensorFlow.js graph model to a TensorFlow frozen model (i.e. the most common use case?), just specify the directory containing the model.json, followed by the path and file name of the frozen model like so:

tfjs_graph_converter path/to/js/model path/to/frozen/model.pb

Usage from within Python

The package installs the module tfjs_graph_converter, which contains all the functionality used by the converter script. You can leverage the API to either load TensorFlow.js graph models directly for use with your TensorFlow program (e.g. for inference, fine-tuning, or extending), or use the advanced functionality to combine several TFJS models into a single SavedModel. The latter is only supported using the API (it's just a single function call, though, so don't panic 😉)

API Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfjs-graph-converter-1.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfjs_graph_converter-1.1.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file tfjs-graph-converter-1.1.0.tar.gz.

File metadata

  • Download URL: tfjs-graph-converter-1.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for tfjs-graph-converter-1.1.0.tar.gz
Algorithm Hash digest
SHA256 cfec3f590072b05bc9bb3302876679a1dbd748c4e00b3afbdb06d88dfb19d6da
MD5 839d072f6ef3a2668ea0e99f91521682
BLAKE2b-256 8e21f5d5ce5731c9b2315ce0057ce722402377d94e0b1e786d1137b2b4769fa6

See more details on using hashes here.

File details

Details for the file tfjs_graph_converter-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tfjs_graph_converter-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for tfjs_graph_converter-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a5c4e95adf4f46efb9111ce0e4fa74de3ffa7a905e242cf8cce0993d08f9b8e
MD5 f9d230cd2ef8c6da18f6e96252d7aa7e
BLAKE2b-256 238b019dea8a381e6b42a3b3461d600fc605b2a7c3aa135ebf9d50479d13eb19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page