YOLO依賴opencv,所以需要在VS2017中配置opencv。YOLO使用的是COCO數據集,感興趣的可以移步官網。
【配置opencv】屬性表方式
新建opencv3410_release_x64.txt,粘貼如下內容后,改為opencv3410_release_x64.props。注意黃色部分自己的opencv路徑
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <IncludePath>D:\opencv3410\build\include;D:\opencv3410\build\include\opencv;D:\opencv3410\build\include\opencv2;$(IncludePath)</IncludePath> <LibraryPath>D:\opencv3410\build\x64\vc15\lib;$(LibraryPath)</LibraryPath> </PropertyGroup> <ItemDefinitionGroup> <Link> <AdditionalDependencies>opencv_world3410.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemGroup /> </Project>
【VS2017運行YOLOv4】
下載https://github.com/AlexeyAB/darknet后,解壓。
修改darknet.vcxproj中cuda版本為自己安裝的cuda版本,大概在55行、306行共計兩處。
VS2017打開darknet.sln,如下圖,添加opencv3410_release_x64.props,運行。在x64目錄里會生成darknet.exe。
若報關於cuda的錯誤,把cuda安裝目錄
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\visual_studio_integration\MSBuildExtensions
里的4個文件拷貝到VS的安裝目錄
D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\BuildCustomizations
【cmd執行darknet.exe】
下載已經訓練好的權重文件yolov4.weights,地址:yolov4.weights(可能會比較慢)
在darknet.exe同目錄下新建weights文件夾,用於存放權重文件yolov4.weights。
打開cmd,進入到darknet.exe所在的文件夾(其中dog.jpg可以換成自己的圖片),輸入:
darknet.exe detector test cfg\coco.data cfg\yolov4.cfg .\weights\yolov4.weights .\data\dog.jpg
【參考】
https://blog.csdn.net/qq_18483627/article/details/105861365
https://github.com/AlexeyAB/darknet#datasets 上一個鏈接是對此鏈接的中文解讀,需下載的東西,此鏈接都有。