You need to sign in or sign up before continuing.
Unverified Commit 286ca71e authored by Akshay Naresh Modi's avatar Akshay Naresh Modi Committed by GitHub
Browse files

Release GIL before detecting faces (#2252)



* Allow the face detector to be run concurrently.

* Use img_view instead of numpy_image
Co-authored-by: default avatarAkshay Modi <amodi@netflix.com>
parent 7b5b3750
...@@ -52,16 +52,21 @@ namespace dlib ...@@ -52,16 +52,21 @@ namespace dlib
if (is_image<unsigned char>(img)) if (is_image<unsigned char>(img))
{ {
array2d<unsigned char> temp; array2d<unsigned char> temp;
auto img_view = make_image_view(numpy_image<unsigned char>(img));
// Release the GIL so that this code can be run in parallel.
py::gil_scoped_release release;
if (upsampling_amount == 0) if (upsampling_amount == 0)
{ {
detector(numpy_image<unsigned char>(img), rect_detections, adjust_threshold); detector(img_view, rect_detections, adjust_threshold);
split_rect_detections(rect_detections, rectangles, split_rect_detections(rect_detections, rectangles,
detection_confidences, weight_indices); detection_confidences, weight_indices);
return rectangles; return rectangles;
} }
else else
{ {
pyramid_up(numpy_image<unsigned char>(img), temp, pyr); pyramid_up(img_view, temp, pyr);
unsigned int levels = upsampling_amount-1; unsigned int levels = upsampling_amount-1;
while (levels > 0) while (levels > 0)
{ {
...@@ -82,16 +87,21 @@ namespace dlib ...@@ -82,16 +87,21 @@ namespace dlib
else if (is_image<rgb_pixel>(img)) else if (is_image<rgb_pixel>(img))
{ {
array2d<rgb_pixel> temp; array2d<rgb_pixel> temp;
auto img_view = make_image_view(numpy_image<rgb_pixel>(img));
// Release the GIL so that this code can be run in parallel.
py::gil_scoped_release release;
if (upsampling_amount == 0) if (upsampling_amount == 0)
{ {
detector(numpy_image<rgb_pixel>(img), rect_detections, adjust_threshold); detector(img_view, rect_detections, adjust_threshold);
split_rect_detections(rect_detections, rectangles, split_rect_detections(rect_detections, rectangles,
detection_confidences, weight_indices); detection_confidences, weight_indices);
return rectangles; return rectangles;
} }
else else
{ {
pyramid_up(numpy_image<rgb_pixel>(img), temp, pyr); pyramid_up(img_view, temp, pyr);
unsigned int levels = upsampling_amount-1; unsigned int levels = upsampling_amount-1;
while (levels > 0) while (levels > 0)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment