Are tools like opencv_traincascade GPU accelerated in OpenCV4Tegra?

I’m looking to use Jetson TK1 for training a classifier. There are some tools available in OpenCV for the same.

I trained a haar classifier using OpenCV’s tool opencv_traincascade. I am using Opencv4Tegra which according to the documentation is CPU optimized and is also built with GPU support but it seems that the opencv_traincascade tool is not GPU accelerated (tegrastats is showing 0% GPU load).

So my question is, for a standard jetson installation of openCV, are tools like opencv_traincascade accelerated? If not what is the best way to get accelerated versions?

Hi aestaq,

To train cascade is meant to be used as an offline tool to create a cascade detector, you should try using a powerful desktop system for training, and then use OpenCV4Tegra on Jetson to run the trained classifier on the device.

There is a CUDA accelerated version of the cascade training tool available in the Ubuntu Desktop x64 version of the OpenCV4Tegra package, which can be downloaded here:
http://developer.nvidia.com/embedded/dlc/l4t-24-1-opencv4tegra-ubuntu

Thanks

Hi kayccc,

Thanks for your reply. I downloaded the Ubuntu Desktop x64 version of the OpenCV4Tegra package you mentioned above and installed it (requires CUDA 7.0) on my Desktop having Nvidia GTX 960M. I ran the opencv_traincascade to train a haar classifier with 20 stages. But it does not seem to use any GPU for training as you can see from the stats given by nvidia-smi tool.

LDD output of opencv_traincascade:

beyond@beyond-asus /tmp/opencv-haar-classifier-training $ ldd /usr/bin/opencv_traincascade 
	linux-vdso.so.1 =>  (0x00007ffee6d8b000)
	libopencv_core.so.2.4 => /usr/lib/libopencv_core.so.2.4 (0x00007fcfc20c4000)
	libopencv_ml.so.2.4 => /usr/lib/libopencv_ml.so.2.4 (0x00007fcfc1e3b000)
	libopencv_imgproc.so.2.4 => /usr/lib/libopencv_imgproc.so.2.4 (0x00007fcfc194f000)
	libopencv_highgui.so.2.4 => /usr/lib/libopencv_highgui.so.2.4 (0x00007fcfc1706000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcfc1400000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcfc10fc000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcfc0ee6000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcfc0b21000)
	libcudart.so.7.0 => /usr/local/cuda-7.0/lib64/libcudart.so.7.0 (0x00007fcfc08c4000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fcfc06ab000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcfc048d000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fcfc0285000)
	libtbb.so.2 => /usr/lib/libtbb.so.2 (0x00007fcfc0051000)
	libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fcfbfdfc000)
	libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fcfbfbd6000)
	libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fcfbf964000)
	libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007fcfbf70d000)
	libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007fcfbf0d0000)
	libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007fcfbee1d000)
	libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fcfbebcc000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fcfbe8c4000)
	libavcodec.so.54 => /usr/lib/x86_64-linux-gnu/libavcodec.so.54 (0x00007fcfbdb70000)
	libavformat.so.54 => /usr/lib/x86_64-linux-gnu/libavformat.so.54 (0x00007fcfbd84e000)
	libavutil.so.52 => /usr/lib/x86_64-linux-gnu/libavutil.so.52 (0x00007fcfbd629000)
	libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007fcfbd3e2000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fcfc268a000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcfbd1de000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fcfbcfbc000)
	libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007fcfbcdae000)
	libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007fcfbcbaa000)
	libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007fcfbc99d000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fcfbc668000)
	libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fcfbc462000)
	libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007fcfbc240000)
	libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007fcfbbf35000)
	libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007fcfbbd14000)
	libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007fcfbb9a1000)
	libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007fcfbb78c000)
	libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007fcfbb53f000)
	libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fcfbb303000)
	libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fcfbb0f9000)
	libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007fcfbaef6000)
	libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007fcfbace6000)
	libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007fcfbaadc000)
	libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007fcfba8d2000)
	libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007fcfba6cf000)
	libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007fcfba4cc000)
	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fcfba2ba000)
	libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fcfba0b2000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fcfb9e74000)
	libxvidcore.so.4 => /usr/lib/x86_64-linux-gnu/libxvidcore.so.4 (0x00007fcfb9b36000)
	libx264.so.142 => /usr/lib/x86_64-linux-gnu/libx264.so.142 (0x00007fcfb97a0000)
	libvpx.so.1 => /usr/lib/x86_64-linux-gnu/libvpx.so.1 (0x00007fcfb93c1000)
	libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007fcfb8ef2000)
	libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007fcfb8cc5000)
	libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007fcfb8a85000)
	libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007fcfb886c000)
	libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007fcfb8653000)
	libschroedinger-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libschroedinger-1.0.so.0 (0x00007fcfb838f000)
	libopus.so.0 => /usr/lib/x86_64-linux-gnu/libopus.so.0 (0x00007fcfb8147000)
	libopenjpeg.so.2 => /usr/lib/x86_64-linux-gnu/libopenjpeg.so.2 (0x00007fcfb7f25000)
	libmp3lame.so.0 => /usr/lib/x86_64-linux-gnu/libmp3lame.so.0 (0x00007fcfb7c98000)
	libgsm.so.1 => /usr/lib/x86_64-linux-gnu/libgsm.so.1 (0x00007fcfb7a8a000)
	libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007fcfb7874000)
	librtmp.so.0 => /usr/lib/x86_64-linux-gnu/librtmp.so.0 (0x00007fcfb765a000)
	libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007fcfb739c000)
	libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007fcfb718c000)
	libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fcfb6ee9000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fcfb6cca000)
	libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007fcfb6a22000)
	libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007fcfb681f000)
	libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007fcfb6616000)
	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fcfb63f3000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fcfb61d8000)
	libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007fcfb5f83000)
	libthai.so.0 => /usr/lib/x86_64-linux-gnu/libthai.so.0 (0x00007fcfb5d7a000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fcfb5b50000)
	libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007fcfb5947000)
	liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007fcfb56c5000)
	libgcrypt.so.11 => /lib/x86_64-linux-gnu/libgcrypt.so.11 (0x00007fcfb5445000)
	libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007fcfb5231000)
	libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007fcfb4fef000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fcfb4deb000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fcfb4be5000)
	libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007fcfb49bf000)
	libdatrie.so.1 => /usr/lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007fcfb47b8000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007fcfb45b3000)
beyond@beyond-asus /tmp/opencv-haar-classifier-training $ ldd /usr/bin/opencv_traincascade |grep cu
	libcudart.so.7.0 => /usr/local/cuda-7.0/lib64/libcudart.so.7.0 (0x00007f913d4b4000)
	libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f91374c2000)

Haar training parameters:

beyond@beyond-asus /tmp/opencv-haar-classifier-training $ opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1500 -numNeg 2058 -w 70 -h 50 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1500
numNeg: 2058
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 70
sampleHeight: 50
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
Number of unique features given windowSize [70,50] : 9657437

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   1500 : 1500
NEG count : acceptanceRatio    2058 : 1
Precalculation time: 15

Please find the attached image showing gpu stats:

Hi aestaq,

There is no attachments in your last post, could you re-attache it?

Thanks

Hi kayccc,

I have re-attached the image file showing gpu stats. The haar parameters and ldd output of opencv_traincascade is shown in the code Block.

Thanks.

Hi aestaq,

That’s too bad… I would have thought the desktop tool would use more GPU. I guess it actually is not using much at all.

Only thing I could suggest is to try going to the latest OpenCV source and seeing if the cascade training tool has improved with it’s GPU utilization.

Thanks