From 86fa427e26c9b3945372e053b0cd7f47af4d1092 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 10 Sep 2016 15:29:06 -0400 Subject: [PATCH] Made input_rgb_image_pyramid use multiple cores while building the pyramid. --- dlib/dnn/input.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/dlib/dnn/input.h b/dlib/dnn/input.h index 95e0a8b7d..52fcee0dd 100644 --- a/dlib/dnn/input.h +++ b/dlib/dnn/input.h @@ -567,15 +567,21 @@ namespace dlib } - matrix img; - create_tiled_pyramid(*ibegin, img, data.annotation().get>()); - nr = img.nr(); - nc = img.nc(); - data.set_size(std::distance(ibegin,iend), 3, nr, nc); + std::vector> imgs(std::distance(ibegin,iend)); + parallel_for(0, imgs.size(), [&](long i){ + std::vector rects; + if (i == 0) + create_tiled_pyramid(ibegin[i], imgs[i], data.annotation().get>()); + else + create_tiled_pyramid(ibegin[i], imgs[i], rects); + }); + nr = imgs[0].nr(); + nc = imgs[0].nc(); + data.set_size(imgs.size(), 3, nr, nc); const size_t offset = nr*nc; auto ptr = data.host(); - while(true) + for (auto&& img : imgs) { for (long r = 0; r < nr; ++r) { @@ -592,11 +598,6 @@ namespace dlib } } ptr += offset*(data.k()-1); - - ++ibegin; - if (ibegin == iend) - break; - create_tiled_pyramid(*ibegin, img, data.annotation().get>()); } }