Hello, I am trying to train a neural network in the background (or in a tab that is not active).
I am using TFJS (3.11) with React and Ionic to deploy it also for mobile. The training works without problem when the tab of the browser is in foreground or the app is on the foreground with the screen on for the mobile.
When I switch to another tab on the browser or when I turn off the screen of the mobile the training stops. When I go back to the app/web-app the training resumes from where it froze.
Is there a way to keep the app training even when it is moved to the background?
Right now I am trying with web-workers but I am facing some issues with React and I am not guaranteed that it will work.
This is a browser level detail. You do need to have the tab visible on the screen to get processing resource allocated to the tab.
As this is implemented at Browser level it is not something TensorFlow.js can change. The reason for this is that many people have tens of tabs open, if all tabs could have unlimited processing your computer would fast come to a halt or use battery for laptop/mobile pretty fast. Thus only active tabs are given most resources.
As you mentioned, Web Workers at the domain level may be a good bet here. Not sure what the problem with React is, as I am a vanilla JS guy myself, but WebWorkers are well supported at the browser level:
Thank you very much for your reply.
I managed to implement my solution with web workers, and I can confirm that for the browser web app works as intended (even with WebGL) and continues training even when the tab isn’t in the foreground (I am using Edge).
I am still facing issues with the Mobile Ionic App, but I don’t think it is related to TFJS. I will try also with the WASM backend.
Thank you again to your reply
Great to hear! If you are feeling in the mood at some point it would be great to see a blog post or tutorial on your experience here as I am sure others are starting to think about similar things for their own web apps and curious about how others did it. You can shine some light here, I have seen a few folk asking similar questions.