npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neocortex-js

v0.5.0

Published

Run trained neural networks in the browser or node.js

Downloads

20

Readme

Run trained deep neural networks in the browser or node.js. Currently supports serialization from trained Keras models.

PROJECT PAGE AND EXAMPLES

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 run build

To build just for the browser:

$ npm run build-browser

Frameworks

Keras

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

API

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

  • flattenLayer

Recurrent layers
  • rGRULayer (gated-recurrent unit or GRU)

  • rLSTMLayer (long short-term memory or LSTM)

  • rJZS1Layer, rJZS2Layer, rJZS3Layer (mutated GRUs - JZS1, JZS2, JZS3 - from Jozefowicz et al. 2015)

Convolutional layers
  • convolution2DLayer

  • maxPooling2DLayer

  • convolution1DLayer

  • maxPooling1DLayer

Embedding layers
  • embeddingLayer - maps indices to corresponding embedding vectors
Normalization layers

Todo

  • [ ] implement merge and graph structures from keras

  • [ ] implement additional keras layers such as TimeDistributedDense, etc.

Tests

$ npm test

Browser testing is planned.

Credits

Thanks to @halmos for the logo.

License

Apache 2.0