MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / loadLabels

Function loadLabels

mnist-node/data.js:99–120  ·  view source on GitHub ↗
(filename)

Source from the content-addressed store, hash-verified

97}
98
99async function loadLabels(filename) {
100 const buffer = await fetchOnceAndSaveToDiskWithBuffer(filename);
101
102 const headerBytes = LABEL_HEADER_BYTES;
103 const recordBytes = LABEL_RECORD_BYTE;
104
105 const headerValues = loadHeaderValues(buffer, headerBytes);
106 assert.equal(headerValues[0], LABEL_HEADER_MAGIC_NUM);
107
108 const labels = [];
109 let index = headerBytes;
110 while (index < buffer.byteLength) {
111 const array = new Int32Array(recordBytes);
112 for (let i = 0; i < recordBytes; i++) {
113 array[i] = buffer.readUInt8(index++);
114 }
115 labels.push(array);
116 }
117
118 assert.equal(labels.length, headerValues[1]);
119 return labels;
120}
121
122/** Helper class to handle loading training and test data. */
123class MnistDataset {

Callers 1

loadDataMethod · 0.70

Calls 2

loadHeaderValuesFunction · 0.70

Tested by

no test coverage detected