Skip to content

Commit

Permalink
fix errors | add freshly generated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mateogianolio committed Mar 23, 2015
1 parent ae218e0 commit 7502f4e
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 53 deletions.
108 changes: 73 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,97 @@ var character = String.fromCharCode(parseInt(output.join(''), 2));

### [MNIST [0-9]](http:https://yann.lecun.com/exdb/mnist/)

```config.json```:

```javascript
{
"mnist": true,
"network": {
"hidden": 40,
"learning_rate": 0.1
}
}
```

* **Neurons**
* ```400``` input
* ```40``` hidden
* ```4``` output
* **Learning rate**
* ```0.1```
* **Training set**
* ```59999``` digits
* **Testing set**
* ```9999``` digits
* **Measured success rate**
* ```82.08820882088209%```
* **Learning rate:** ```0.1```
* **Training set:** ```60000``` digits
* **Testing set:** ```10000``` digits
* **Training time:** ```3 min 58 s 225 ms```
* **Success rate:** ```78.06%```

### [a-z]

* **Fonts**
* sans-serif
* serif
```config.json```:

```javascript
{
"mnist": false,
"text": "abcdefghijklmnopqrstuvwxyz",
"fonts": [
"sans-serif",
"serif"
],
"training_set": 2000,
"testing_set": 1000,
"image_size": 16,
"threshold": 400,
"network": {
"hidden": 40,
"learning_rate": 0.1
}
}
```

* **Neurons**
* ```400``` input
* ```256``` input
* ```40``` hidden
* ```8``` output
* **Learning rate**
* ```0.1```
* **Learning rate:** ```0.1```
* **Training set**
* ```52000``` characters
* **Sample**
* ![abcdefghijklmnopqrstuvwxyz](https://raw.github.com/mateogianolio/mlp-character-recognition/master/examples/abcdefghijklmnopqrstuvwxyz.png)
* **Testing set**
* ```13000``` characters
* **Measured success rate**
* ```96.32307692307693%```
* **Size:** ```52000``` characters
* **Sample:** ![abcdefghijklmnopqrstuvwxyz](https://raw.github.com/mateogianolio/mlp-character-recognition/master/examples/abcdefghijklmnopqrstuvwxyz.png)
* **Testing set:** ```26000``` characters
* **Training time:** ```2 min 10 s 752 ms```
* **Success rate:** ```91.77692307692308%```

### [0-9]

* **Fonts**
* sans-serif
* serif
```config.json```:

```javascript
{
"mnist": false,
"text": "0123456789",
"fonts": [
"sans-serif",
"serif"
],
"training_set": 2000,
"testing_set": 1000,
"image_size": 16,
"threshold": 400,
"network": {
"hidden": 40,
"learning_rate": 0.1
}
}
```

* **Neurons**
* ```400``` input
* ```256``` input
* ```40``` hidden
* ```8``` output
* **Learning rate**
* ```0.1```
* **Learning rate:** ```0.1```
* **Training set**
* **Size**
* ```20000``` digits
* **Sample**
* ![0123456789](https://raw.github.com/mateogianolio/mlp-character-recognition/master/examples/0123456789.png)
* **Testing set**
* ```5000``` digits
* **Measured success rate**
* ```99.22%```
* **Size:** ```20000``` digits
* **Sample:** ![0123456789](https://raw.github.com/mateogianolio/mlp-character-recognition/master/examples/0123456789.png)
* **Testing set:** ```10000``` digits
* **Training time:** ```1 min 6 s 620 ms```
* **Success rate:** ```99.22%```

## Configuration

Expand Down
11 changes: 1 addition & 10 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"mnist": false,
"text": "abcdefghijklmnopqrstuvwxyz",
"fonts": [
"sans-serif",
"serif"
],
"training_set": 2000,
"testing_set": 500,
"image_size": 20,
"threshold": 400,
"mnist": true,
"network": {
"hidden": 40,
"learning_rate": 0.1
Expand Down
Binary file modified examples/0123456789.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/abcdefghijklmnopqrstuvwxyz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
training = [],
testing = [],
settings = {
size: chars,
size: config.text.length,
height: config.image_size,
text: config.text,
fonts: config.fonts,
Expand All @@ -67,6 +67,9 @@
return function(text, data) {
var png = new PNG({ filterType: 4 });
png.parse(data, parse(text, index));

if(index === 0)
fs.writeFileSync('./examples/' + text + '.png', data, 'base64');
};
}

Expand Down Expand Up @@ -149,7 +152,7 @@
pixel = [],
i, j, k, x, y;

for(i = 0; i < chars; i++) {
for(i = 0; i < config.text.length; i++) {
for(y = 0; y < data.height; y++) {
for(x = i * config.image_size; x < (i * config.image_size + config.image_size); x++) {
position = (data.width * y + x) << 2;
Expand All @@ -160,15 +163,15 @@
chunk.push(
pixel.reduce(function(previous, current) {
return previous + current;
}) > threshold ? 0 : 1
}) > config.threshold ? 0 : 1
);
pixel = [];
}
}

chunk = tools.center(chunk);

if(index < training_set) {
if(index < config.training_set) {
training.push({
input: chunk,
output: ('00000000' + text.charCodeAt(i).toString(2)).substr(-8).split('').map(Number)
Expand Down
17 changes: 13 additions & 4 deletions network.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,30 @@
log(' hidden:', network.layers.hidden[0].size, 'neurons.');
log(' output:', network.layers.output.size, 'neurons.');
log('learning rate:', rate, '\n');
log('learning ...');
log('training with', length, 'inputs ...');

var start = process.hrtime();

while(set.length) {
object = set.pop();

if(count % Math.round(length / 10) === 0)
log('progress:', Math.round(100 * (count / length)) + '%');
log('progress:', Math.round(100 * (count / length)),'%');

network.activate(object.input);
network.propagate(rate, object.output);

count++;
}

log('... done');
var elapsed = process.hrtime(start);
var time = {
minutes: Math.floor(elapsed[0] / 60),
seconds: elapsed[0] % 60,
milliseconds: Math.floor(elapsed[1] / 1000000)
};

log('... done', '(' + time.minutes, 'min', time.seconds, 's', time.milliseconds, 'ms)');
log();
};

Expand All @@ -38,7 +47,7 @@
count = 0;

// test on random inputs
log('testing on', length, 'samples ...');
log('testing on', length, 'inputs ...');
while(set.length) {
object = set.pop();

Expand Down

0 comments on commit 7502f4e

Please sign in to comment.