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

Function loadLabels

quantization/data_mnist.js:128–155  ·  view source on GitHub ↗
(baseURL, destDir, filename)

Source from the content-addressed store, hash-verified

126}
127
128async function loadLabels(baseURL, destDir, filename) {
129 const buffer =
130 await fetchOnceAndSaveToDiskWithBuffer(baseURL, destDir, filename);
131
132 const headerBytes = LABEL_HEADER_BYTES;
133 const recordBytes = LABEL_RECORD_BYTE;
134
135 const headerValues = loadHeaderValues(buffer, headerBytes);
136 tf.util.assert(
137 headerValues[0] === LABEL_HEADER_MAGIC_NUM,
138 () => `Label file header doesn't match expected magic num.`);
139
140 const labels = [];
141 let index = headerBytes;
142 while (index < buffer.byteLength) {
143 const array = new Int32Array(recordBytes);
144 for (let i = 0; i < recordBytes; i++) {
145 array[i] = buffer.readUInt8(index++);
146 }
147 labels.push(array);
148 }
149
150 tf.util.assert(
151 labels.length === headerValues[1],
152 () => `Actual labels length (${images.length} doesn't match ` +
153 `value in header (${headerValues[1]})`);
154 return labels;
155}
156
157/** Helper class to handle loading training and test data. */
158export class MnistDataset {

Callers 1

loadDataMethod · 0.70

Calls 2

loadHeaderValuesFunction · 0.70

Tested by

no test coverage detected