TensorFlow.js is an open-source JavaScript library for training and deploying machine learning models in the browser and on Node.js. It provides layered APIs, model converters, and several compute backends.
Overview
TensorFlow.js is an open-source, hardware-accelerated JavaScript library for training and deploying machine learning models. Developers can run machine learning directly in the browser or under the Node.js runtime using the same APIs, and the project is part of the broader TensorFlow ecosystem aimed at JavaScript and web development.
The library ships several APIs for different levels of abstraction. TensorFlow.js Core offers a flexible low-level API for neural networks and numerical computation. TensorFlow.js Layers provides a high-level API with functionality similar to Keras. TensorFlow.js Data loads and prepares data in a way analogous to tf.data. The Converter imports TensorFlow SavedModels into TensorFlow.js, while TensorFlow.js Vis adds in-browser visualization for models. TensorFlow.js AutoML loads and runs models produced by AutoML Edge.
Compute backends include a pure JavaScript CPU backend for the browser and Node.js, plus browser backends for WebGL, WebAssembly, and WebGPU. On Node.js, native TensorFlow runs through a C++ adapter. A React Native integration uses an expo-gl adapter. Individual packages can be imported separately when bundle size matters.
You can install TensorFlow.js from NPM with a bundler or load it via script tags in HTML. Pre-trained models are available for common tasks, and existing TensorFlow, Keras, and SavedModel checkpoints can be converted for use in JavaScript. Tutorials, examples, and demos illustrate end-to-end workflows such as transfer learning with your own data or running converted Python models in the browser.
Key features
- Low-level Core API for neural networks
- High-level Layers API similar to Keras
- Data loading and preparation API
- SavedModel and Keras model conversion
- In-browser model visualization
- WebGL, WASM, and WebGPU browser backends
- Node.js execution via TensorFlow C++ adapter
- AutoML Edge model loading APIs
Use cases
- Training machine learning models in JavaScript
- Running inference in the browser
- Deploying models on Node.js
- Converting existing TensorFlow or Keras models
- Retraining models with client-side data