Skip to content

Commit

Permalink
A heavy change, step 1
Browse files Browse the repository at this point in the history
A heavy change, step 1
  • Loading branch information
suquark committed Mar 4, 2017
1 parent 6f90052 commit cdc219b
Show file tree
Hide file tree
Showing 38 changed files with 45 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ test/
tags

.vscode/launch.json

dataset/mnist.raw
24 changes: 15 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# Modern ConvNetJS
# InspireNN

It is a project trying to reimplement [ConvNetJS](https://github.com/karpathy/convnetjs) with modern styles (ECMAScript6, functional programming), making it's code shorter, more readable for beginners and easier to extend.
This project makes neural networks running on browsers. It can be useful in blogging & presentation.


It reimplements [ConvNetJS](https://github.com/karpathy/convnetjs) with modern styles (ECMAScript6, functional programming), making it's code shorter, more readable for beginners and easier to extend.

It's sure that we should never expect a neural network training in the browser doing a big deal, but it's useful for presentation and understanding.

It is still under developing.

Following is a short introduction to ConvNetJS itself:

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

* transpiler

`systemjs` + `traceur` is used to load ES6 modules and provide ES6 polyfill for older browsers.

* style

`jquery`, `materializecss`, `d3js` and `three.js` is included in the project for supporting visualization tasks. Though making use of CDNs may be a better idea, but I prefer to keep them local for offline situations.


- 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 [convnetjs.com](http://convnetjs.com)

## License
MIT
34 changes: 15 additions & 19 deletions backend/image.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tensor } from 'backend/tensor.js';
import { assert } from 'util/assert.js';
import { clip_pixel, scale_shift } from 'backend/ops.js';

import { clip_pixel } from 'backend/ops.js';
import { prod } from 'util/array.js';
/**
* This class provides a more uniform and general way to store and save images with same shape
*/
Expand All @@ -21,7 +21,7 @@ class ImageBuffer {
for (let i of tsArray) {
let x = i.clone();
clip_pixel(x);
let ba = new Uint8ClampedArray(size);
let ba = new Uint8ClampedArray(size);
for (let j = 0; j < size; j++) {
ba[j] = x.w[j];
}
Expand All @@ -30,15 +30,14 @@ class ImageBuffer {
return ib;
}

get tensors() {
return this.images.map(b => {
let t = new Tensor(this.shape);
let N = t.size;
for (let i = 0; i < N; i++) {
t.w[i] = (b[i] / 255.0) * 2.0 - 1.0;
}
return t;
});
get tensor() {
let image = this.images;
let t = new Tensor(this.shape);
let N = t.size;
for (let i = 0; i < N; i++) {
t.w[i] = (image[i] / 255.0) * 2.0 - 1.0;
}
return t;
}

/**
Expand All @@ -50,20 +49,17 @@ class ImageBuffer {
static load(map, buf) {
let ib = new ImageBuffer();
ib.name = map.name;
assert(map.shape.length === 4, "Error: images should be tensor with 4 dims")
ib.shape = map.shape;
ib.images = [];

let size = ib.shape[0] * ib.shape[1] * ib.shape[2]; // FIXME: may a more general way?
let size = prod(ib.shape);
// OK, load values from buffer
for (let i = 0; i < map.count; i++) {
ib.images.push(buf.read(size, 'Uint8ClampedArray'));
}
ib.images = buf.read(size, 'Uint8ClampedArray');
return ib;
}

__save__(buf) {
for (let i of this.images) buf.write(i);
return {name: this.name, shape: this.shape, count: this.images.length, type: 'images'};
return { name: this.name, shape: this.shape, count: this.images.length, type: 'images' };
}
}

Expand Down
1 change: 1 addition & 0 deletions dataset/mnist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"mnist/","nodes":[{"name":"x","shape":[70000,28,28,1],"type":"images"},{"type":"Uint8Array","name":"y","length":70000}]}]
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions demo/regression/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Regression Demo</title>
<script src="../../visualize/jquery.min.js"></script>
<script src="../../visualize/js/jquery.min.js"></script>

<link rel="stylesheet" href="../../visualize/materialize/css/materialize.min.css" />
<link rel="stylesheet" href="../../visualize/materialize/css/material_icons.css" />
<script src="../../visualize/materialize/js/materialize.min.js"></script>
<link rel="stylesheet" href="../../visualize/prism/prism.css" />
<script src="../../visualize/prism/prism.js"></script>
<link rel="stylesheet" href="../../visualize/js/materialize/css/materialize.min.css" />
<link rel="stylesheet" href="../../visualize/js/materialize/css/material_icons.css" />
<script src="../../visualize/js/materialize/js/materialize.min.js"></script>

<link rel="stylesheet" href="../js/prism/prism.css" />
<script src="../js/prism/prism.js"></script>
<style>
section {
margin-top: 40px;
Expand Down
8 changes: 4 additions & 4 deletions demo/regression/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
<script src="../../transpiler/system.js"></script>
<script src="../sysconf.js"></script>

<script src="../../visualize/jquery.min.js"></script>
<script src="../../visualize/foreign/jquery.min.js"></script>

<link rel="stylesheet" href="../../visualize/materialize/css/materialize.min.css" />
<link rel="stylesheet" href="../../visualize/materialize/css/material_icons.css" />
<script src="../../visualize/materialize/js/materialize.min.js"></script>
<script src="../../visualize/foreign/materialize/js/materialize.min.js"></script>

<script src="../../visualize/preload-mask.js"></script>

<script src="../../visualize/d3.min.js"></script>
<script src="../../visualize/d3-interpolate-path.js"></script>
<script src="../../visualize/foreign/d3.min.js"></script>
<script src="../../visualize/foreign/d3-interpolate-path.js"></script>

<style>
path {
Expand Down
2 changes: 1 addition & 1 deletion util/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function sum(arr) {

// create array
export { zeros, zeros2d, array2d, one_hot };
export { prod };
export { prod, sum };
// property of array
export { maxmin, indexOfMax, arrUnique, arrContains };
// geometry
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit cdc219b

Please sign in to comment.