Last active
September 30, 2019 21:03
-
-
Save kevinvangelder/aa4dbc797bfb63e479f19597975a8a1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imageToTensor(rawImageData: ArrayBuffer): tf.Tensor3D { | |
const TO_UINT8ARRAY = true; | |
const { width, height, data } = jpeg.decode(rawImageData, TO_UINT8ARRAY); | |
// Drop the alpha channel info for mobilenet | |
const buffer = new Uint8Array(width * height * 3); | |
let offset = 0; // offset into original data | |
for (let i = 0; i < buffer.length; i += 3) { | |
buffer[i] = data[offset]; | |
buffer[i + 1] = data[offset + 1]; | |
buffer[i + 2] = data[offset + 2]; | |
offset += 4; | |
} | |
return tf.tensor3d(buffer, [height, width, 3]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment