vladmandic / human

Human: AI-powered 3D Face Detection & Rotation Tracking, Face Description & Recognition, Body Pose Tracking, 3D Hand & Finger Tracking, Iris Analysis, Age & Gender & Emotion Prediction, Gaze Tracking, Gesture Recognition
https://vladmandic.github.io/human/demo/index.html
MIT License
2.16k stars 308 forks source link

Automatic Page Refresh on Image Detection with Human Library in Worker Environment #413

Closed Bobo100 closed 5 months ago

Bobo100 commented 5 months ago

Issue Description I'm encountering what I suspect to be an Out of Memory (OOM) issue on my iPhone SE 2 with iOS 17.2.1, in a basic web application that inputs images and processes them using the Human library for facial detection. My setup only utilizes the face model with all other models disabled.

While using a worker on the iPhone SE 2 (iOS 17.2.1), the webpage automatically refreshes when detecting images, suggesting a potential OOM situation. Interestingly, this issue does not occur when workers are not used, and the application functions normally. Both scenarios have also been tested on a Windows 10 platform with smooth operations.

Human Library Configuration:

{
  "backend": "wasm",
  "modelBasePath": "https://cdn.jsdelivr.net/npm/@vladmandic/human/models",
  "face": {
    "enabled": true,
    "emotion": { "enabled": false },
    "age": { "enabled": false },
    "gender": { "enabled": false },
    "iris": { "enabled": false }
  },
  "body": { "enabled": false },
  "hand": { "enabled": false },
  "object": { "enabled": false },
  "gesture": { "enabled": false },
  "segmentation": { "enabled": false }
}

Environment

Questions:

  1. What could be causing this issue in the worker environment, leading to a potential OOM scenario?
  2. Are there any methods to reduce memory usage to prevent this issue?
  3. Considering that the Human library uses OffscreenCanvas, is it only suitable for Safari on iOS versions 17.0 and above?

Testing URL: Home (human-next-js-worker.vercel.app)

Code Repository: Bobo100/human-next.js-worker (github.com)

Thank you for your assistance and time in addressing this issue.

vladmandic commented 5 months ago

to show if there is memory leak or not, you need to enable debug in configuration and collect browser logs, without that its just a speculation which is not actionable.

and yes, webworkers require offscreencanvas - there is no way around it.

Bobo100 commented 5 months ago

Thank you for your response.

I have enabled debug mode and added some console.log statements for debugging.

Regarding the console results, there haven't been any error messages. In the screenshot I provided (obtained through Mac's Web Inspector), the last console.log message before a forced page refresh is always "human.detect." This has led me to suspect that it might be an out-of-memory (OOM) issue. console

Sometimes, when performance is worse, it will display a message saying "A Problem Repeatedly Occurred on…" before a forced refresh.

I'm not entirely sure if the screenshots I have are what you were referring to. However, I have genuinely conducted numerous tests.

At times, the issue arises with just 5 images, while on other occasions, it can handle up to 18 images without any problems. My biggest challenge is the lack of additional console information, which led me to this speculation.

However, as I mentioned earlier, when I disable the use of worker mode, the issue doesn't occur on an iPhone SE 2 (iOS 17.2.1).

I have also conducted similar tests on other phones without using worker mode: iPhone 15 Plus, iOS 17.1 => OK iPhone SE 3, iOS 16.6 => NG (This might be expected as it doesn't support OffscreenCanvas) iPhone 11, iOS 17.2.1 => NG I haven't yet tested it in worker mode, but I will do so.

In any case, thank you for your response.

Bobo100 commented 5 months ago

Additional supplement

iPhone SE 2 (17.2.1) still automatically refreshes in non-worker mode. Previously, I only uploaded around 20 images, and there were no issues. However, today, when I uploaded more than 20, around 23 or 24, the problem started to occur.”

Thanks.

vladmandic commented 5 months ago

some devices/platforms are just not good enough for web-worker mode.

but if it works for 10 image and and break on 20 - there is no reason for that unless you're either submitting them in parallel or not doing cleanups in your code. i'm sorry i cant say more, but i really cannot spend time analyzing your code.

Bobo100 commented 5 months ago

I think I will double-check my syntax on this end to see if there are any missing cleanups.

Thank you once again for your assistance.