Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Tensorflow Tfjs Python Converter

From Leeroopedia


Metadata
Source TensorFlow.js, tfjs-converter README
Domains Infrastructure, Model_Conversion
Date 2026-02-10 00:00 GMT

Overview

Python environment with tensorflowjs pip package for converting TensorFlow/Keras/JAX models to browser-deployable formats.

Description

A Python environment required for the model conversion pipeline. The tensorflowjs pip package includes two primary tools:

  • tensorflowjs_converter — CLI tool for converting models from various TensorFlow formats to TensorFlow.js web-friendly format.
  • tensorflowjs_wizard — Interactive wizard that guides users through the conversion process step by step.

The converter supports the following input formats:

  • TF SavedModel — Standard TensorFlow 2.x serialization format
  • TF Hub modules — Pre-trained models from TensorFlow Hub
  • Keras HDF5 — Legacy Keras .h5 model files
  • tf.keras SavedModel — Keras models saved via tf.keras.Model.save()
  • Frozen Model (deprecated) — TensorFlow 1.x frozen graph format
  • JAX/Flax models — Converted programmatically via jax_conversion.convert_jax()

Output formats include tfjs_graph_model (optimized for inference) and tfjs_layers_model (supports fine-tuning and transfer learning). Not all input-output format pairs are supported.

Usage

Use this environment when converting pre-trained Python models to TensorFlow.js web-friendly format. This is a required prerequisite for the Pretrained_Model_Conversion workflow. The conversion step must be performed in a Python environment before the resulting model artifacts can be loaded in a browser or Node.js environment.

System Requirements

Requirement Details
Python 3.7.10 recommended (check tf-nightly-cpu-2.0-preview availability for your version)
pip Latest version recommended
Isolation Docker container or virtual environment strongly recommended
OS Linux, macOS, or Windows with pip

Note: The converter documentation recommends running in a Docker container or virtual environment to avoid dependency conflicts with system-level TensorFlow installations.

Dependencies

Basic Installation

pip install tensorflowjs

With Interactive Wizard

pip install tensorflowjs[wizard]

The [wizard] extra installs additional dependencies required for the interactive tensorflowjs_wizard tool.

Key Internal Dependencies

  • TensorFlow — The tensorflowjs package pulls in a compatible version of TensorFlow as a dependency
  • Protocol Buffers — For model serialization and deserialization
  • NumPy — For tensor data manipulation during conversion

Credentials

None required for basic model conversion. All operations are local.

Quick Install

# Recommended: use a virtual environment
python -m venv tfjs_env
source tfjs_env/bin/activate  # Linux/macOS
# tfjs_env\Scripts\activate   # Windows

# Install with wizard support
pip install tensorflowjs[wizard]

# Verify installation
tensorflowjs_converter --version

Code Evidence

From tfjs-converter/README.md

The converter documentation explicitly recommends isolation:

"Please make sure that you run in a Docker container or a virtual environment."

And specifies the recommended Python version:

"Most of the times, this means that you have to use Python 3.7.10
in your local environment."

Example Conversion Command

# Convert a TF SavedModel to tfjs_graph_model
tensorflowjs_converter \
    --input_format=tf_saved_model \
    --output_format=tfjs_graph_model \
    /path/to/saved_model \
    /path/to/output

# Convert a Keras HDF5 model to tfjs_layers_model
tensorflowjs_converter \
    --input_format=keras \
    --output_format=tfjs_layers_model \
    /path/to/model.h5 \
    /path/to/output

Common Errors

Error Cause Solution
TensorFlow version conflicts System TensorFlow clashes with converter requirements Use a virtual environment or Docker container to isolate dependencies.
Unsupported ops Model contains operations not implemented in TensorFlow.js Check supported_ops.md for the list of supported operations. Consider simplifying the model or using custom op registration.
Recurrent layers (LSTM) not supported in graph model Graph model format does not support stateful recurrent layers Convert to tfjs_layers_model format instead of tfjs_graph_model for models with LSTM/GRU layers.
Session bundle format deprecated Attempting to convert a TF 1.x Session bundle Re-export the model as a SavedModel or Frozen Model first.

Compatibility Notes

Supported Input Formats

Input Format --input_format Flag Notes
TF SavedModel tf_saved_model Recommended format for TF 2.x models
TF Hub module tf_hub Loads directly from TensorFlow Hub URLs
Keras HDF5 keras Legacy .h5 files
tf.keras SavedModel tf_saved_model Keras models saved via model.save()
Frozen Model tf_frozen_model Deprecated; migrate to SavedModel
JAX/Flax Programmatic API Use jax_conversion.convert_jax() in Python

Supported Output Formats

  • tfjs_graph_model — Optimized for inference only. Loaded with tf.loadGraphModel().
  • tfjs_layers_model — Supports fine-tuning and transfer learning. Loaded with tf.loadLayersModel().

Not all input-output format combinations are supported. Session bundle format is deprecated.

Related Pages

Required By (Implementations)

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment