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

How to save the model @tensorflow-models/pose-detection locally for offline use? #8334

Closed
ZhongxuYang opened this issue Jul 16, 2024 · 3 comments
Assignees

Comments

@ZhongxuYang
Copy link

I want to save the tfjs-models's models in the public dir of the frontend project, so that they can be used in a netless environment. How should I do it?

  • I tried to save model, but because @tensorflow-models/pose-detection does not provide a save function, I didn't know how to proceed.
@ZhongxuYang ZhongxuYang added the type:bug Something isn't working label Jul 16, 2024
@ZhongxuYang ZhongxuYang changed the title How to save the model @tensorflowmodels/pose detection locally for offline use? How to save the model @tensorflowmodels/pose-detection locally for offline use? Jul 16, 2024
@ZhongxuYang ZhongxuYang changed the title How to save the model @tensorflowmodels/pose-detection locally for offline use? How to save the model @tensorflow-models/pose-detection locally for offline use? Jul 16, 2024
@gaikwadrahul8
Copy link
Contributor

gaikwadrahul8 commented Jul 16, 2024

Hi, @ZhongxuYang

Thank you for bringing this issue to our attention and as far I know, you can download model from kaggle here is link and please make sure select only Model Variations as TensorFlow.js option and download whichever model you want to use and once model got downloaded then please try to load the model with the help of below code snippet and it should work

const tf = require('@tensorflow/tfjs-node');

const modelPath = '/path/to/your/model.json';
const handler = tf.io.fileSystem(modelPath);
const model = await tf.loadLayersModel(handler);

You can also load a model composed of Layer objects, including its topology and optionally weights by below options also please refer to tf.loadLayersModel for examples :

  1. Load a model from an HTTP server.
  2. Save model's topology and weights to browser local storage; then load it back.
  3. Saving model's topology and weights to browser IndexedDB; then load it back.
  4. Load a model from user-selected files from HTML file input elements.

If issue still persists please let us know with error log for further investigation.

Thank you for your cooperation and patience.

@ZhongxuYang
Copy link
Author

Hi, @ZhongxuYang

Thank you for bringing this issue to our attention and as far I know, you can download model from kaggle here is link and please make sure select only Model Variations as TensorFlow.js option and download whichever model you want to use and once model got downloaded then please try to load the model with the help of below code snippet and it should work

const tf = require('@tensorflow/tfjs-node');

const modelPath = '/path/to/your/model.json';
const handler = tf.io.fileSystem(modelPath);
const model = await tf.loadLayersModel(handler);

You can also load a model composed of Layer objects, including its topology and optionally weights by below options also please refer to tf.loadLayersModel for examples :

  1. Load a model from an HTTP server.
  2. Save model's topology and weights to browser local storage; then load it back.
  3. Saving model's topology and weights to browser IndexedDB; then load it back.
  4. Load a model from user-selected files from HTML file input elements.

If issue still persists please let us know with error log for further investigation.

Thank you for your cooperation and patience.

Thank you for your patient reply!

I have followed your tips to fulfill my needs. Proceed as follows:

  1. download model from kaggle here is link
  2. Pass the detectorConfig argument to the poseDetection.createDetector function call.
const loadHandpose = async () => {
  const detectorConfig: MoveNetModelConfig = {
    modelUrl: '/your/public/path',
  }
  detector = await poseDetection.createDetector(model, detectorConfig)
  startDetect()
}

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

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

2 participants