简体   繁体   中英

What is an efficient way to load a tensorFlow.js model (weights & biases) into a web worker context

I am working on loading a tensorFlow model into a multiple web-workers in vanilla JS

I have tried using tf.loadLayersModel("indexeddb://model_name") but it gives a "ReferenceError: window is not defined" error. I am aware that the web-worker does not have access to the window object so no big surprise there. I tried overwriting the window object with self, but it still throws the error.

My understanding is web-workers can access the indexed DB and a few post on git hub https://github.com/tensorflow/tfjs/issues/2643 and https://github.com/tensorflow/tfjs/issues/3402 lead me to believe that tensorflow does infact support the indexed DB inside of web-workers (at least when saving). Is there a way to do this?

If not, is there a good way to encode a model into a ArrayBuffer or SharedArrayBuffer to efficiently upload the data into the webworker context?

i can confirm it works for graph models - loading in web worker from indexdb is fine. i'd suggest to open an issue in tfjs git repo if it fails for layers models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM