Skip to content

Instantly share code, notes, and snippets.

@Nithanaroy
Last active February 20, 2020 08:02
Show Gist options
  • Save Nithanaroy/602b16401e1c64f245c81bceba759c75 to your computer and use it in GitHub Desktop.
Save Nithanaroy/602b16401e1c64f245c81bceba759c75 to your computer and use it in GitHub Desktop.
Code to parse MNIST Binary Buffer for Training
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