zaidalyafeai / ml-projects

Implementation of web friendly ML models using TensorFlow.js. pix2pix, face segmentation, fast style transfer and many more ...
MIT License
648 stars 254 forks source link

How to recognize camera data stream images #27

Open zyqq opened 2 years ago

zyqq commented 2 years ago

I preprocess imgData like this

 const imgData = {data: new Uint8Array(frame.data), width: frame.width, height: frame.height}
    return tf.tidy(() => {
        var tensor = tf.browser.fromPixels(imgData, 1)
        const resized = tf.image.resizeBilinear(tensor, [28, 28]).toFloat()
        const offset = tf.scalar(255.0);
        const normalized = tf.scalar(1.0).sub(resized.div(offset));
        const batched = normalized.expandDims(0)
        return batched
   }

but it doesn't work right. Did I make a mistake?