Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float32 array returns zeroed out values past index 128 on each row #40

Open
computerjazz opened this issue Feb 21, 2024 · 7 comments
Open

Comments

@computerjazz
Copy link

computerjazz commented Feb 21, 2024

Hi, I'm trying to pipe vision camera output into a tflite face detection model that requires 128x128x3 float32 input. Here's the relevant code:

        const IMAGE_SIZE = 128
        const COLOR_CHANNELS = 3

        const data = resize(frame, {
          crop: {
            x: 0,
            y: 0,
            width: frame.width,
            height: frame.height,
          },
          scale: {
            width: IMAGE_SIZE,
            height: IMAGE_SIZE,
          },
          pixelFormat: 'rgb',
          dataType: 'float32',
        })

        // log out first row of image (and 1st pixel R value of the second row)
        console.log('first row plus 1px', data.slice(0, IMAGE_SIZE * COLOR_CHANNELS + 1))

        const outputs = bfsr.model?.runSync([data])

I was noticing that my face would only be detected if it was in the left side of the screen. Upon inspecting the resized array, I noticed that only the first 128 indices from each row had values:

Screenshot 2024-02-21 at 2 17 40 PM

This did not happen when I changed dataType to uint8:
Screenshot 2024-02-21 at 2 22 02 PM

Am I missing something? Thanks!

@mrousavy
Copy link
Owner

Huh - interesting. iOS or Android?

@computerjazz
Copy link
Author

Observed on iOS

@c-goettert
Copy link

I just noticed the same thing (also on iOS). To verify / understand the content of my frames, I created a simple demo app that stores the frame content returned from the resize plugin and just draws it right below the original image via react-native-skia.
With uint8 it looks just fine:
IMG-20240305-WA0000

But with float32 , only the left side is painted:
IMG-20240305-WA0001

@computerjazz computerjazz changed the title Float32 array returns zeroeded out values past index 128 on each row Float32 array returns zeroed out values past index 128 on each row Mar 5, 2024
@mrousavy
Copy link
Owner

Hey - can you send me a link to a public github repo where I can also see this appear on the left side? That'd help me debug.

@c-goettert
Copy link

I'm not sure if you mean me, but here I have created a demo repository which visualizes the image stream via skia (not really stable, but is suitable for debugging).

@mrousavy
Copy link
Owner

yep perfect, thanks! I'll take a look next week or so :)

@mrousavy
Copy link
Owner

mrousavy commented May 3, 2024

Hey - is this still an issue? cc @rodgomesc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants