• This repository has been archived on 17/Dec/2017
  • Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run trained deep neural networks in the browser or node.js

PROJECT PAGE AND EXAMPLES

Run trained deep neural networks in the browser or node.js. Currently supports serialization from trained Keras models (note: not up-to-date with the current Keras API).

build status npm version

Background

Training deep neural networks on any meaningful dataset requires massive computational resources and lots and lots of time. However, the forward-pass prediction phase is relatively cheap - typically there is no backpropagation, computational graphs, loss functions, or optimization algorithms to worry about.

What do you do when you have a trained deep neural network and now wish to use it to power a part of your client-facing web application? Traditionally, you would deploy your model on a server and call it from your web application through an API. But what if you can deploy it in the browser alongside the rest of your webapp? Computation would be offloaded entirely to your end-user!

Perhaps most users will not be able to run billion-parameter networks in their browsers quite yet, but smaller networks are certainly within the realm of possibility.

The goal of this project is to provide a lightweight javascript library that can take a serialized Keras, Caffe, Torch or [insert other deep learning framework here] model, together with pre-trained weights, pack it in your webapp, and be up and running. Currently supports serialization from trained Keras models.

Examples

  • MNIST multi-layer perceptron / src / demo

  • CIFAR-10 VGGNet-like convolutional neural network / src / demo

  • LSTM recurrent neural network for classifying astronomical object names / src / demo

You can also run the examples on your local machine at http://localhost:8000:

$ npm run examples-server

Usage

See the source code of the examples above. In particular, the CIFAR-10 example demonstrates a multi-threaded implementation using Web Workers.

In the browser:

<script src="neocortex.min.js"></script>
<script>
  // use neural network here
</script>

In node.js:

$ npm install neocortex-js
import NeuralNet from 'neocortex-js';

The core steps involve:

  1. Instantiate neural network class
let nn = new NeuralNet({
  // relative URL in browser/webworker, absolute path in node.js
  modelFilePath: 'model.json',
  arrayType: 'float64', // float64 or float32
});
  1. Load the model JSON file, then once loaded, feed input data into neural network
nn.init().then(() => {
  let predictions = nn.predict(input);
  // make use of predictions
});

Build

To build the project yourself, for both the browser (outputs to build/neocortex.min.js) and node.js (outputs to dist/):

$ npm install
$ npm run build

To build just for the browser:

$ npm run build-browser

Keras

A script to serialize a trained Keras model together with its hdf5 formatted weights is located in the utils/ folder. It currently only supports sequential models with layers listed below. Implementation of graph models is planned.

Functions and layers currently implemented are listed below. More forthcoming.

  • Activation functions: linear, relu, sigmoid, hard_sigmoid, tanh, softmax

  • Advanced activation layers: leakyReLULayer, parametricReLULayer, parametricSoftplusLayer, thresholdedLinearLayer, thresholdedReLuLayer

  • Basic layers: denseLayer, dropoutLayer, flattenLayer, mergeLayer

  • Recurrent layers: rGRULayer (gated-recurrent unit or GRU), rLSTMLayer (long short-term memory or LSTM)

  • Convolutional layers: convolution2DLayer, maxPooling2DLayer, convolution1DLayer, maxPooling1DLayer

  • Embedding layers: embeddingLayer (maps indices to corresponding embedding vectors)

  • Normalization layers: batchNormalizationLayer

Tests

$ npm test

Browser testing is planned.

Credits

Thanks to @halmos for the logo.

Citation

DOI

License

Apache 2.0

More Repositories

1

tsne-js

t-distributed stochastic neighbor embedding (t-SNE) algorithm implemented in JavaScript
JavaScript
242
star
2

mesh-tree

Utility functions for traversing the Medical Subject Heading (MeSH) ontology tree
JavaScript
38
star
3

scholarly.vernacular.io

A vernacular of HTML for scholarly publishing
HTML
38
star
4

crossref

Client for the Crossref API
JavaScript
31
star
5

omml2mathml

Small utility to convert from Microsoft's OMML to MathML
JavaScript
20
star
6

react-blobber

Create orthogonal blobs from arrays of rectangles
JavaScript
15
star
7

pubmed-schema-org

PubMed and PubMed central mapped to schema.org and expressed as JSON-LD and RDFa.
JavaScript
13
star
8

paper-input

Paper Input React component
JavaScript
9
star
9

react-router-redux-sync

Sync params and location from react-router to a redux store
JavaScript
9
star
10

react-pouchdb-changes

React component middleware for listening to the changes feed from CouchDB or PouchDB
JavaScript
8
star
11

ldstars

Rate (as in five stars linked data) a schema.org document in JSON-LD
JavaScript
8
star
12

cssnow

Sort of like cssnext used to be
JavaScript
7
star
13

RJSONLD

Export results of standard analytics to JSON-LD format
R
6
star
14

vernacular.io

The vernacular.io website
HTML
4
star
15

paper-textarea

Paper Textarea React component
JavaScript
4
star
16

5-star-linked-data-icons

icons for 5 star linked data
4
star
17

doc-dna

Visualize the DNA of the CreativeWork a JSON-LD document using schema.org context
JavaScript
4
star
18

blog

Standard Analytics IO weblog (powered by poet and purecss.io)
CSS
3
star
19

stat-ontology

An experimentation for a statistics ontology
JavaScript
3
star
20

style-guide-db

Searchable database of style guides
JavaScript
3
star
21

ducted

General purpose pipeline manager
JavaScript
3
star
22

optimizify

Browserify transform for optimize-js
JavaScript
3
star
23

jsonld-context-infer

Infer a JSON-LD context from a readable stream of tabular data.
JavaScript
3
star
24

data-citations

Web-First Data Citations
HTML
2
star
25

get-xml

Parse XML transparently in Node or the browser
JavaScript
2
star
26

preview-tabular-data

Extract the first x lines of tabular dataset
JavaScript
2
star
27

paper-checkbox

Paper Checkbox React component
JavaScript
1
star
28

embed

makes trees out of flattened JSON-LD documents
JavaScript
1
star
29

time-picker

A very simple React time picker
JavaScript
1
star