本文介绍了如何处理“DNN模块不是用CUDA后端构建的;切换到 CPU"C++中的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio 2019 上使用 CUDA 10.2 和 cuDNN v7.6.5 在 Windows 10 上使用 NVidia GeForce 930M 运行 YOLOv3.这是我使用的部分代码.

I am trying to run YOLOv3 on Visual Studio 2019 using CUDA 10.2 with cuDNN v7.6.5 on Windows 10 using NVidia GeForce 930M. Here is part of the code I used.

#include <fstream>
#include <sstream>
#include <iostream>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;
using namespace dnn;
using namespace std;

int main()
{
    // Load names of classes
    string classesFile = "coco.names";
    ifstream ifs(classesFile.c_str());
    string line;
    while (getline(ifs, line)) classes.push_back(line);

    // Give the configuration and weight files for the model
    String modelConfiguration = "yolovs.cfg";
    String modelWeights = "yolov3.weights";

    // Load the network
    Net net = readNetFromDarknet(modelConfiguration, modelWeights);
    net.setPreferableBackend(DNN_BACKEND_CUDA);
    net.setPreferableTarget(DNN_TARGET_CUDA);

    // Open the video file
    inputFile = "vid.mp4";
    cap.open(inputFile);

    // Get frame from the video
    cap >> frame;

    // Create a 4D blob from a frame
    blobFromImage(frame, blob, 1 / 255.0, Size(inpWidth, inpHeight), Scalar(0, 0, 0), true, false);

    // Sets the input to the network
    net.setInput(blob);

    // Runs the forward pass to get output of the output layers
    vector<Mat> outs;
    net.forward(outs, getOutputsNames(net));
}

虽然我在 C/C++ 中将 $(CUDNN)\include;$(cudnn)\include; 添加到 附加包含目录链接器,在C/C++>预处理器定义中添加了CUDNN_HALF;CUDNN;,并添加了cudnn.lib;链接器>输入,我仍然收到此警告:

Although I add $(CUDNN)\include;$(cudnn)\include; to Additional Include Directories in both C/C++ and Linker, added CUDNN_HALF;CUDNN; to C/C++>Preprocessor Definitions, and added cudnn.lib; to Linker>Input, I still get this warning:

DNN 模块不是用 CUDA 后端构建的;切换到 CPU

它在 CPU 而不是 GPU 上运行,有人能帮我解决这个问题吗?

and it runs on CPU instead of GPU, can anyone help me with this problem?

推荐答案

我使用 CMake 解决了这个问题,但我必须先添加这个 opencv_contrib 然后使用 Visual Studio 重建它.确保选中这些WITH_CUDAWITH_CUBLASWITH_CUDNNOPENCV_DNN_CUDABUILD_opencv_worldCMake 中.

I solved it by using CMake, but I had first to add this opencv_contrib then rebuilding it using Visual Studio. Make sure that these WITH_CUDA, WITH_CUBLAS, WITH_CUDNN, OPENCV_DNN_CUDA, BUILD_opencv_world are checked in CMake.

这篇关于如何处理“DNN模块不是用CUDA后端构建的;切换到 CPU"C++中的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 05:07