Created
September 7, 2018 08:02
-
-
Save zaidalyafeai/9ff6856c37a47db3862f0f2abe5d3e9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function preprocess(imgData) { | |
return tf.tidy(() => { | |
//convert to a tensor | |
const tensor = tf.fromPixels(imgData).toFloat() | |
//resize | |
const resized = tf.image.resizeBilinear(tensor, [256, 256]) | |
//normalize | |
const offset = tf.scalar(127.5); | |
const normalized = resized.div(offset).sub(tf.scalar(1.0)); | |
//We add a dimension to get a batch shape | |
const batched = normalized.expandDims(0) | |
return batched | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment