ConvNetJS
ConvNetJS is a Javascript implementation of Neural networks, together with nice browser-based demos. It currently supports:
- Common Neural Network modules (fully connected layers, non-linearities)
- Classification (SVM/Softmax) and Regression (L2) cost functions
- A MagicNet class for fully automatic neural network learning (automatic hyperparameter search and cross-validatations)
- Ability to specify and train Convolutional Networks that process images
- An experimental Reinforcement Learning module, based on Deep Q Learning
For much more information, see the main page at convnetjs.com
Online Demos
Example Code
Here's a minimum example of defining a 2-layer neural network and training
it on a single data point:
var layer_defs = [];
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:2});
layer_defs.push({type:'fc', num_neurons:20, activation:'relu'});
layer_defs.push({type:'softmax', num_classes:10});
var net = new convnetjs.Net();
net.makeLayers(layer_defs);
var x = new convnetjs.Vol([0.3, -0.5]);
var prob = net.forward(x);
console.log('probability that x is class 0: ' + prob.w[0]);
var trainer = new convnetjs.SGDTrainer(net, {learning_rate:0.01, l2_decay:0.001});
trainer.train(x, 0);
var prob2 = net.forward(x);
console.log('probability that x is class 0: ' + prob2.w[0]);
and here is a small Convolutional Neural Network if you wish to predict on images:
var layer_defs = [];
layer_defs.push({type:'input', out_sx:32, out_sy:32, out_depth:3});
layer_defs.push({type:'conv', sx:5, filters:16, stride:1, pad:2, activation:'relu'});
layer_defs.push({type:'pool', sx:2, stride:2});
layer_defs.push({type:'conv', sx:5, filters:20, stride:1, pad:2, activation:'relu'});
layer_defs.push({type:'pool', sx:2, stride:2});
layer_defs.push({type:'conv', sx:5, filters:20, stride:1, pad:2, activation:'relu'});
layer_defs.push({type:'pool', sx:2, stride:2});
layer_defs.push({type:'softmax', num_classes:10});
net = new convnetjs.Net();
net.makeLayers(layer_defs);
var x = convnetjs.img_to_vol(document.getElementById('#some_image'))
var output_probabilities_vol = net.forward(x)
Getting Started
A Getting Started tutorial is available on main page.
The full Documentation can also be found there.
See the releases page for this project to get the minified, compiled library, and a direct link to is also available below for convenience (but please host your own copy)
Compiling the library from src/ to build/
If you would like to add features to the library, you will have to change the code in src/
and then compile the library into the build/
directory. The compilation script simply concatenates files in src/
and then minifies the result.
The compilation is done using an ant task: it compiles build/convnet.js
by concatenating the source files in src/
and then minifies the result into build/convnet-min.js
. Make sure you have ant installed (on Ubuntu you can simply sudo apt-get install it), then cd into compile/
directory and run:
$ ant -lib yuicompressor-2.4.8.jar -f build.xml
The output files will be in build/
Use in Node
The library is also available on node.js:
- Install it:
$ npm install convnetjs
- Use it:
var convnetjs = require("convnetjs");
License
MIT