• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mnist digits in javascript

MNIST Digits

mnist digits

The goal of this library is to provide an easy-to-use way for training and testing MNIST digits for neural networks (either in the browser or node.js). It includes 10000 different samples of mnist digits. I built this in order to work out of the box with Synaptic.

You are free to create any number (from 1 to 60 000) of different examples c via MNIST Digits data loader

Installation

for node.js: npm install mnist --save

for the browser: bower install mnist --save

Usage

The most important method is mnist.set(trainingAmount, testAmount) which takes the amount of samples for the training and test sets, and returns an object with the two sets of samples (one for training and the other one for testing). Both sets are shuffled, and there are no samples repeated in both sets.

For example:

var mnist = require('mnist'); // this line is not needed in the browser

var set = mnist.set(8000, 2000);

var trainingSet = set.training;
var testSet = set.test;

That would create a random training set of 8000 mnist digits, and a test set with other random 2000 mnist digits, and there are not going to be any sample in the training set repeated in the test set.

Every set consist of an array of elements, which each of them will looks like this:

{
    input: [0,0,0,1,1, ... ,0,0], // a 784-length array of floats representing each pixel of the 28 x 28 image, normalized between 0 and 1
    output: [0,0,0,0,0,0,1,0,0,0] // a 10-length binary array that tells which digits (from 0 to 9) is in that image
}

Helpers

Every digit has a set of helper functions which are listed below. To access these functions you have to target the desired digit like this: mnist[digit].

So, for example, to get a single '5' digit, you would call mnist[5].get().

These are all the helper function:

#####.get([index])

Returns a single sample of that digit, given its index. If no index is provided, a random sample is returned.

mnist[0].get(100) // [0,0,0,1,1...,0,0]

#####.length

Returns the number of samples available for that digit

mnist[6].length // 1009

#####.range(start, end)

Returns an array of samples, corresponding to the range specified between the start and end arguments

mnist[9].range(10, 17) // [ array with 7 samples of the digit 9 ]

#####.set(start, end)

Returns an dataset of samples, corresponding to the range specified between the start and end arguments, every element of the array has an input and output properties, being input the normalized data for all the pixels of each image, and output a 10-length binary array representing which digit is in that image.

mnist[4].set(200, 250) // [ dataset with 50 samples of the digit 4 ready for training/testing a neural network ]

#####.raw

This property provides access to all the raw data for all the samples of that digit

mnist[3].raw // all the raw data for digit 3

Drawing a digit (only in the browser)

This lets you draw a given digit in a canvas context: mnist.draw(digit, context [,offsetX, offsetY])

var digit = mnist[1].get();
var context = document.getElementById('myCanvas').getContext('2d');

mnist.draw(digit, context); // draws a '1' mnist digit in the canvas

The digit provided has to be a 784-length array of normalized values (0-1). All of the following approaches will work:

var digit = mnist[0].get(); // single digit
var digit = mnist[1].range(0, 100)[50]; // extracting the digit from a range
var digit = mnist[4].set(0, 100)[20].input; // extracting the digit from a dataset
var digit = mnist.set(8000, 2000).training[0].input; // extracting the digit from a training set
var digit = mnist.set(8000, 2000).test[15].input; // extracting the digit from a test set

Contributing

If you want to contribute feel free to submit PR's, just make sure to run npm run build to build the /dist files before submitting.

More Repositories

1

synaptic

architecture-free neural network library for node.js and the browser
JavaScript
6,914
star
2

coin-hive

CoinHive cryptocurrency miner for node.js
JavaScript
1,982
star
3

coin-hive-stratum

use CoinHive's JavaScript miner on any stratum pool
TypeScript
416
star
4

shoal

autonomous agents + genetic algorithms
JavaScript
242
star
5

react-coin-hive

Mine cryptocurrency while your users haven't engaged with your content lately
JavaScript
158
star
6

eth-pictures

🎨 Draw your own NFTs
TypeScript
44
star
7

coin-hive-proxy

Deprecated. Use CoinHive Stratum instead.
35
star
8

donger

npm package to generate dongers ヽ༼ຈل͜ຈ༽ノ
JavaScript
29
star
9

minero

a bunch of APIs mashed together
24
star
10

haha

humorous javascript obfuscation tool
JavaScript
16
star
11

nftmarketcap

top non-fungible tokens by (avg) market capitalization
JavaScript
13
star
12

react-redux-perf

Performance Engineering with React + Redux
JavaScript
12
star
13

synaptic-wikipedia

This is the source code for Synaptic's Wikipedia example
JavaScript
11
star
14

cheapbase

like Firebase, but for free (thanks to Heroku).
JavaScript
10
star
15

synaptic-workshop

Synaptic workshop for MuleSoft's MeetUp 2017
JavaScript
8
star
16

decentraland-shoal-scene

Decentraland Shoal Scene
TypeScript
7
star
17

react-storybook-typescript-template

🤸🏻‍♀️Template for a UI library using React + Storybook with TypeScript
JavaScript
7
star
18

earthquakes

just an experiment mixing Firebase open datasets + Google's WebGL Globe
JavaScript
5
star
19

hamster-scene

🐹 A hamster trying to escape from a pipe maze
TypeScript
4
star
20

lysergic

javascript neural network compiler
TypeScript
4
star
21

oliver

⚽️ Bot de Telegram para armar equipos de futbol
JavaScript
3
star
22

cazala.github.io

this is the source of my website
JavaScript
3
star
23

q-cache

simple tool to cache promises
JavaScript
2
star
24

query-to-json

just and endpoint that receives a query and returns a json of it
TypeScript
2
star
25

universal-app

2
star
26

point-e

Text to 3D mesh using OpenAI's Point-E
Python
2
star
27

builder-bot

Twitter bot that tweets every time new content is deployed via Decentraland's Builder
TypeScript
2
star
28

powerhour

tiny app for playing Power Hour (drinking game)
HTML
2
star
29

mana-altar

🔥 Burn MANA collected from Decentraland's Marketplace and light the Altar's flame
TypeScript
1
star
30

screenshots

TypeScript
1
star
31

eth-pictures-bot

✍Twitter bot that tweets new images submitted to https://eth.pictures
JavaScript
1
star
32

react-redux-seed

React + Redux + Router boilterplate
JavaScript
1
star
33

cra-bug-repro

TypeScript
1
star
34

rodo

🐘 HTTP mocking service
JavaScript
1
star
35

log

stdout
CSS
1
star
36

sabe

NodeJS meets ElBananero
JavaScript
1
star
37

universal-gitbook

1
star