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

Face Detection not defined #8290

Open
mirzamukkarambaig opened this issue May 29, 2024 · 8 comments
Open

Face Detection not defined #8290

mirzamukkarambaig opened this issue May 29, 2024 · 8 comments

Comments

@mirzamukkarambaig
Copy link

I am creating a React JS-based front end that employs the Tensorflow JS Simple Face Detection model. The application runs fine when being run on the dev environment using npm run dev. However when I run npm run build and npm run preview the model throws the following error:

index-BEYgabte.js:15635 Uncaught (in promise) TypeError: Zse.FaceDetection is not a constructor
    at new t (index-BEYgabte.js:15635:1827)
    at index-BEYgabte.js:15635:3968
    at index-BEYgabte.js:15635:1457
    at Object.next (index-BEYgabte.js:15635:1562)
    at index-BEYgabte.js:15635:499
    at new Promise (<anonymous>)
    at l0 (index-BEYgabte.js:15635:250)
    at SEe (index-BEYgabte.js:15635:3683)
    at index-BEYgabte.js:15635:15604
    at index-BEYgabte.js:15635:1457

I ran the following command for installation

   yarn add @mediapipe/face_detection
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
yarn add @tensorflow-models/face-detection

Got the following warnings:

upgrade
yarn upgrade v1.22.22
[1/4] Resolving packages...
warning @tensorflow-models/face-detection > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning @tensorflow-models/face-detection > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @tensorflow-models/face-detection > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning plotly.js > color-rgba > color-space > mumath@3.3.4: Redundant dependency in your project.
warning webgazer > @tensorflow-models/face-landmarks-detection > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "plotly.js > @plotly/mapbox-gl > @mapbox/mapbox-gl-supported@1.5.0" has unmet peer dependency "mapbox-gl@>=0.32.1 <2.0.0".
warning "webgazer > @tensorflow-models/face-landmarks-detection@0.0.3" has incorrect peer dependency "@tensorflow/tfjs-converter@^3.1.0".
warning "webgazer > @tensorflow-models/face-landmarks-detection@0.0.3" has incorrect peer dependency "@tensorflow/tfjs-core@^3.1.0".
warning "webgazer > @tensorflow-models/face-landmarks-detection > @tensorflow-models/blazeface@0.0.7" has incorrect peer dependency "@tensorflow/tfjs-converter@^3.1.0".
warning "webgazer > @tensorflow-models/face-landmarks-detection > @tensorflow-models/blazeface@0.0.7" has incorrect peer dependency "@tensorflow/tfjs-core@^3.1.0".

This is the picture of the preview
image

This is the picture of the dev
Screenshot from 2024-05-28 18-24-46

@gaikwadrahul8 gaikwadrahul8 self-assigned this May 29, 2024
@gaikwadrahul8 gaikwadrahul8 added comp:react-native type:bug Something isn't working labels May 29, 2024
@gaikwadrahul8
Copy link
Contributor

HI, @mirzamukkarambaig

I apologize for the delayed response and thank you for bringing this issue to our attention, if possible could you please help us with your Github repo along with converted TensorFlow.js models and complete steps to replicate the same behavior from our end to investigate this issue further from our end ?

Thank you from your cooperation and patience.

@mirzamukkarambaig
Copy link
Author

No worries.
Kindly find the code one this repo

the code you will be looking inside the src/utils/detect_faces and src/components/access_webcam files.

@fgsalomon
Copy link

Hi @gaikwadrahul8 ,

Any news on this issue?

I'm seeing the same problem on a Vue 3 app and I'm interested in a solution or workaround.

Thank you.

@gaikwadrahul8
Copy link
Contributor

Hi, @mirzamukkarambaig

Thank you for your patience with the delay in my response. I'm able to replicate the reported behavior using the npm run preview command (output below). Running npm run build produces a different output (also below). We'll need to investigate this issue further and will provide an update soon. thank you for bringing this issue to our attention.

1. Output log of npm run preview command :

image

2. Output of npm run build command :

gaikwadrahul-macbookpro2:Face-Detection-TF-JS gaikwadrahul$ npm run build

> react-js-ai-procotring-tool@0.0.0 build
> vite build

vite v5.2.12 building for production...
✓ 816 modules transformed.
dist/index.html                     0.46 kB │ gzip:   0.29 kB
dist/assets/index-CGXWcEaS.css      6.14 kB │ gzip:   1.84 kB
dist/assets/index-fXzlpHlG.js   1,441.00 kB │ gzip: 271.41 kB

(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 2.75s
gaikwadrahul-macbookpro2:Face-Detection-TF-JS gaikwadrahul$ 

Thank you for your cooperation and patience.

@Jettonn
Copy link

Jettonn commented Jul 24, 2024

@gaikwadrahul8 is there a fix for this issue, cause it's showing on my app too (only when running build dev)?

@klimeryk
Copy link

I've run into the same issue - any updates on the investigation here?

klimeryk added a commit to klimeryk/dealwithit that referenced this issue Sep 30, 2024
Had some issues with tensorflow.js in production, see tensorflow/tfjs#8290

This feels more maintained, though the model does not seem as accurate
as TFJS'. But I'll take it over fighting some old JS code, possibly
needing to fork it, fix some simple import issues just to make Vitejs
happy...
@klimeryk
Copy link

As a workaround, I've switched to using Mediapipe directly, see klimeryk/dealwithit@7d470f6. Since this library uses mediapipe behind the scenes, the data is in very similar format. You just need to multiple the keypoint coordinates by the dimensions of the source image. See full example from Google here: https://codepen.io/mediapipe-preview/pen/OJByWQr. And docs here: https://ai.google.dev/edge/mediapipe/solutions/vision/face_detector/web_js.

The model itself is not as accurate as the "full" model here. Looks like it's somewhere between short and full. But looks like "full" version is on the horizon: https://ai.google.dev/edge/mediapipe/solutions/vision/face_detector/index#blazeface_full-range.

Anyway, figured I'd share in case someone else finds it helpful 🙇

klimeryk added a commit to klimeryk/dealwithit that referenced this issue Oct 12, 2024
It works after tensorflow/tfjs#7905 got fixed
:tada:
But, it's still not possible to use it in production due to tensorflow/tfjs#8290
@klimeryk
Copy link

From my digging, looks like the root issue is vitejs/vite#15851. Seems vite does not like when the library uses imports like import * as faceMesh from '@mediapipe/face_mesh';? And instead would prefer import faceMesh from '@mediapipe/face_mesh';. Or even better import { justStuffYouNeed } from '@mediapipe/face_mesh';.

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

No branches or pull requests

5 participants