1

I am training a shape predictor using dlib for landmark detection on pictures. Everything works fine so far and my results are decent. I'm using

options = dlib.shape_predictor_training_options()

and

options.num_threads = 12

which is my cpu thread count. I have tried other numbers but however, when training it uses only 1 core.

I want to do training using all my cores, as it takes forever on just 1.

I am using conda env, python 3.5.6 and dlib 18.18 on windows 10. I can't find any solutions in the web for this issue. Hope for help from you guys.

1 Answers1

0

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.

  1. OpenCV / Python : multi-threading for live facial recognition

  2. how to use multi-threading for optimizing face detection?

quine9997
  • 685
  • 7
  • 13