diff --git a/tools/python/src/simple_object_detector_py.h b/tools/python/src/simple_object_detector_py.h index 2d16b06e3..10337e237 100644 --- a/tools/python/src/simple_object_detector_py.h +++ b/tools/python/src/simple_object_detector_py.h @@ -52,16 +52,21 @@ namespace dlib if (is_image(img)) { array2d temp; + auto img_view = make_image_view(numpy_image(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(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(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(img)) { array2d temp; + auto img_view = make_image_view(numpy_image(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(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(img), temp, pyr); + pyramid_up(img_view, temp, pyr); unsigned int levels = upsampling_amount-1; while (levels > 0) {