0

My app can't connect Internet all the time, and how to load trained bodypix from local disk? The nodejs code snippet

    const net = await bodyPix.load({
        architecture: 'MobileNetV1',
        outputStride: 16,
        multiplier: 0.75,
        quantBytes: 2,
    });

In README.md I found

modelUrl - An optional string that specifies custom url of the model. This is useful for local development or countries that don't have access > to the models hosted on GCP.

Could you please give me an example what the url is of the local model? and what's the content of the dest model (BTW: how can I download the trained model?). Thanks very much!

Jack Tang
  • 59
  • 5

2 Answers2

1

To load a bodypix model locally you need to download, and host the model's json, and .bin files then access them using the modelUrl option.

Eg:

const net = await bodyPix.load({
    architecture: 'MobileNetV1',
    outputStride: 16,
    multiplier: 0.75,
    quantBytes: 2,
    modelUrl: "/public/model-stride16.json"
});

The url passed to modelUrl must be a valid url.

Guillaume250
  • 502
  • 5
  • 6
0

You should look into Progressive Web Apps if you want to be able to use JavaScript offline like an App.

https://www.smashingmagazine.com/2016/08/a-beginners-guide-to-progressive-web-apps/

https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Offline_Service_workers

Jason Mayes
  • 301
  • 2
  • 8
  • The original question has been edited to clarify that the code is a "nodejs code snippet", for which service workers are not available. While this answer is correct for web apps where self hosting is not neccessary, it does not help with nodejs. – ecc521 Oct 10 '20 at 03:48
  • Ah I see. The bodypix wrapper the team made makes a fetch to server to grab the model files. I guess it wouldn't be too hard to fork that and cache those files locally so it then loads from disk instead? Only way I can think of. – Jason Mayes Oct 10 '20 at 08:08
  • 1
    Since you have to polyfill fetch on NodeJS anyways, the best way would probably be to hijack fetch to pull from a local cache, or fallback to network. That way you don't need to deal with format/location changes, etc, in their files. All you do is cache every request for next time. – ecc521 Oct 11 '20 at 23:44