当我尝试在启用推理引擎的情况下编译 OpenCv 时,出现错误

Posted

技术标签:

【中文标题】当我尝试在启用推理引擎的情况下编译 OpenCv 时,出现错误【英文标题】:When I try to compile OpenCv with inference engine enabled, I am getting an error 【发布时间】:2019-02-09 16:31:34 【问题描述】:

如果我尝试在启用推理引擎的情况下构建 OpenCV 4.0.0,我会收到以下错误:

1>------ Build started: Project: opencv_dnn, Configuration: Release x64 ------
1>dnn.cpp
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(1595): error C2259: 'cv::dnn::InfEngineBackendNet': cannot instantiate abstract class
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(1595): note: due to following members:
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(1595): note: 'InferenceEngine::StatusCode InferenceEngine::ICNNNetwork::serialize(const std::string &,const std::string &,InferenceEngine::ResponseDesc *) noexcept const': is abstract
1>C:\local\Intel\computer_vision_sdk_2018.5.445\deployment_tools\inference_engine\include\ie_icnn_network.hpp(190): note: see declaration of 'InferenceEngine::ICNNNetwork::serialize'
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(2556): error C2259: 'cv::dnn::InfEngineBackendNet': cannot instantiate abstract class
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(2556): note: due to following members:
1>C:\local\opencv-4.0.0\modules\dnn\src\dnn.cpp(2556): note: 'InferenceEngine::StatusCode InferenceEngine::ICNNNetwork::serialize(const std::string &,const std::string &,InferenceEngine::ResponseDesc *) noexcept const': is abstract
1>C:\local\Intel\computer_vision_sdk_2018.5.445\deployment_tools\inference_engine\include\ie_icnn_network.hpp(190): note: see declaration of 'InferenceEngine::ICNNNetwork::serialize'
1>Done building project "opencv_dnn.vcxproj" -- FAILED.

为什么会出现这个错误?

编辑

Cmake 输出为:

Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
AVX_512F is not supported by C++ compiler
AVX512_SKX is not supported by C++ compiler
Dispatch optimization AVX512_SKX is not available, skipped
libjpeg-turbo: VERSION = 1.5.3, BUILD = opencv-4.0.0-libjpeg-turbo
Looking for Mfapi.h
Looking for Mfapi.h - found
found Intel IPP (ICV version): 2019.0.0 [2019.0.0 Gold]
at: C:/local/opencv-build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2019.0.0
at: C:/local/opencv-build/3rdparty/ippicv/ippicv_win/iw
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find BLAS (missing: BLAS_LIBRARIES) 
LAPACK requires BLAS
A library with LAPACK API not found. Please specify library location.
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 
Detected InferenceEngine: cmake package
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: C:/local/opencv-build/python_loader
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp

General configuration for OpenCV 4.0.0 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2019-02-09T13:06:47Z
    Host:                        Windows 10.0.17134 AMD64
    CMake:                       3.13.0-rc3
    CMake generator:             Visual Studio 15 2017 Win64
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe
    MSVC:                        1916

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (7 files):          + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (13 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      NO
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe  (ver 19.16.27026.1)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /MT /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4    /MT /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4  /MTd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          IE::inference_engine ade comctl32 gdi32 ole32 setupapi ws2_32
    3rdparty dependencies:       ittnotify libprotobuf zlib libjpeg-turbo libwebp libpng libtiff libjasper IlmImf quirc ippiw ippicv

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java_bindings_generator ml objdetect photo python3 python_bindings_generator stitching ts video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 java js python2
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 1.5.3-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.35)
    TIFF:                        build (ver 42 - 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (ver 58.35.100)
      avformat:                  YES (ver 58.20.100)
      avutil:                    YES (ver 56.22.100)
      swscale:                   YES (ver 5.3.100)
      avresample:                YES (ver 4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2019.0.0 Gold [2019.0.0]
           at:                   C:/local/opencv-build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2019.0.0)
              at:                C:/local/opencv-build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Inference Engine:            YES (2018040000 / 1.5.0)
                libs:            C:/local/Intel/computer_vision_sdk_2018.5.445/deployment_tools/inference_engine/lib/intel64/Release/inference_engine.lib / C:/local/Intel/computer_vision_sdk_2018.5.445/deployment_tools/inference_engine/lib/intel64/Debug/inference_engined.lib
            includes:            C:/local/Intel/computer_vision_sdk_2018.5.445/deployment_tools/inference_engine/include
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                C:/local/opencv-4.0.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 C:/Program Files/Python36/python.exe (ver 3.6.5)
    Libraries:                   C:/Program Files/Python36/libs/python36.lib (ver 3.6.5)
    numpy:                       C:/Users/m/AppData/Roaming/Python/Python36/site-packages/numpy/core/include (ver 1.15.4)
    packages path:               C:/Program Files/Python36/Lib/site-packages

  Python (for build):            C:/Program Files/Python36/python.exe

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/local/opencv
-----------------------------------------------------------------

Configuring done

【问题讨论】:

请指定您尝试使用哪个版本的 IE 构建 OpenCV。什么是 IE 的版本由 OpenCV 确定(参见控制台的 CMake 摘要)? @DmitryKurtaev 请在问题的编辑部分找到 cmake 输出。 IE 版本被确定为2018040000。这意味着您使用的是不支持 R5 版本的旧 OpenCV 版本,或者您没有清理构建文件夹。 @DmitryKurtaev 我使用了来自 openCV.org 的 OpenCv 4.0.0,还安装了最新版本的 OpenVino。事实上,我有旧版本的 OpenVino,我将其删除并升级到最新版本。 Cmake如何查找OpenVino版本或IE版本? 默认情况下,OpenCV 设置 IE 的最新可用版本(请参阅github.com/opencv/opencv/blob/…)。 OpenCV 4.0.0 发布日期为 [Nov 18, 2018],早于 OpenVINO R5 发布。这意味着默认版本是 2018040000。我强烈建议您在本地更新 OpenCV。 【参考方案1】:

总结我们在cmets中的讨论,

OpenVINO R5 于 12 月发布,但随附的 CMake 摘要显示使用的 OpenCV 版本较旧(11 月)。因此解决方案是将 OpenCV 更新到支持 Intel 推理引擎的 OpenVINO R5 的最新版本。

关于如何在 IE 支持下构建 OpenCV 的 Wiki:https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend

【讨论】:

以上是关于当我尝试在启用推理引擎的情况下编译 OpenCv 时,出现错误的主要内容,如果未能解决你的问题,请参考以下文章

AssertionError:Torch 未在启用 CUDA 的情况下编译

在我的 CLR 项目中添加包含会使 WLR 无法在启用 /clr 的情况下编译

如何在没有 Ivy 的情况下编译库?

ios下编译opencv

在linux下编译opencv for android

在release模式下编译opencv写的人脸检测代码,提示:无法打开输入文件“opencv_calib3d244.lib”