Last active
November 15, 2020 15:33
-
-
Save aniketbiprojit/94a4012a8d84ce68b1bdd4d1abede5ff to your computer and use it in GitHub Desktop.
Load MNIST Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code from https://stackoverflow.com/questions/25024179/reading-mnist-dataset-with-javascript-node-js | |
// Author https://stackoverflow.com/users/254532/lilleman | |
// Download files from http://yann.lecun.com/exdb/mnist/ | |
const fs = require('fs') | |
const dataFileBuffer = fs.readFileSync(__dirname + '/train-images-idx3-ubyte') | |
const labelFileBuffer = fs.readFileSync(__dirname + '/train-labels-idx1-ubyte') | |
const load = () => { | |
let pixelValues = [] | |
for (var image = 0; image < 8192; image++) { | |
var pixels = [] | |
for (var x = 0; x <= 27; x++) { | |
for (var y = 0; y <= 27; y++) { | |
pixels.push(dataFileBuffer[image * 28 * 28 + (x + y * 28) + 15]) | |
} | |
} | |
var imageData = {} | |
imageData[JSON.stringify(labelFileBuffer[image + 8])] = pixels | |
pixelValues.push(imageData) | |
} | |
return pixelValues | |
} | |
module.exports = load |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment