Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hsahovic/7fb9a962d2343892a21abf113b3abec6 to your computer and use it in GitHub Desktop.
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.
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