Abd*_*tef 5 c++ opencv darknet yolo
我正在尝试在 Visual Studio 2019 上使用 CUDA 10.2 和 cuDNN v7.6.5 在 Windows 10 上使用 NVidia GeForce 930M 运行 YOLOv3。这是我使用的代码的一部分。
#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));
}
Run Code Online (Sandbox Code Playgroud)
虽然我添加了$(CUDNN)\include;$(cudnn)\include; 到附加包含目录在两个C / C ++和链接器,加入CUDNN_HALF; CUDNN; 到C/C++>Preprocessor Definitions,并添加cudnn.lib;到Linker>Input,我仍然收到此警告:
DNN 模块不是用 CUDA 后端构建的;切换到 CPU
它在 CPU 而不是 GPU 上运行,有人能帮我解决这个问题吗?
我通过使用CMake解决了这个问题,但我必须首先添加这个opencv_contrib然后使用Visual Studio重建它。确保在CMake中检查了这些WITH_CUDA、WITH_CUBLAS、WITH_CUDNN、OPENCV_DNN_CUDA、BUILD_opencv_world。