Last active
February 20, 2020 08:02
-
-
Save Nithanaroy/602b16401e1c64f245c81bceba759c75 to your computer and use it in GitHub Desktop.
Code to parse MNIST Binary Buffer for Training
This file contains 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
static parseBuffer(buffer, offset = 16, isBigEndianProcessor = false) { | |
let allData = null; | |
if (isBigEndianProcessor) { | |
// Let native JavaScript decode the bytes as MNIST dataset is encoded in Big Endian format | |
allData = new Uint8Array(buffer, offset) | |
} | |
else { | |
const dataView = new DataView(buffer); | |
const numBytes = dataView.byteLength - offset; | |
allData = new Uint8Array(numBytes); | |
for (let i = offset, j = 0; i < numBytes; i++ , j++) { | |
allData[j] = dataView.getUint8(i, isBigEndianProcessor); | |
} | |
} | |
return allData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment