Similar problem here.
I am doing face recognition, not training.
I am using the function dlib.get_frontal_face_detector().
More or less I solve it in this way.
I have the script my_script.py.
Inside it there is the function my_script().
Inside my_script() there are several instructions in particular the dlib functions.
import dlib
def my_script():
dlib.get_frontal_face_detector().
Inside my_script.py there is the function my_script(), plus a classical multithread block of code.
This multithread code works fine with every thread function, but not with my_script() because it contain the DLIB FUNCTIONS.
So, I remove the multithread code and run several my_script.py instances inside the bash shell in background.
my_script.py &
my_script.py &
my_script.py &
etc..
A better solution is to use SUBPROCESS.
So I create another script my_script2.py .
Inside it there are 2 block of code.
A. The funcion my_script2() defined below.
B. A classical multithread block of code.
As thread function I use the function my_script2().
Inside my_script2() there is the command subprocess.run.
The command subprocess.run call my_script.py.
Inside my_script.py there is only the function my_script().
As you can see in the previous example, inside my_script() there is the function dlib.get_frontal_face_detector().
def my_script2():
command='python my_script.py'
os.chdir(directory_of_myscript)
subprocess.run(command,shell=True)
I just want to observe that some people has a similar problem.
OpenCV / Python : multi-threading for live facial recognition
how to use multi-threading for optimizing face detection?