Loading a model twice using multiprocessing to improve performance

asked 2019-03-05 11:18:15 -0500

deepanshu gravatar image

updated 2019-03-05 12:05:24 -0500

berak gravatar image

I have created two processes using multiprocessing in python. Following are the tasks done by the processes Process 1 : This process reads an image from a directory, pre-process it using cv2.dnn.blobFromImage() and puts that blob into a queue.

Process 2: This process loads the config and weights file using net = cv2.dnn.readNetFromDarknet(), fetches the blob from the queue and performs the detection.

As per my understanding, if I have two instances of Process 2, the model will be loaded twice in the memory, and two images can be processed in parallel by these processes. But my observation is that the model is loaded only once, because when I print the address of net object, it is same in both the processes.

Starting producer => 18946 
Starting consumer => 18947 
Starting consumer => 18948 
address of net <dnn_Net 0x7fa6993cf230> 
address of net <dnn_Net 0x7fa6993cf230>

Because of this there is no reduction in the execution time. Please suggest what could be the reason for this or I am missing something basic.

edit retag flag offensive close merge delete


please add your code to the question, else you leave us guessing ..

error is most likely on your side:

>>> cv2.dnn.readNet("C:/data/mdl/udnie.t7")
<dnn_Net 00000065058B7C70>
>>> cv2.dnn.readNet("C:/data/mdl/udnie.t7")
<dnn_Net 00000065058B7810>
berak gravatar imageberak ( 2019-03-05 12:03:04 -0500 )edit