Develop ML in the Browser
Run Existing models
Use TensorFlow.js model converters to run pre-existing TensorFlow models right in the browser.
Retrain Existing models
Retrain pre-existing ML models using sensor data connected to the browser, or other client-side data.
About this repo
This repository contains the logic and scripts that combine two packages:
- TensorFlow.js Core, a flexible low-level API, formerly known as deeplearn.js.
- TensorFlow.js Layers, a high-level API which implements functionality similar to Keras.
If you care about bundle size, you can import those packages individually.
Migrating from deeplearn.js
See these release notes for how to migrate from deeplearn.js to TensorFlow.js.
via Script Tag
Add the following code to an HTML file:
<!-- Load TensorFlow.js --><!-- Place your code in the script tag below. You can also use an external .js file -->
Open up that html file in your browser and the code should run!
Add TensorFlow.js to your project using yarn or npm. Note: Because
we use ES2017 syntax (such as
import), this workflow assumes you are using a modern browser or a bundler/transpiler
to convert your code to something older browsers understand. See our
to see how we use Parcel to build
our code. However you are free to use any build tool that you prefer.
;// Define a model for linear regression.const model = tf;model;// Prepare the model for training: Specify the loss and the optimizer.model;// Generate some synthetic data for training.const xs = tf;const ys = tf;// Train the model using the data.model;
Importing pre-trained models
We support porting pre-trained models from: