convnetjs README

The project's README from github.com/karpathy/convnetjs. As one markdown file: README.md.

ConvNetJS

ConvNetJS is a Javascript implementation of Neural networks, together with nice browser-based demos. It currently supports:

For much more information, see the main page at convnetjs.com

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();
net.makeLayers(layer_defs);

// 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();
net.makeLayers(layer_defs);

// 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");

License

MIT

convnetjs (karpathy/convnetjs)

Searching Database…

11.2K ·GitHub
这是什么?ConvNetJS 是一个 JavaScript 神经网络实现,让你可以直接在浏览器里训练卷积神经网络、普通全连接网络,甚至强化学习智能体。
这是浏览器库还是 Node 包?两者都是:它通过编译好的 convnet.js/convnet-min.js 文件在浏览器端运行,同时也作为 Node.js 模块发布,可以在服务端代码里 require()。
怎么把它加到项目里?在 Node 里运行 npm install convnetjs 然后 require 它;在浏览器里,从 releases 页面获取压缩版构建并引入 convnet.js 或 convnet-min.js,再参照主站上的 Getting Started 教程查看示例代码。
这个项目还在维护吗?不维护了——作者明确表示已经没有时间维护,甚至警告 npm 包页面可能已经失效。
如今它对谁还有用?如今它主要具有历史/教学价值,适合想看看一个从零写起的 JS 神经网络库如何运作的人,而不是用于生产级深度学习——现代项目应该改用仍在维护的库。
训练实际在哪里运行?全部在客户端的 JavaScript 里运行——在浏览器或 Node.js 下——不涉及任何服务器或 Python 后端。
ConvNetJS 实际能搭建哪些类型的网络?带非线性激活的全连接层、SVM/Softmax 分类、L2 回归、面向图像数据的完整卷积网络,以及一个实验性的 Deep Q-Learning 强化学习模块。
安装之前有在线演示可以先试试吗?有——README 链接了多个浏览器演示,包括在 MNIST 数字和 CIFAR-10 上训练 CNN、简单的 2D/1D 回归、MNIST 自编码器、Deep Q-Learning 强化学习演示,以及图像回归的“Painting”演示。
完整文档在哪里?Getting Started 教程和完整文档都在项目主站 convnetjs.com 上,而不是在仓库里。
Creator
karpathy
Size
27.2 MB
Stars
11.2K
Age
12y
Commits · 90 Days