GoLang et OpenCV (OpenVino && Cuda)

Bonne journée à tous. Il y a déjà beaucoup d'articles sur le travail avec OpenCV on Go sur le hub ( et en effet sur Internet ).

Le code fini est certainement intĂ©ressant, mais des informations plus dĂ©taillĂ©es sur l'installation des pilotes doivent ĂȘtre collectĂ©es en plusieurs parties - j'essaierai de combiner tous les gestes nĂ©cessaires dans un seul article.

image


J'ai un ordinateur portable avec Ubuntu 18.04 Ă  bord,

  • CPU: Intel
  • GPU: Intel / Nvidia

Nvidia et Intel essaient de se battre, et j'essaierai de profiter d'OpenVino et de Cuda en mĂȘme temps.
Je vous préviens tout de suite, pour utiliser Cuda, vous avez besoin d'une capacité de calcul minimale (version) 5.3, vous pouvez voir votre carte vidéo ici

Cuda


J'ai choisi Cuda 10.0 pour pouvoir Ă©galement utiliser Tensorflow.

Vous devez d'abord télécharger un package avec developer.nvidia.com (comme la

image

commande Set runtime (local) ) Set

sudo sh cuda_10.0.130_410.48_linux.run


cudNN


Lien vers les packages
Vous devez sélectionner la version qui correspond à Cuda, c'est-à-dire
Télécharger cuDNN v7.5.0 (21 février 2019), pour CUDA 10.0

image

Et téléchargez deux packages deb
BibliothÚque de développeur cuDNN pour Ubuntu18.04 (Deb)
BibliothÚque de développeur cuDNN pour Ubuntu18.04 (Deb)

Si vous ne disposez pas d'un compte https://developer.nvidia.com/ , vous serez invité à enregistrer l'

image

installation:

sudo dpkg -i libcudnn7-dev_7.5.0.56-1+cuda10.0_amd64.deb
sudo dpkg -i libcudnn7_7.5.0.56-1+cuda10.0_amd64.deb

Pilote Intel OpenCL


Lien vers le référentiel .

Installation:

wget https://github.com/intel/compute-runtime/releases/download/20.04.15428/intel-gmmlib_19.4.1_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/20.04.15428/intel-igc-core_1.0.3151_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/20.04.15428/intel-igc-opencl_1.0.3151_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/20.04.15428/intel-opencl_20.04.15428_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/20.04.15428/intel-ocloc_20.04.15428_amd64.deb

sudo dpkg -i *.deb

Opencv + OpenVino

Script (naturellement avec des bĂ©quilles), qui collectera tout par lui-mĂȘme.

