easy-mnist allows you to easily access the popular MNIST dataset.
npm i easy-mnist
Here is how you would get a training & testing set.
const mnist = require('easy-mnist')
.makeData(60000, 10000);
mnist.train[index].label
mnist.train[index].image
mnist.test[index].label
mnist.test[index].image
or you can get the entire 70 000 mnist digits in one set.
const mnist = require('easy-mnist')
.Load();
mnist[index].label
mnist[index].image
The index of 1 is the correct label.
console.log(mnist.train[0].label);
// outputs:
// [0,0,0,0,0,1,0,0,0,0]
The white values are 1 and black values are 0.
console.log(mnist.train[0].image);
// outputs:
// array (length of 784)
You can also make your dataset with batches.
const mnist = require('easy-mnist')
.makeBatch(100);
this will create a dataset with 100 length batches for the training & testing set.
You can also shuffle the training & testing set separately like so:
const mnist = require('easy-mnist')
.makeData(60000, 10000, { shuffle: true });
This will not mix the two sets.