Created
December 8, 2019 23:31
-
-
Save hsahovic/7fb9a962d2343892a21abf113b3abec6 to your computer and use it in GitHub Desktop.
This gist reproduces the cafee (which is default) image preprocessing used in keras.applications (up to a rescaling factor) with tensorflow.js.
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
let img = await webcam.capture(); | |
let rChannel = img.slice([0,0,0],[192,192,1]).reshape([192,192]); | |
let gChannel = img.slice([0,0,1],[192,192,1]).reshape([192,192]); | |
let bChannel = img.slice([0,0,2],[192,192,1]).reshape([192,192]); | |
img = tf.stack([bChannel, gChannel, rChannel], 2); | |
img = tf.mul(img, 1/255); | |
img = tf.add(img, -.5); | |
img = tf.add(img, [0.0923, 0.0420, 0.1498]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment