将YOLO的Darknet框架改到Qt下使用(附个yolov2整个加速的cpu工程github地址:https://github.com/syoung9029/darknet_cpu)
使用Qt创建新的工程,
删除创建好的main.cpp,
加入darknet下的源文件
更改.pro文件,添加多线程/cuda库/opencv的路径 SOURCES之前改为如下所示:
TEMPLATE = app QT += qml quick widgets
TARGET = yoloV2
CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += thread
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2
LIBS += -L/usr/local/lib -lopencv_core -lopencv_features2d -lopencv_flann \
-lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect \
-lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videoio \
-lopencv_video -lopencv_videostab
然后在HEADERS后面添加:
CUDA_SOURCES += \
../src/network_kernels.cu \
../src/maxpool_layer_kernels.cu \
../src/im2col_kernels.cu \
../src/dropout_layer_kernels.cu \
../src/deconvolutional_kernels.cu \
../src/crop_layer_kernels.cu \
../src/convolutional_kernels.cu \
../src/col2im_kernels.cu \
../src/blas_kernels.cu \
../src/avgpool_layer_kernels.cu \
../src/activation_kernels.cu
CUDA_DIR = /usr/local/cuda-7.5
INCLUDEPATH += $$CUDA_DIR/include
OBJECTS_DIR = ./
LIBS += -L/usr/local/cuda-7.5/lib64 -lcudart -lcufft -lcuda -lcublas -lcurand
CUDA_ARCH = sm_50
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
cuda.input = CUDA_SOURCES
cuda.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
# compile CUDA kernels using nvcc
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -g -G -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} \
2>&1 | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
QMAKE_EXTRA_COMPILERS += cuda
上面已经配置好所需要的库文件路径,下面更改Headers里面的cuda.h文件,加入GPU加速,添加#define GPU
然后更改cuda
.c文件,加入cuda
.h的头文件,
在blas.h中将#ifdef GPU后面的#include "cuda.h"提到其前面,在col2im.h和im2col.h中#ifdef GPU前面添加#define GPU。(如果还有错误,就暴力查看所有头文件里面需要定义GPU或者OPENCV的,即有ifdef GPU或者OPENCV的,在前面添加#define GPU或者#define OPENCV)
如果需要使用opencv,还要到使用了opencv的文件对应更改,此处只修改了测试阶段需要的文件里面的opencv:修改darknet.c,demo.c, detector.c, image.c
定义#define OPENCV
project里面更改执行命令
|