(baseURL, destDir, filename)
| 87 | } |
| 88 | |
| 89 | async function loadImages(baseURL, destDir, filename) { |
| 90 | const buffer = |
| 91 | await fetchOnceAndSaveToDiskWithBuffer(baseURL, destDir, filename); |
| 92 | |
| 93 | const headerBytes = IMAGE_HEADER_BYTES; |
| 94 | const recordBytes = IMAGE_HEIGHT * IMAGE_WIDTH; |
| 95 | |
| 96 | const headerValues = loadHeaderValues(buffer, headerBytes); |
| 97 | tf.util.assert( |
| 98 | headerValues[0] === IMAGE_HEADER_MAGIC_NUM, |
| 99 | () => `Image file header doesn't match expected magic num.`); |
| 100 | tf.util.assert( |
| 101 | headerValues[2] === IMAGE_HEIGHT, |
| 102 | () => `Value in file header (${headerValues[2]}) doesn't ` + |
| 103 | `match the expected image height ${IMAGE_HEIGHT}`); |
| 104 | tf.util.assert( |
| 105 | headerValues[3] === IMAGE_WIDTH, |
| 106 | () => `Value in file header (${headerValues[3]}) doesn't ` + |
| 107 | `match the expected image height ${IMAGE_WIDTH}`); |
| 108 | |
| 109 | const images = []; |
| 110 | let index = headerBytes; |
| 111 | while (index < buffer.byteLength) { |
| 112 | const array = new Float32Array(recordBytes); |
| 113 | for (let i = 0; i < recordBytes; i++) { |
| 114 | // Normalize the pixel values into the 0-1 interval, from |
| 115 | // the original 0-255 interval. |
| 116 | array[i] = buffer.readUInt8(index++) / 255; |
| 117 | } |
| 118 | images.push(array); |
| 119 | } |
| 120 | |
| 121 | tf.util.assert( |
| 122 | images.length === headerValues[1], |
| 123 | () => `Actual images length (${images.length} doesn't match ` + |
| 124 | `value in header (${headerValues[1]})`); |
| 125 | return images; |
| 126 | } |
| 127 | |
| 128 | async function loadLabels(baseURL, destDir, filename) { |
| 129 | const buffer = |
no test coverage detected