windows: darknet 编译与使用 (有cuda ,没有OPENCV )
darknet调用:
.\darknet.exe detector test .\data\xxx.data .\cfg\yolov4-tiny_test.cfg yolov4-tiny_best.weights xxx.jpg
yolo测试用例调用
.\yolo_console_dll.exe xxx.names xxx_test.cfg xxx.weights xx.jpg
一. 编译 darknet.sln windows + GPU (without opencv):
修改darknet-master\build\darknet下面的darknet.vcxproj文件:
1.先找到cuda 11.1(有两处,可能会有差异,不是11.1,找到它改成自己电脑上的cuda版本即可),将其改为自己的cuda版本(比如我的cuda 10.1)。
2.然后确定自己要编译哪一版的,比如我要编译64位release版,那就找到x64|release这个节点,做修改:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
修改预编译参数 <PreprocessorDefinitions>:
①去掉OPENCV(因为我没装opencv),并把OPENCV加到<UndefinePreprocessorDefinitions>节点里面
②去掉CUDNN_HALF(开启CUDNN_DATA_HALF数据类型优化,好像算力>=70以上的显卡会支持优化。但是我的GTX1650,开启优化之后,虽然编译通过了,但是darknet什么也没检测出来,所以这里禁掉优化);
修改架构计算能力<CudaCompile> 下面的 <CodeGeneration>值。(根据自己的显卡,查官网确定),比如:
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75</CodeGeneration>
(我的GTX1650显卡官方显示最高算力是75,如果加了86及以上架构,可能会报报错nvcc fatal : Unsupported gpu architecture ‘compute_xx’的错误,)
用vs打开darknet.sln,选择x64/release,点击生成,即可。
上述步骤2也可以在打开darknet.sln之后在项目属性里面修改:
属性》配置属性》C/C++》预处理器: 去掉预处理定义里面的OPENCV 和CUDNN_HAL,并在取消预处理器定义里面加上OPENCV。
属性》配置属性》CUDA C/C++》Device:修改Code Generation里面的内容
二.编译yolo_cpp_dll.sln:
和编译 darknet.sln步骤基本一致
三. 编译yolo_console_dll.sln:
修改yolo_console_dll.vcxproj里面,Release|x64的ClCompile节点里面加一行,UndefinePreprocessorDefinitions OPENCV的配置,如下:
<ItemDefinitionGroup <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>...
<UndefinePreprocessorDefinitions>OPENCV</UndefinePreprocessorDefinitions>
</ClCompile>...
</ItemDefinitionGroup>
用vs打开yolo_console_dll.sln,选择x64/release,点击生成。