Library / SDK
tensorflow/tfjs avatar
tensorflow/tfjs

TensorFlow.js: A WebGL Accelerated JavaScript Library for Training and Deploying ML Models

A WebGL accelerated JavaScript library for training and deploying ML models.

19,141 stars2,028 forksTypeScriptApache-2.0

At a glance

What is it?
TensorFlow.js is an Apache-2.0 TypeScript monorepo that brings tensor computation, Keras-style layers, and model conversion to the browser and Node.js. It is a strong fit for client-side inference and small in-browser training loops, but it is not a replacement for server-side training at scale.
Who is it for?
Adopt TensorFlow.js when you need inference or light training to run inside a browser tab or a Node.js process and you can accept the constraints of the WebGL, WASM, or CPU backends. Do not adopt it as a drop-in replacement for server-side TensorFlow training on large datasets, and do not assume a SavedModel will convert without checking op coverage.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 85 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What TensorFlow.js Is Actually For

The README frames the project around four jobs: building models in the browser with the low-level linear algebra API or the higher-level layers API, running native TensorFlow under Node.js with the same API surface, running pre-existing TensorFlow models in the browser through the converter, and retraining existing models on client-side data. That last item is the one that separates it from a plain inference runtime. The pitch is not just that you can run a model in a tab, but that you can keep a small amount of training on the device where the data already lives, so sensor readings or user interactions do not have to leave the client to update the model. The audience follows from that: front-end and TypeScript engineers who want a model inside a web product without standing up a Python service, and Node.js developers who want the TensorFlow C++ runtime behind a JavaScript API rather than the Python one.

The Monorepo Is the Architecture

This repository is not a single library. The README describes it as containing the logic and scripts that combine several packages, and lists them explicitly: tfjs-core for low-level computation, tfjs-layers for a Keras-like high-level API, tfjs-data for input pipelines analogous to tf.data, tfjs-converter for importing SavedModels, tfjs-vis for in-browser visualization, and tfjs-automl for AutoML Edge models. The backends are separate packages too: a pure-JS CPU backend, a WebGL backend, a WASM backend, a WebGPU backend, a Node.js backend built on a TensorFlow C++ adapter, and a React Native backend built on an expo-gl adapter. The README states plainly that if you care about bundle size you can import those packages individually. That single sentence is the most consequential line in the document. The default @tensorflow/tfjs entry point pulls in a set of backends and the layers API; a project that only needs tensor math on the CPU can import a much smaller slice. The backend abstraction is the reason the same model code can target WebGL in a browser and the native TensorFlow runtime under Node.js, but it also means your performance characteristics are a property of the backend you register, not of the library as a whole.

Getting It Running: Script Tag and NPM

The README gives two installation paths. The script tag path loads a single file from a CDN, https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js, and then uses a global tf with no import statement. The README's example builds a one-unit dense layer with inputShape [1], compiles it with loss meanSquaredError and optimizer sgd, fits it on two tensor2d inputs, and calls model.predict(tf.tensor2d([5], [1, 1])).print() in the fit callback. The NPM path installs @tensorflow/tfjs and uses import * as tf from '@tensorflow/tfjs', with the same model code below it. The README attaches a caveat to the NPM path: because the library uses ES2017 syntax such as import, that workflow assumes a modern browser or a bundler or transpiler, and it points at the examples repository to show how Parcel is used to build the code. It also says you are free to use any build tool. That is the whole of the documented setup. There is no config file, no environment variable, and no CLI in the material provided. Backend selection and package slicing are done by choosing which package you import, which is why the package list in the README matters more than the quickstart.

Where the Backend Choice Becomes Your Problem