run.sh
#!/bin/bash
git clone https://github.com/opencv/dldt -b 2019 && \
            (cd dldt/inference-engine && \
            git submodule init && \
            git submodule update --recursive && \
            ./install_dependencies.sh && \
            mv -f thirdparty/clDNN/common/intel_ocl_icd/6.3/linux/Release thirdparty/clDNN/common/intel_ocl_icd/6.3/linux/RELEASE && \
            mkdir -p build && \
            cd build && \
            cmake -D CMAKE_BUILD_TYPE=RELEASE \
                  -D CMAKE_INSTALL_PREFIX=/usr/local \
                  -D BUILD_SHARED_LIBS=ON \
                  -D ENABLE_TESTS=OFF \
                  -D ENABLE_VPU=ON \
                  -D ENABLE_MKL_DNN=ON \
                  -D ENABLE_CLDNN=ON .. && \
                  make -j $(nproc --all) && \
                  touch VERSION && \
                  mkdir -p src/ngraph && \
                  sudo cp -r ../bin/intel64/RELEASE/lib/* /usr/local/lib && \
                  cp thirdparty/ngraph/src/ngraph/version.hpp src/ngraph && \
                  sudo make install)

OPENCV_VERSION="4.2.0"

# install opencv
curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
            unzip -q opencv.zip && \
            curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
            unzip -q opencv_contrib.zip && \
            rm opencv.zip opencv_contrib.zip && \
            (cd opencv-${OPENCV_VERSION} && \
            mkdir build && cd build && \
            cmake -D CMAKE_BUILD_TYPE=RELEASE \
                  -D CMAKE_INSTALL_PREFIX=/usr/local \
                  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
                  -D InferenceEngine_DIR=../../../dldt/inference-engine/build \
                  -D WITH_JASPER=OFF \
                  -D BUILD_DOCS=OFF \
                  -D BUILD_EXAMPLES=OFF \
                  -D ENABLE_CXX11=ON \
                  -D WITH_INF_ENGINE=ON \
                  -D WITH_QT=OFF \
                  -D WITH_GTK=ON \
                  -D WITH_FFMPEG=OFF \
                  -D CUDA_ARCH_BIN=5.3,6.0,6.1,7.0,7.5 \
                  -D CUDA_ARCH_PTX=5.3 \
                  -D WITH_CUDA=ON \
                  -D WITH_CUDNN=ON \
                  -D OPENCV_DNN_CUDA=ON \
                  -D ENABLE_FAST_MATH=1 \
                  -D WITH_CUBLAS=1 \
                  -D WITH_TIFF=OFF \
                  -D WITH_WEBP=OFF \
                  -D WITH_QT=OFF \
                  -D WITH_PNG=OFF \
                  -D WITH_1394=OFF \
                  -D HAVE_OPENEXR=OFF \
                  -D BUILD_TESTS=OFF \
                  -D BUILD_PERF_TESTS=OFF \
                  -D BUILD_opencv_java=NO \
                  -D BUILD_opencv_python=NO \
                  -D BUILD_opencv_python2=NO \
                  -D BUILD_opencv_python3=NO \
                  -D BUILD_SHARED_LIBS=ON \
                  -D OPENCV_GENERATE_PKGCONFIG=ON .. && \
            make -j $(nproc --all) && \
            sudo make preinstall && sudo make install && sudo ldconfig )


Voyons maintenant comment cela fonctionnera!

Nous clonons nous-mĂȘmes le code source:

git clone https://github.com/Danile71/go_realtime_object_recognition
cd go_realtime_object_recognition
go get -d
go build
./go_realtime_object_recognition

La reconnaissance vidéo fonctionnera sur CPU, VulkanAPI et / ou Cuda.

Maintenant, j'ai fait plusieurs demandes de tirage dans
github.com/hybridgroup/gocv

pour prendre en charge OpenVino + Cuda, mais on ne sait pas combien de temps ils iront Ă  la branche principale, alors faisons un petit tour:

#!/bin/bash
cd $GOPATH/src/gocv.io/x/gocv
wget https://patch-diff.githubusercontent.com/raw/hybridgroup/gocv/pull/607.patch
wget https://patch-diff.githubusercontent.com/raw/hybridgroup/gocv/pull/609.patch
wget https://patch-diff.githubusercontent.com/raw/hybridgroup/gocv/pull/610.patch
wget https://patch-diff.githubusercontent.com/raw/hybridgroup/gocv/pull/612.patch

patch -p1 < 607.patch
patch -p1 < 609.patch
patch -p1 < 610.patch
patch -p1 < 612.patch

Pour pouvoir utiliser OpenVino / CPU / VulkanAPI / Cuda en mĂȘme temps

go build -tags openvino
./go_realtime_object_recognition

Et pour sélectionner un appareil, changez

  • CPU

    modelNet.SetPreferableBackend(gocv.NetBackendDefault)
    modelNet.SetPreferableTarget(gocv.NetTargetCPU)
    

  • VulkanAPI

    modelNet.SetPreferableBackend(gocv.NetBackendVKCOM)
    modelNet.SetPreferableTarget(gocv.NetTargetVulkan)
    

  • Cuda
    modelNet.SetPreferableBackend(gocv.NetBackendCUDA)
    modelNet.SetPreferableTarget(gocv.NetTargetCUDA)
    

  • Intel GPU

    modelNet.SetPreferableBackend(gocv.NetBackendOpenVINO)
    modelNet.SetPreferableTarget(gocv.NetTargetFP16)
    

  • Intel Neural Compute Stick 2
    modelNet.SetPreferableBackend(gocv.NetBackendOpenVINO)
    modelNet.SetPreferableTarget(gocv.NetTargetVPU)
    


Voici un autre petit exemple de reconnaissance de genre / Ăąge / Ă©motion.

Et puis reconnaissance de l’objet «humain» Ă  l’aide de Cuda.

Si quelqu’un est intĂ©ressĂ© et que quelque chose n’a pas fonctionnĂ©, Ă©crivez,

je serai heureux de vous aider :-) Tchouktche n’est pas Ă©crivain, mais j’ai essayĂ©.

upd.
Il y a des moments oĂč vous devez crĂ©er un binaire statique; pour cela, remplacez dldt et opencv dans l'assembly
-D BUILD_SHARED_LIBS=ON

sur le
-D BUILD_SHARED_LIBS=OFF

Source: https://habr.com/ru/post/undefined/


All Articles