(filename)
| 97 | } |
| 98 | |
| 99 | async 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. */ |
| 123 | class MnistDataset { |
no test coverage detected