Release GIL before detecting faces (#2252)

* Allow the face detector to be run concurrently.

* Use img_view instead of numpy_image

Co-authored-by: Akshay Modi <amodi@netflix.com>
This commit is contained in:
Akshay Naresh Modi 2020-12-13 11:57:41 -08:00 committed by GitHub
parent 7b5b375026
commit 286ca71e1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -52,16 +52,21 @@ namespace dlib
if (is_image<unsigned char>(img))
{
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)
{
detector(numpy_image<unsigned char>(img), rect_detections, adjust_threshold);
detector(img_view, rect_detections, adjust_threshold);
split_rect_detections(rect_detections, rectangles,
detection_confidences, weight_indices);
return rectangles;
}
else
{
pyramid_up(numpy_image<unsigned char>(img), temp, pyr);
pyramid_up(img_view, temp, pyr);
unsigned int levels = upsampling_amount-1;
while (levels > 0)
{
@ -82,16 +87,21 @@ namespace dlib
else if (is_image<rgb_pixel>(img))
{
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)
{
detector(numpy_image<rgb_pixel>(img), rect_detections, adjust_threshold);
detector(img_view, rect_detections, adjust_threshold);
split_rect_detections(rect_detections, rectangles,
detection_confidences, weight_indices);
return rectangles;
}
else
{
pyramid_up(numpy_image<rgb_pixel>(img), temp, pyr);
pyramid_up(img_view, temp, pyr);
unsigned int levels = upsampling_amount-1;
while (levels > 0)
{