← Open Source
mateogianolio

ocr

Neural network OCR.

TutorialsML/AI fundamentalsJavaScript
Open on GitHub
Momentum
+0stars in 24 hours0.0%
1.13k
Stars
94
Forks
+1
This week
4
Contributors
Created 2015-03-10 · Updated 2026-10-13 · #11473 today
Top developers
mateogianolioChristoSilviaGoGoGadgetGrant

mateogianolio/ocr is ranked 11,473 with 1,132 stars.

Same-category comparison

mateogianolio/ocr is ranked 11,473 among these 8 peers; omoindrot/tensorflow-triplet-loss is ranked 11,487.

Same-category comparison
NameRankMetrics
Timthony/self_drive11,441
Language:
Python
Stars:
1,139
Forks:
277
Description:
Self-driving car based on raspberry pi(tensorflow)).
daveebbelaar/langchain-experiments11,445
Language:
Jupyter Notebook
Stars:
1,138
Forks:
637
Description:
Building Apps with LLMs.
MachineLP/Tensorflow-11,452
Language:
Jupyter Notebook
Stars:
1,136
Forks:
378
wasabeef/claude-code-cookbook11,456
Language:
Shell
Stars:
1,136
Forks:
114
Description:
A collection of settings to make Claude Code more useful.
omoindrot/tensorflow-triplet-loss11,487
Language:
Python
Stars:
1,127
Forks:
281
Description:
Implementation of triplet loss in TensorFlow.
reshamas/fastai_deeplearn_part111,509
Language:
HTML
Stars:
1,121
Forks:
305
Description:
Notes for Fastai Deep Learning Course.
LearnedVector/A-Hackers-AI-Voice-Assistant11,510
Language:
Python
Stars:
1,120
Forks:
373
Description:
A hackers AI voice assistant, built using Python and PyTorch.
vivekkalyanarangan30/llm_from_scratch11,521
Language:
Python
Stars:
1,119
Forks:
296
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguageJavaScript
CategoryTutorials
SubcategoryML/AI fundamentals
KeywordsOCR
Stars1,132
Forks94
Contributors4
Created date2015-03-10
Updated date2026-10-13
Stars in 1 day0
Stars in 7 days1
Rank11,473
Previous rank11,420
Rank change-53
7-day stars rank10,152
Previous 7-day stars rank10,192
7-day stars rank change40
Total stars rank10,152
Previous total stars rank10,142
Total stars rank change-10
CountrySweden
README summary

OCR Trains a multi-layer perceptron (MLP) neural network to perform optical character recognition (OCR). The training set is automatically generated using a heavily modified version of the captcha-generator node-captcha. Support for the MNIST handwritten digit database has been added recently (see performance section). The network takes a one-dimensional binary array (default -bit) as input and outputs an 10-bit array of probabilities, which can be converted into a character code. Initial performance measurements show promising success

rates. After training, the network is saved as a standalone module to , which can then be used in your project like this (from ): Usage Clone this repository. The script is using canvas, so you'll need to install the **Cairo** rendering engine. On OS X, assuming you have Homebrew installed, this can be done with the following (copied from canvas README): Then install npm dependencies and test it: Performance All runs below were performed with a MacBook Pro Retina 13" Early

