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