Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Deep Learning in Javascript. Train Convolutional Neural Networks (or ordinary ones) in your browser.

Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star full 4f7b624809470f25b6493d5a7b30d9b9cb905931146e785d67c86ef0c205a402Star blank 374f33e4d622a2930833db3cbea26b5d03dc44961a6ecab0b9e13276d97d6682 (1 ratings)
Rated 4.0 out of 5
Subscribe to updates I use convnetjs

Statistics on convnetjs

Number of watchers on Github 8829
Number of open issues 59
Average time to close an issue about 1 month
Main language JavaScript
Average time to merge a PR 1 day
Open pull requests 21+
Closed pull requests 5+
Last commit about 3 years ago
Repo Created almost 6 years ago
Repo Last Updated over 1 year ago
Size 27.2 MB
Organization / Authorkarpathy
Latest Release2014.08.31
Page Updated
Do you use convnetjs? Leave a review!
View open issues (59)
View convnetjs activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating convnetjs for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


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
  • 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

Note: I am not actively maintaining ConvNetJS anymore because I simply don't have time. I think the npm repo might not work at this point.

Online Demos

Example Code

Here's a minimum example of defining a 2-layer neural network and training it on a single data point:

// species a 2-layer neural network with one hidden layer of 20 neurons
var layer_defs = [];
// input layer declares size of input. here: 2-D data
// ConvNetJS works on 3-Dimensional volumes (sx, sy, depth), but if you're not dealing with images
// then the first two dimensions (sx, sy) will always be kept at size 1
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:2});
// declare 20 neurons, followed by ReLU (rectified linear unit non-linearity)
layer_defs.push({type:'fc', num_neurons:20, activation:'relu'}); 
// declare the linear classifier on top of the previous hidden layer
layer_defs.push({type:'softmax', num_classes:10});

var net = new convnetjs.Net();

// forward a random data point through the network
var x = new convnetjs.Vol([0.3, -0.5]);
var prob = net.forward(x); 

// prob is a Vol. Vols have a field .w that stores the raw data, and .dw that stores gradients
console.log('probability that x is class 0: ' + prob.w[0]); // prints 0.50101

var trainer = new convnetjs.SGDTrainer(net, {learning_rate:0.01, l2_decay:0.001});
trainer.train(x, 0); // train the network, specifying that x is class zero

var prob2 = net.forward(x);
console.log('probability that x is class 0: ' + prob2.w[0]);
// now prints 0.50374, slightly higher than previous 0.50101: the networks
// weights have been adjusted by the Trainer to give a higher probability to
// the class we trained the network with (zero)

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}); // declare size of input
// output Vol is of size 32x32x3 here
layer_defs.push({type:'conv', sx:5, filters:16, stride:1, pad:2, activation:'relu'});
// the layer will perform convolution with 16 kernels, each of size 5x5.
// the input will be padded with 2 pixels on all sides to make the output Vol of the same size
// output Vol will thus be 32x32x16 at this point
layer_defs.push({type:'pool', sx:2, stride:2});
// output Vol is of size 16x16x16 here
layer_defs.push({type:'conv', sx:5, filters:20, stride:1, pad:2, activation:'relu'});
// output Vol is of size 16x16x20 here
layer_defs.push({type:'pool', sx:2, stride:2});
// output Vol is of size 8x8x20 here
layer_defs.push({type:'conv', sx:5, filters:20, stride:1, pad:2, activation:'relu'});
// output Vol is of size 8x8x20 here
layer_defs.push({type:'pool', sx:2, stride:2});
// output Vol is of size 4x4x20 here
layer_defs.push({type:'softmax', num_classes:10});
// output Vol is of size 1x1x10 here

net = new convnetjs.Net();

// helpful utility for converting images into Vols is included
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:

  1. Install it: $ npm install convnetjs
  2. Use it: var convnetjs = require("convnetjs");



convnetjs open issues Ask a question     (View All Issues)
  • about 3 years how to reference Brain()?
  • about 3 years Build with node why ant?
  • about 3 years what are the actions in agent in rldemo ?
  • about 3 years Newbie question about deepQ
  • about 3 years [Question] Why use javascript ?
  • over 3 years unhelpful bug messages
  • over 3 years Question: Multiple outputs..
  • almost 4 years Question: trainer network error
  • almost 4 years Backprop zeroing on FullyConnLayer
  • almost 4 years Reinforcement Learning with negative rewards?
  • about 4 years Question for deepqlearn.js
  • about 4 years Where is the Model Zoo
  • about 4 years Brain fromJSON
  • about 4 years Running the brain demo gets warning every iteration
  • about 4 years Reference to window object brakes the script in WebWorkers
  • about 4 years MagicNet for Node.js
  • over 4 years ReferenceError: deepqlearn is not defined
  • over 4 years Saving experiences in Q-Learning
  • over 4 years SVM to classify text sentences
  • over 4 years Is there a thorough explanation of the inner workings of convnet.js & deepqlearn.js?
  • over 4 years Loaded JSON runs slower
  • over 4 years npm version out of date?
  • over 4 years Marching Squares
  • over 4 years Use SIMD where possible?
  • almost 5 years What kind of neural network do I need?
  • almost 5 years MaxoutLayer uses different options to initialize "switches" array depending on fromJSON or base constructor
  • about 5 years How can data be serialized?
  • about 5 years MagicNet's convergence
  • over 5 years WebGL implementation of calculations
convnetjs open pull requests (View All Pulls)
  • fix dropout prob
  • fix deepqlearn nodejs dep; precompiled
  • use hash to improve speed of arrUnique function
  • Fixed typographical error, changed arbitary to arbitrary in README.
  • Progress thus far on using SIMD + Typed Objects.
  • [ConvNetJS] Implement DropConnect for regularizing large fully-connected layers
  • basic demo added
  • optimize for v8
  • Fix adam optimizer
  • Fixed LRN layer
  • Code cleanup
  • Inverted colors
  • Fixed two bugs
  • fix for uploading image in mnist demo
  • gitignore convnet output files
  • Prevent Regression Layer from being NaN
  • Add example node.js script demonstrating image regression.
  • Rename bower.json to package.json
  • Fixed typo in comment
  • Allow to work in non-browser env
  • Allow specific input shape
convnetjs questions on Stackoverflow (View All Questions)
  • Why is Tensorflow 100x slower than convnetjs in this simple NN example?
  • Neural Net ConvNetJs - Why can't it converge
  • Don't understand train data from convnetjs
convnetjs list of languages used
convnetjs latest release notes
2014.08.31 v1.1.0

Switching convnetjs to releases. This is the first official release: it includes everything seen in the repo and the built version (build/convnet.js and build/convnet-min.js) that contains the library.

Other projects in JavaScript