head-pose-estimation icon indicating copy to clipboard operation
head-pose-estimation copied to clipboard

breaking change : multithreading on windows

Open Makio64 opened this issue 8 years ago • 9 comments

An issue appear since the multithreading update on windows 10.

cv2.dnn cant be pickle during the thread creation.

in mark_detector.py : self.face_net = cv2.dnn.readNetFromCaffe(dnn_proto_text, dnn_model)

Related stackoverflow : https://stackoverflow.com/a/11985056

Makio64 avatar Feb 21 '18 15:02 Makio64

Yes, multithreading is imported to speed up the entire process. However it seems not working on macOS High Sierra which I've tried, and the issue seems to be with OpenCV itself, maybe TBB related.

As there is no Windows PC at hand, I'm afraid Windows users need to figure it out by themselves. Or, this commit without multithreading could be helpful.

yinguobing avatar Feb 22 '18 02:02 yinguobing

Yes, I posted the issue to help futur users to find the commit you indicated below more than getting a support/solution.

Maybe an OS checking or flag to activate or not multithreading will be a easy solution to put on.

PS: Thanks for your work, it helped me a lot! 👍

Makio64 avatar Feb 22 '18 03:02 Makio64

OS checking is a great idea which I should have thought of!

This feature will be added in the next commit. Also please feel free to send any pull request.

yinguobing avatar Feb 22 '18 03:02 yinguobing

Hi everyone. In advance, I'm sorry for bad English. What about creating a thread instead of a process? Something like this (It works on windows):

import threading
#...
    img_queue.put(sample_frame)
    thread = threading.Thread(target=get_face, args=(mark_detector, img_queue, box_queue))
    thread.daemon = True
    thread.start()

ins2718 avatar May 09 '18 20:05 ins2718

@ins2718 Glad you make it work! I'm sure this is helpful for other Windows users.

yinguobing avatar May 10 '18 06:05 yinguobing

The "multiprocess" does not work on Windows. ins2718's code work well.

flyyufenfei123 avatar Jun 02 '18 03:06 flyyufenfei123

@flyyufenfei123 @yinguobing Since as ins2718 said we can replace process with thread. But in the code, there still exists Queue from multiprocessing, and how should we deal with it?

humphreyBristol avatar Jul 13 '18 19:07 humphreyBristol

I guess a pull request will make everybody happy😃

yinguobing avatar Jul 14 '18 06:07 yinguobing

@ins2718 your Thread solution is working, I also got an error in mark_detector.py in self.face_net.setInput(cv2.dnn.blobFromImage( image, 1.0, (300, 300), (104.0, 177.0, 123.0), False)) I removed the last parameter. I don't know what it does, I just read online that this method takes max 5 params. and I commented in estimate_head_pose.py the line print(tm.getTimeSec()/tm.count())

elhammoumi avatar Sep 13 '19 18:09 elhammoumi