The README lists five browser-capable backends (CPU, WebGL, WASM, WebGPU) plus Node.js and React Native, and it offers a local benchmark tool at tfjs-benchmarks.web.app for collecting speed and memory metrics on your own device across CPU, WebGL and WASM backends. The existence of that tool is itself the admission: performance is device-dependent, and the project expects you to measure rather than trust a published figure. WebGL support varies by browser and driver, WebGPU is a newer browser surface, and the pure-JS CPU backend exists as a fallback rather than a fast path. The README does not claim any backend is universally available. For a product shipping to a broad audience, that means backend fallback logic is your responsibility, and the failure mode is quiet: a model that runs acceptably on your development machine may fall back to the CPU path on a user's device and stall the main thread. There is a multi-device benchmark tool referenced in the README for collecting the same metrics across a set of remote devices, which is the closest thing to guidance on this, and it still leaves the decision to you.

Model Conversion Is a Real Gate, Not a Formality

The README states that TensorFlow.js supports porting pre-trained models from TensorFlow SavedModel and from Keras, and it links to dedicated tutorials for each. The converter package, tfjs-converter, is listed among the APIs. What the README does not do is promise that any SavedModel converts cleanly. Conversion depends on the ops your graph uses, and the README's own op listing is truncated in the material available here, so the supported-op surface cannot be confirmed from this document alone. Treat the converter as a checkpoint in your plan rather than a step you schedule at the end. A model with custom ops, or one exported from a training pipeline that uses operations outside the supported set, is the case where this tool is the wrong choice, and you will usually discover that after you have already committed to a browser deployment. The retraining story has a related constraint: the README describes retraining on sensor data connected to the browser or other client-side data, which is a small-data framing. Fine-tuning a large model in a tab is not what the documentation describes.

How It Compares to ONNX Runtime Web

ONNX Runtime Web is the closest alternative for the browser-inference half of this project. The difference is in the model format and the surrounding toolchain. TensorFlow.js is built around TensorFlow SavedModel and Keras imports through its own converter, and it ships a training API in JavaScript (tfjs-layers, tfjs-core) alongside inference. ONNX Runtime Web consumes ONNX graphs and is oriented toward running models exported from whatever framework produced them, with execution providers for WebGL, WebAssembly and WebGPU. If your models already live in the TensorFlow ecosystem and you want the option to train or fine-tune in the browser, TensorFlow.js keeps that path open in one API. If your models come from PyTorch or another exporter and you only need inference, the ONNX route avoids a TensorFlow-specific conversion step. Neither choice removes the backend-support question, and neither removes the need to measure on target devices. The training capability is the clearest differentiator on the TensorFlow.js side; the format neutrality is the clearest on the ONNX side.

Maintenance, Releases and Licence

The repository is not archived, the default branch is master, and the most recent release in the supplied material is tfjs-v4.22.0 from October 2024, following tfjs-v4.21.0 in September 2024 and tfjs-v4.20.0 in June 2024. That cadence suggests active maintenance, though the material does not describe a support window or a deprecation policy for older majors, so pinning a version and reading the release notes before upgrading is the only defensible approach from what is documented here. The practical upgrade cost is the split-package structure: a major bump can touch tfjs-core, tfjs-layers, tfjs-converter and whichever backend package you depend on, and if you imported individual packages to control bundle size you are tracking several version numbers rather than one. The licence is Apache-2.0, a permissive licence that permits commercial use and modification and includes an explicit patent grant, with the usual obligations around retaining notices and stating changes. That is a description of the licence identifier, not legal advice; if the patent grant or notice requirements matter to your organisation, have counsel read the LICENSE file in the repository.

Editorial conclusion

Adopt TensorFlow.js when you need inference or light training to run inside a browser tab or a Node.js process and you can accept the constraints of the WebGL, WASM, or CPU backends. Do not adopt it as a drop-in replacement for server-side TensorFlow training on large datasets, and do not assume a SavedModel will convert without checking op coverage. Verify first that your target model converts with the tfjs-converter, that your chosen backend actually initializes in your target browser, and that your bundle budget survives importing @tensorflow/tfjs rather than the individual packages.

Official sources

  1. License: Apache-2.0
  2. Project website
  3. README
  4. Releases
  5. tensorflow/tfjs on GitHub
Community notes

Community notes