Skip to content
Advertisement

How to get multiprocessing for subtask work with tensorflow-gpu?

Basically I use tf-gpu 2.3rc0 to perform image detection on a video stream. For each loop, there’s a subtask runs separately. So I try to use Pool from multiprocessing The structure is like:

JavaScript

It runs without error, but the tf seems to re-initiate for each frame, resulting to a extremely slow speed… Specifically, the same as follows shows for each loop:

JavaScript

Normally this info only appears once when it the model is loaded. I don’t know how to fix it – is it that I used it wrong or is there some settings of tf I should be aware of?

Advertisement

Answer

it seems likely you’re not only re-initializing tf for each frame, but you’re starting a new process for each frame, then killing it after it’s done. One of the benefits of a Pool is letting some initialization happen in the child process, then keeping it around to execute multiple tasks. I think a simple solution would probably be re-arranging your code to look something like this, though it’s hard to know with what you’ve posted.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement