README.md

Getting started

deeplearn.js is an open source hardware-accelerated JavaScript library for
machine intelligence. deeplearn.js brings performant machine learning
building blocks to the web, allowing you to train neural networks in a browser
or run pre-trained models in inference mode.

We provide an API that closely mirrors the TensorFlow eager API.
deeplearn.js was originally developed by the Google Brain PAIR team to build
powerful interactive machine learning tools for the browser, but it can be used
for everything from education, to model understanding, to art projects.

TypeScript / ES6 JavaScript

Let's add a scalar value to a 1D Tensor. Deeplearn js supports broadcasting
the value of scalar over all the elements in the tensor.

import*asdlfrom'deeplearn'; // If not loading the script as a globalconsta=dl.tensor1d([1, 2, 3]);
constb=dl.scalar(2);
constresult=a.add(b); // a is not modified, result is a new tensorresult.data().then(data=>console.log(data)); // Float32Array([3, 4, 5]// Alternatively you can use a blocking call to get the data.// However this might slow your program down if called repeatedly.console.log(result.dataSync()); // Float32Array([3, 4, 5]

ES5 JavaScript

Let's do the same thing in ES5 Javascript. Remember to include the script tag to
load deeplearn.js

var a =dl.tensor1d([1, 2, 3]);
var b =dl.scalar(2);
var result =a.add(b); // a is not modified, result is a new tensor// Option 1: With a Promise.result.data().then(data=>console.log(data)); // Float32Array([3, 4, 5])// Option 2: Synchronous download of data. Blocks the UI.console.log(result.dataSync());

Development

To build deeplearn.js from source, we need to clone the project and prepare
the dev environment:

Yarn vs NPM

Generally speaking it's up to you. Yarn is fully interoperable with npm. You can either do yarn or npm install. However we use yarn, and if you are adding or removing dependencies you should use yarn to keep the yarn.lock file up to date.

Then visit http://localhost:8080/demos/nn-art/. The
watch-demo script monitors for changes of typescript code and does
incremental compilation (~200-400ms), so users can have a fast edit-refresh
cycle when developing apps.

Testing

Before submitting a pull request, make sure the code passes all the tests and is clean of lint errors:

On Windows, use bash (available through git) to use the scripts above.

Looking to contribute, and don't know where to start? Check out our "help wanted"
issues.

Supported environments

deeplearn.js targets environments with WebGL 1.0 or WebGL 2.0. For devices
without the OES_texture_float extension, we fall back to fixed precision
floats backed by a gl.UNSIGNED_BYTE texture. For platforms without WebGL,
we provide CPU fallbacks.