Reputation: 31
I'm creating programm to blur people's faces in video and I wanted to use
http://dlib.net/dnn_mmod_face_detection_ex.cpp.html
as base for face recognition because it have great result and quite simple to use. But the problen is - it takes about 75 second to process single image, and that's quite long. dlib library was complied without cuda enabled. My GPU is nvidia geforce gtx 560 ti - it has cuda support, but not cudnn support, and as long as awared, without both librarys it's impossible to compile dlib with cude support. So, because I can't use GPU acceleration natively, is there any way to increase speed of programm? I have some experience with OpenMP, but I don't know if I can use here, because the most longest part in example - this single line
auto dets = net(img);
Upvotes: 0
Views: 921
Reputation: 2462
Your results are typical of using Dlib's DNN without GPU support. There is no meaningful way to speed up the actual code. It is already multithreaded and SIMD / AVX optimized. To speed it up further would require massive effort and probably some assembly code work.
But there may be other options... A lot of the recommendations below depend on your requirements (eg minimum face size to capture, camera setup, etc)
Depending on the resolution of your source video and the minimum size face you want to capture you can call the detection with a 0 as the second argument:
detector(image,0)
This will indicate that you don't want to do any upscaling to your input image. I don't have the documentation in front of me at the moment but I believe that the minimum size face that can be detected with no up scaling is 80px x 80px which might work in your case.
Another option, along the same lines is to down sample your image prior to processing. Assuming you down sample the image by two in each dimension and call with the detector(image,0)
call, you will only be able to detect faces of size 160px x 160px. But the processing speed should be 4 times faster.
If you can generalize places where the face will never be, you can crop your images down to the relevant area and perform the detection. Then just modify the detection boxes to reverse the crop.
If you can't generalize then you might use a different "pre-detector" that is faster like OpenCV's full body and upper body haarcascades. Then crop the image into smaller images using the outputs of those pre-detections and perform the DNN detection on those crops.
Upvotes: 3
Reputation: 70
I only have a suggestion but have you tried simply using OpenCV library for blurring faces?
It supports GPU acceleration. You can read more about UMat
class here: https://jeanvitor.com/opencv-opencl-umat-performance/. You can simply use GaussianBlur
, MedianBlur
or whatever you like quite easily with these objects.
Upvotes: 0