2015 with 8GB RAM. [MNIST [0-9]]( To test with the MNIST dataset: click on the title above, download the 4 data files and put them in a folder called in the root directory of this repository. Then run **Neurons** input hidden output **Learning rate:** **Training set:** digits **Testing set:** digits **Training time:** **Success rate:** [A-Za-z0-9] **Neurons** input hidden output **Learning rate:** **Training set** **Size:** characters **Testing set:** characters **Training time:** **Success rate:** [a-z] **Neurons** input

hidden output **Learning rate:** **Training set** **Size:** characters **Testing set:** characters **Training time:** **Success rate:** [0-9] **Neurons** input hidden output **Learning rate:** **Training set** **Size:** digits **Testing set:** digits **Training time:** **Success rate:** Configuration Tweak the network for your needs by editing the file located in the main folder. Pasted below is the default config file. ** ** If set to true, the MNIST handwritten digit dataset will be used for training and testing the network. This setting will overwrite configured

set sizes and will ignore the , , and settings. ** ** A string containing the glyphs with which to train/test the network. ** ** An array of fonts to be used when generating images. ** ** Number of images to be generated and used as the network training set. ** ** Same as above, but these images are used for testing the network. ** ** The size of the square chunk (in pixels) containing a glyph. ** ** When analyzing the pixels of a glyph, the algorithm reduces each pixel to and

everything below is marked as 1 in the resulting binary array used as network input.

Frequently asked questions

How many stars and forks are recorded?

mateogianolio/ocr has 1,132 stars and 94 forks.

What is the repository rank?

mateogianolio/ocr is ranked 11,473.

What language and category are recorded?

mateogianolio/ocr has 1,132 stars, uses JavaScript and belongs to Tutorials.

Which repository is closest in rank?

mateogianolio/ocr is compared with omoindrot/tensorflow-triplet-loss, ranked 11,487 with 1,127 stars.

README

OCR

Trains a multi-layer perceptron (MLP) neural network to perform optical character recognition (OCR).

The training set is automatically generated using a heavily modified version of the captcha-generator node-captcha. Support for the MNIST handwritten digit database has been added recently (see performance section).

The network takes a one-dimensional binary array (default 20 * 20 = 400-bit) as input and outputs an 10-bit array of probabilities, which can be converted into a character code. Initial performance measurements show promising success rates.

After training, the network is saved as a standalone module to ./ocr.js, which can then be used in your project like this (from test.js):

var predict = require('./ocr.js');

// a binary array that we want to predict
var one = [
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];

// the prediction is an array of probabilities
var prediction = predict(one);

// the index with the maximum probability is the best guess
console.log('prediction:', prediction.indexOf(Math.max.apply(null, prediction)));
// will hopefully output 1 if trained with 0-9 :)

Usage

Clone this repository. The script is using canvas, so you'll need to install the Cairo rendering engine. On OS X, assuming you have Homebrew installed, this can be done with the following (copied from canvas README):

$ brew install pkg-config cairo jpeg giflib

Then install npm dependencies and test it:

$ npm install
$ node main.js
$ node test.js

Performance

All runs below were performed with a MacBook Pro Retina 13" Early 2015 with 8GB RAM.

MNIST [0-9]

To test with the MNIST dataset: click on the title above, download the 4 data files and put them in a folder called mnist in the root directory of this repository.

// config.json
{
  "mnist": true,
  "network": {
    "hidden": 160,
    "learning_rate": 0.03
  }
}

Then run

$ node mnist.js
  • Neurons
    • 400 input
    • 160 hidden
    • 10 output
  • Learning rate: 0.03
  • Training set: 60000 digits
  • Testing set: 10000 digits
  • Training time: 21 min 53 s 753 ms
  • Success rate: 95.16%

[A-Za-z0-9]

// config.json
{
  "mnist": false,
  "text": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012356789",
  "fonts": [
    "sans-serif",
    "serif"
  ],
  "training_set": 2000,
  "testing_set": 1000,
  "image_size": 16,
  "threshold": 400,
  "network": {
    "hidden": 60,
    "learning_rate": 0.1,
    "output": 62
  }
}
  • Neurons
    • 256 input
    • 60 hidden
    • 62 output
  • Learning rate: 0.03
  • Training set
    • Size: 124000 characters
    • Sample:
  • Testing set: 62000 characters
  • Training time: 8 min 18 s 560 ms
  • Success rate: 93.58225806451614%

[a-z]

// config.json
{
  "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,
    "output": 26
  }
}
  • Neurons
    • 256 input
    • 40 hidden
    • 26 output
  • Learning rate: 0.1
  • Training set
    • Size: 52000 characters
    • Sample:
  • Testing set: 26000 characters
  • Training time: 1 min 55 s 414 ms
  • Success rate: 93.83846153846153%

[0-9]

// config.json
{
  "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
    • 256 input
    • 40 hidden
    • 10 output
  • Learning rate: 0.1
  • Training set
    • Size: 20000 digits
    • Sample:
  • Testing set: 10000 digits
  • Training time: 0 min 44 s 363 ms
  • Success rate: 99.59%

Configuration

Tweak the network for your needs by editing the config.json file located in the main folder. Pasted below is the default config file.

// config.json
{
  "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
  }
}

  • mnist
    • If set to true, the MNIST handwritten digit dataset will be used for training and testing the network. This setting will overwrite configured set sizes and will ignore the image_size, threshold, fonts and text settings.
  • text
    • A string containing the glyphs with which to train/test the network.
  • fonts
    • An array of fonts to be used when generating images.
  • training_set
    • Number of images to be generated and used as the network training set.
  • testing_set
    • Same as above, but these images are used for testing the network.
  • image_size
    • The size of the square chunk (in pixels) containing a glyph. The resulting network input size is image_size^2.
  • threshold
    • When analyzing the pixels of a glyph, the algorithm reduces each pixel (r, g, b) to (r + g + b) and everything below threshold is marked as 1 in the resulting binary array used as network input.
  • network
    • hidden
      • The size (number of neurons) of the hidden layer of the network.
    • learning_rate
      • The learning rate of the network.
Nearby in the ranking
Similar items