google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.59k stars 5.16k forks source link

How to use mediapipe hands javascript model as offline #5729

Open georgelxl6 opened 1 day ago

georgelxl6 commented 1 day ago

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

None

OS Platform and Distribution

Windows

MediaPipe version

0.4.1675469240

Bazel version

No response

Solution

No response

Programming Language and version

Javascript

Describe the actual behavior

No response

Describe the expected behaviour

No response

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

I am using mediapipe/hands in a web app.
And now finding a way to use this on my local machine offline mode.
Is there any solution?

Other info / Complete Logs

No response

kuaashish commented 10 hours ago

Hi @georgelxl6,

Yes, you can run the npm package offline. However, it seems you are using the legacy @mediapipe/hands package (please correct me if I am wrong). This solution has been upgraded and is now part of the Task Vision package https://www.npmjs.com/package/@mediapipe/tasks-vision. Here's an example implementation for the updated Hand Landmarker:

const vision = await FilesetResolver.forVisionTasks(
    "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm"
);
const handLandmarker = await HandLandmarker.createFromModelPath(vision,
    "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/1/hand_landmarker.task"
);
const image = document.getElementById("image") as HTMLImageElement;
const landmarks = handLandmarker.detect(image);

You can find the Hand Landmarker overview here and the web implementation guide here.(https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker) and Implenetation for Web you can find here.

Please note that support for the old package @mediapipe/hands has been discontinued, as mentioned here. Let us know if you encounter any issues!

Thank you!!

georgelxl6 commented 6 hours ago

Hi @kuaashish,

Thank you for your response. Yes, it’s similar to what I’m using now. However, I’m planning to use it locally. The link below will not work offline: https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm

Thank you