Sep-04-2021, 09:31 AM
(This post was last modified: Sep-04-2021, 09:31 AM by samuelbachorik.)
Hi, iam trying to speed up my code by this way. But it is still not working fine. Let me tell you what iam doing.
I have two models that can process image for me. These images are frames from webcam (So it is realtime and it needs to be fast). When i run this serially in for loop it takes a lot of time - first process in model 1 and then in model 2. So i decided to make second process that will be processing image on second model. But i dont see any speed up so I suppose iam doing it wrong.
Can someone tell me what iam doing wrong ?
I have two models that can process image for me. These images are frames from webcam (So it is realtime and it needs to be fast). When i run this serially in for loop it takes a lot of time - first process in model 1 and then in model 2. So i decided to make second process that will be processing image on second model. But i dont see any speed up so I suppose iam doing it wrong.
Can someone tell me what iam doing wrong ?
from multiprocessing.connection import Listener from multiprocessing import Process from multiprocessing.connection import Client #My process that process image on model 1 def run(): address = ('localhost', 6000) listener = Listener(address, authkey='secret password'.encode('utf-8')) conn = listener.accept() while True: try: msg = conn.recv() msg = process_model1(msg) conn.send(msg) except EOFError: pass address = ('localhost', 6000) client = Client(address, authkey='secret password'.encode('utf-8')) for image in frames: # FRAMES ARE FROM WEBCAM, I NEED TO SPEED IT UP client.send(image) # PROCESS IMAGE ON MODEL 1 result_a = process_model2(image) # PROCESS IMAGE ON MODEL 2 result_b = client.recv() # GET RESULT FROM PROCESS # Here iam just mixing results.... if __name__ == '__main__': p = Process(target=run) p.start()
My github:
https://github.com/Samuel-Bachorik
https://github.com/Samuel-Bachorik