Closed mattrossman closed 3 years ago
I found a way for web worker:
d.D = d.h.GL.currentContext.GLctx
(after d.h.GL.makeContextCurrent(k);
)holistic is fixed in this way too (d.C = d.h.GL.currentContext.GLctx;
and line 993)
Working vanilla js example: https://alexshafir.github.io/Sensoria/ Source: https://github.com/AlexShafir/Sensoria You need to rotate camera on the right in (+X & +Y) direction to see face mesh in 3D.
As for your question about input, I post ImageBitmap and it works.
@AlexShafir Your demo doesn't work for me, what browser are you using? I am testing in Chrome and Firefox.
Here is the error I see in Chrome:
The other problem is that Firefox doesn't fully support OffscreenCanvas which the image gets painted to before prediction, so the ImageBitmap can't be used there:
Lastly, I am curious how you determined that ImageBitmap works as an input, since it is not listed as an input in the type definitions? And can you explain why you added the d.C = d.h.GL.currentContext.GLctx
line?
@mattrossman I am testing on Chrome 94. Just checked rn and it works. Note that on old PC my demo is stuck. I do not consider Firefox, so cannot help there.
How I understood that ImageBitmap works as input - see comment by @tyrmullen. Mediapipe is in alpha -> lots of inconsistencies including type defs.
How I figured why to add said line: that was classic "missing field" bug (I fix such stuff daily, but on Android).
I tested in Chrome 94 as well on both MacOS and Window 10, both machines just show an error in the console.
I didn't know mediapipe is alpha, that's good to know. I will avoid using it in my project due to the difficulties I've faced using it versus the TF.js package.
I tested on both Windows (my own machine) and MacOs (3rd party machine), it worked there.
Oh, I remembered error you talked about. When Mediapipe does not detect face, it outputs 0 instead of result and halts - I did not handle this case. It is a known bug #2434.
For my pet project Mediapipe still lacks Iris tracking, so I chose to move with @tensorflow/face-landmarks-detection. It is also alpha stage, but due to Tensorflow automatically selects backend (cpu, WebGl, WebGpu, wasm/simd/threading).
To make tracking easier, let's continue discussion on #2506 and close this issue as a duplicate. Currently running any JS Solution on a worker thread is not fully supported, but that's something we'd like to allow for.
Please make sure that this is a solution issue.
System information (Please provide as much relevant information as possible)
Describe the expected behavior:
I would like to run
@mediapipe/face_mesh
in a web worker to avoid performance issues with other code on the main thread.Standalone code you may have used to try to get what you need :
I started writing a minimal demo with the assumption that I could make predictions from an
ImageData
object, as was the case with the TF.js distribution of face-landmarks-detection: https://glitch.com/~mediapipe-facemesh-worker-issueHowever I soon realized that according to the mediapipe solution's type definitions, the only accepted input types are HTML elements:
None of these types are available in the worker scope (no DOM access). Additionally, searching for "window" in the JS build reveals a reliance on things like
window.location.pathname
which is also unavailable to workers.Other info / Complete Logs :
A related issue was resolved with the Pose solution earlier in the year: #1509