davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.46k stars 3.37k forks source link

dlib uses low GPU despite DLIB_USE_CUDA is true on Jetson Nano #2263

Closed michalrusinowski closed 3 years ago

michalrusinowski commented 3 years ago

I get something like 1-2 frames per second while trying to process video with dlib on jetson nano.

What I am trying to do is: -> I am getting the video from camera in python3 script (using cv2 and/or gstreamer ) with 1280x720 resolution -> Detect face using dlib.get_frontal_face_detector() -> predict landscape using dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") -> do some calculation

I did a bit of investigation on where is the problem including: -> comment the detector line - this resulted in over 20 frames per second -> leave detector but comment rest of the program - to see if the problem is with detector of something else - this resulted in 1-2 frames per second. -> I found out that before my DLIB_USE_CUDA was False so I reflased my Jetson Nano and used PIP3 to install dlib. My DLIB_USE_CUDA shows true now. -> I checked jtop to see where is the bottleneck -> first of all I noticed that openCV is not compiled with cuda so I went thru https://gist.github.com/raulqf/f42c718a658cddc16f9df07ecc627be7

I've seen some folks uxing Jetson xavier and they say they have 12 fps, but this is not solution - they have 12 fps because Xavier has better CPU - not that system uses cuda. I also tried to run the program on my desktop with i7 and nvidia GPU and - yes, i have 12 - 15 fps but GPU performance is also superlow.

Expected Behavior

I am sure that we can get faster video processing - normally with resolution 1280 x 720 I would expect 12 - 15 fps... I would also expect much higher GPU usage because now it seams to be compleatly idle

I would expect something like below example of system performance for script that uses CUDA

Zrzut ekranu z 2020-12-15 13-38-29

Current Behavior

-> I have 1-2 frames per second which looks more like slideshow than video ;) -> Still GPU is Idle Zrzut ekranu z 2020-12-15 13-21-16 -> It is also not the problem with memory - it look like dlib uses only one thread of CPU instead of GPU . Zrzut ekranu z 2020-12-15 13-27-01

Steps to Reproduce

System setup Distributor ID: Ubuntu Description: Ubuntu 18.04.5 LTS Release: 18.04 Codename: bionic hardware - Jetson Nano Jetpack - 4.4.1 Python - 3.6 OpenCV - 4.2 (with cuda compiled)

Dlib - 19.21.0 Where did you get dlib: installed it using pip3 - so that's official i guess

Platform: Distributor ID: Ubuntu Description: Ubuntu 18.04.5 LTS Release: 18.04 Codename: bionic

Compiler: gcc version 6.5.0 20181026 (Ubuntu/Linaro 6.5.0-2ubuntu1~18.04) cmake version 3.10.2

arrufat commented 3 years ago

Hi, dlib.get_frontal_face_detector does not use the GPU, you should use dlib.cnn_face_detection_model_v1 instead if you want to use the GPU for that. Check this example on how to use it.

michalrusinowski commented 3 years ago

Thanks a lot @arrufat, it shows now high GPU usage. The performance is still very weak but I guess problem is somewhere else :( i can see now that HW engines are off - perhaps that is the problem. i am not sure if cnn_face_detection_model_v1 is just more resource consuming that get_frontal_face_detector().

arrufat commented 3 years ago

I've never worked with a Jetson, but I can tell you that, for an 800x448 image (coming from the webcam) on a 1080Ti, that cnn face detector can run at around 100 fps, and the camera is sending images at 30 fps, so more than enough.

dlib-issue-bot commented 3 years ago

Warning: this issue has been inactive for 35 days and will be automatically closed on 2021-01-30 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 3 years ago

Warning: this issue has been inactive for 43 days and will be automatically closed on 2021-01-30 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot commented 3 years ago

Notice: this issue has been closed because it has been inactive for 45 days. You may reopen this issue if it has been closed in error.

Rikhsitilla commented 3 years ago

Hi , also has such a problem , does anyone could solve?