0

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?

Occam
  • 519
  • 5
  • 18
  • I am pretty sure this is bad practice, but a work-around I found that seems to solve the issue is to overwrite the window object with globalThis – Occam Sep 08 '22 at 18:48

1 Answers1

0

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.

Vladimir Mandic
  • 813
  • 5
  • 11