tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.45k stars 1.92k forks source link

React Native Performance Issue #6708

Open realfelixyu opened 2 years ago

realfelixyu commented 2 years ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior

Hi, I've been using the TensorFlow camera feature where I am using MoveNet lightning to detect key joint points. On my OnePlus 7t Pro I'm only getting 8-10 fps. I believe there's some performance issue here.

Describe the expected behavior The specs say iPhone 12 should have 43+ fps but I'm only getting around 20-25. I'm not sure what fps should be like for the OnePlus 7T Pro but 8-10 seems abyssmal.

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.

https://github.com/tensorflow/tfjs-examples/tree/master/react-native/pose-detection

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

darringrove commented 2 years ago

I am seeing similar results with the pose-detection example. I am also testing with MoveNet Lightning, and the FPS is lower with MoveNet Thunder and BlazePose experiments. I'm interested in 3D keypoints, so better performance with RN + BlazePose would be valuable.

yousefamar commented 1 year ago

I have the same FPS on a Galaxy S22 Ultra with pose detection (MoveNet Lightning)

Nevadalol commented 1 year ago

I'm having the same issue with pose-detection example on a Pixel7, it shows ~7fps. I've just cloned the repo and run yarn and yarn start. I've tried to run the example on a ~year ago commit, but nothing changed

sepretf commented 1 year ago

@Nevadalol @yousefamar I have created an API that can be used through a webview, allowing pose estimation with MoveNet at over 20 fps on Android, iOS, or web apps. Check it out at: https://posetracker.com/

yousefamar commented 1 year ago

Thanks for the heads up @sepretf, but for me the whole point of using this repo was to avoid WebView, as that creates other problems in my project, so this is more of a workaround than a solution, and this issue needs to stay open. I don't have high hopes that it will be addressed though. :(

I'm using this as a fallback (in a WebView) for now, and all the logic + rendering is in the WebView, but it's not ideal. I've also found that MoveNet lite is the only model that won't choke on iOS, even though performance is more strained in a WebView than actual Safari.

CreedG commented 1 year ago

Can confirm, with this out of the box example FPS is ~30 on iOS and ~8 even on newer Android phones such as my Samsung Galaxy S22. I've tried my hand at configuring things to improve this, but the problem lies deeper so no luck there.

In the browser context of a WebView, the reverse is true where Android performance is better than iOS. Therefore, for my mobile app I am resorting to running pose detection in a WebView for Android only, and running it natively for iOS. Huge hassle but it works.

Sikaopa commented 9 months ago

I have been facing a similar issue using Blazepose via webview in a React Native App. The reading starts at 30 FPS and starts dropping gradually to reach 7 FPS in matter of 25 seconds. (system info: Iphone 14). Any idea what might be causing this drop from Webview and how to fix it? @yousefamar you mentioned you will also using webview?

yousefamar commented 9 months ago

@Sikaopa, we tested all models across a range of mobile devices, and the general conclusion was that there is no version of Blazepose that will run acceptably within a Webview across all common devices (at least when we did this test a year ago). In some cases it doesn't run at all, in others at too low FPS. Your best bet is to use MoveNet instead for mobile.