Skip to content

Facelandmarker failed to load inside a module web worker #5527

Open
@Hamed-Hassanzadeh

Description

@Hamed-Hassanzadeh

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

Windows 10, Chrome 126

MediaPipe Tasks SDK version

0.10.14

Task name (e.g. Image classification, Gesture recognition etc.)

Face Landmarker

Programming Language and version (e.g. C++, Python, Java)

JavaScript

Describe the actual behavior

Module scripts don't support importScripts() so when you try to run face landmarker in a module web worker it throws an error

Describe the expected behaviour

Should be able to run face landmarker in a module web worker

Standalone code/steps you may have used to try to get what you need

From the main thread:
const myWorker = new Worker("worker.js", { type: "module" });


--------------
worker.js:

import vision from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/vision_bundle.js";
const { FaceLandmarker, FilesetResolver, DrawingUtils } = vision;

async function createFaceLandmarker() {
  const filesetResolver = await FilesetResolver.forVisionTasks(
    "https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/wasm"
  );
  faceLandmarker = await FaceLandmarker.createFromOptions(filesetResolver, {
    baseOptions: {
      modelAssetPath: `https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task`,
      delegate: "GPU"
    },
    outputFaceBlendshapes: true,
    runningMode: "IMAGE",
    numFaces: 1
  });
}
createFaceLandmarker();

------

Error message:

vision_bundle.js:1 Uncaught (in promise) TypeError: Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts().
    at o (vision_bundle.js:1:452684)
    at Array.map (<anonymous>)
    at i (vision_bundle.js:1:452810)
    at createTaskRunner (vision_bundle.js:1:454548)
    at TaskRunner.createInstance (vision_bundle.js:1:454769)
    at VisionTaskRunner.createVisionInstance (vision_bundle.js:1:460257)
    at M.createFromOptions (vision_bundle.js:1:596091)
    at createFaceLandmarker (worker.js:10:47)

Other info / Complete Logs

The "runScript" helper function (https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/web/graph_runner/run_script_helper.ts.template) needs to get updated to support both the classic web workers and module web workers.

Metadata

Metadata

Labels

os:windowsMediaPipe issues on Windowsplatform:javascriptMediaPipe Javascript issuesstat:awaiting googlerWaiting for Google Engineer's Responsetask:face landmarkerIssues related to Face Landmarker: Identify facial features for visual effects and avatars.type:featureEnhancement in the New Functionality or Request for a New Solution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions