原因

按照denseflow教程安装GPU依赖的opencv时报错。CUDA版本与gcc编译器版本不匹配导致,本人环境为

CUDA 10.1
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

可通过以下命令查看:
$ nvcc -V
$ gcc --version

解决

参考类似问题的解决方法 ,修改zzopencv.sh中的cmake编译参数。增加如下两行:

    -DCMAKE_C_COMPILER=$(which gcc-8) \
    -DCMAKE_CXX_COMPILER=$(which g++-8) \

完整cmke编译参数为:

cmake \
    -DBUILD_EXAMPLES=OFF \
    -DWITH_QT=OFF \
    -DCUDA_GENERATION=Auto \
    -DOpenGL_GL_PREFERENCE=GLVND \
    -DBUILD_opencv_hdf=OFF \
    -DBUILD_PERF_TESTS=OFF \
    -DBUILD_TESTS=OFF \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DBUILD_opencv_cnn_3dobj=OFF \
    -DBUILD_opencv_dnn=OFF \
    -DBUILD_opencv_datasets=OFF \
    -DBUILD_opencv_aruco=OFF \
    -DBUILD_opencv_tracking=OFF \
    -DBUILD_opencv_text=OFF \
    -DBUILD_opencv_stereo=OFF \
    -DBUILD_opencv_saliency=OFF \
    -DBUILD_opencv_rgbd=OFF \
    -DBUILD_opencv_reg=OFF \
    -DBUILD_opencv_ovis=OFF \
    -DBUILD_opencv_matlab=OFF \
    -DBUILD_opencv_freetype=OFF \
    -DBUILD_opencv_dpm=OFF \
    -DBUILD_opencv_face=OFF \
    -DBUILD_opencv_dnn_superres=OFF \
    -DBUILD_opencv_dnn_objdetect=OFF \
    -DBUILD_opencv_bgsegm=OFF \
    -DBUILD_opencv_cvv=OFF \
    -DBUILD_opencv_ccalib=OFF \
    -DBUILD_opencv_bioinspired=OFF \
    -DBUILD_opencv_dnn_modern=OFF \
    -DBUILD_opencv_dnns_easily_fooled=OFF \
    -DBUILD_JAVA=OFF \
    -DBUILD_opencv_python2=OFF \
    -DBUILD_NEW_PYTHON_SUPPORT=ON \
    -DBUILD_opencv_python3=OFF \
    -DHAVE_opencv_python3=OFF \
    -DPYTHON_DEFAULT_EXECUTABLE="$(which python)" \
    -DWITH_OPENGL=ON \
    -DWITH_VTK=OFF \
    -DFORCE_VTK=OFF \
    -DWITH_TBB=ON \
    -DWITH_GDAL=ON \
    -DCUDA_FAST_MATH=ON \
    -DWITH_CUBLAS=ON \
    -DWITH_MKL=ON \
    -DMKL_USE_MULTITHREAD=ON \
    -DOPENCV_ENABLE_NONFREE=ON \
    -DWITH_CUDA=ON \
    -DNVCC_FLAGS_EXTRA="--default-stream per-thread" \
    -DWITH_NVCUVID=OFF \
    -DBUILD_opencv_cudacodec=OFF \
    -DMKL_WITH_TBB=ON \
    -DWITH_FFMPEG=ON \
    -DMKL_WITH_OPENMP=ON \
    -DWITH_XINE=ON \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DCMAKE_INSTALL_PREFIX="$ROOTDIR" \
    -DOPENCV_GENERATE_PKGCONFIG=ON \
    -DCMAKE_C_COMPILER=$(which gcc-8) \
    -DCMAKE_CXX_COMPILER=$(which g++-8) \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
    ..

最后成功安装opencv!安装denseflow过程中的其他步骤按照官方说明来就可以。注意环境变量需要自己手动添加。vim ~/.bashrcsource ~/.bashrc

参考

[1] https://github.com/open-mmlab/denseflow
[2] https://github.com/open-mmlab/denseflow/blob/master/INSTALL.md
[3] https://github.com/espressomd/espresso/issues/3654

Logo

更多推荐