使用QT编译与调试YOLO3

本机环境:

Ubuntu16.04,

CUDA8.0,

CUDNN8.0-v5.1,

opencv2.4.13

QT5.6.1

为了更加方便的调试YOLOv3,将YOLO放在QT中编译。

 

1:QT新建一个控制台程序:

2:更改.pro文件:

3:取出不需要编译的冗余文件(不去掉会报错)

在修改.pro文件时,需要注意,YOLOv3并不是所有的文件都参与便于的,可以看到makefile文件中,compare.c,voxel.c,swag.c,rnn_Vid.c,dice.c,writing.c文件并没有参与编译。需要主掉,否则会报错network类型变量相关的函数参数不符的错误。

4:修改GPU,CUDA,CUDNN宏:

位置如下:

    1:darknet.h最开始 

    #ifndef GPU
    #define GPU
    #endif

    #ifndef CUDNN
    #define CUDNN
    #endif

    #ifndef OPENCV
    #define OPENCV
    #endif

    2:im2col.h最开始

    #ifndef GPU
    #define GPU
    #endif

 

    3:col2im.h最开始:

    #ifndef GPU
    #define GPU
    #endif

    4:cuda.h中#ifdef GPU前一行添加:

   #define GPU

 

    cuda.c中第一行:

    #include "cuda.h"

 

5:成功编译。

后面会加上我成功的.pro,需要的朋友可以对照修改自己的pro文件。

6:.pro文件内容如下:

QT += core
QT -= gui

CONFIG += c++11

TARGET = yolov3
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += \
    src/yolo_layer.c \
    src/utils.c \
    src/upsample_layer.c \
    src/tree.c \
    src/softmax_layer.c \
    src/shortcut_layer.c \
    src/route_layer.c \
    src/rnn_layer.c \
    src/reorg_layer.c \
    src/region_layer.c \
    src/parser.c \
    src/option_list.c \
    src/normalization_layer.c \
    src/network.c \
    src/maxpool_layer.c \
    src/matrix.c \
    src/lstm_layer.c \
    src/logistic_layer.c \
    src/local_layer.c \
    src/list.c \
    src/layer.c \
    src/l2norm_layer.c \
    src/image.c \
    src/im2col.c \
    src/gru_layer.c \
    src/gemm.c \
    src/dropout_layer.c \
    src/detection_layer.c \
    src/demo.c \
    src/deconvolutional_layer.c \
    src/data.c \
    src/cuda.c \
    src/crop_layer.c \
    src/crnn_layer.c \
    src/cost_layer.c \
    src/convolutional_layer.c \
    src/connected_layer.c \
    #src/compare.c \
    src/col2im.c \
    src/box.c \
    src/blas.c \
    src/batchnorm_layer.c \
    src/avgpool_layer.c \
    src/activations.c \
    src/activation_layer.c \
    examples/yolo.c \
    #examples/voxel.c \
    examples/tag.c \
    #examples/swag.c \
    examples/super.c \
    examples/segmenter.c \
    #examples/rnn_vid.c \
    examples/rnn.c \
    examples/regressor.c \
    examples/nightmare.c \
    examples/lsd.c \
    examples/go.c \
    #examples/dice.c \
    examples/detector.c \
    examples/darknet.c \
    examples/coco.c \
    examples/classifier.c \
    examples/cifar.c \
    examples/captcha.c \
    examples/attention.c \
    examples/art.c \
    #examples/writing.c

HEADERS += \
    src/yolo_layer.h \
    src/utils.h \
    src/upsample_layer.h \
    src/tree.h \
    src/stb_image_write.h \
    src/stb_image.h \
    src/softmax_layer.h \
    src/shortcut_layer.h \
    src/route_layer.h \
    src/rnn_layer.h \
    src/reorg_layer.h \
    src/region_layer.h \
    src/parser.h \
    src/option_list.h \
    src/normalization_layer.h \
    src/network.h \
    src/maxpool_layer.h \
    src/matrix.h \
    src/lstm_layer.h \
    src/logistic_layer.h \
    src/local_layer.h \
    src/list.h \
    src/layer.h \
    src/l2norm_layer.h \
    src/image.h \
    src/im2col.h \
    src/gru_layer.h \
    src/gemm.h \
    src/dropout_layer.h \
    src/detection_layer.h \
    src/demo.h \
    src/deconvolutional_layer.h \
    src/data.h \
    src/cuda.h \
    src/crop_layer.h \
    src/crnn_layer.h \
    src/cost_layer.h \
    src/convolutional_layer.h \
    src/connected_layer.h \
    src/col2im.h \
    src/classifier.h \
    src/box.h \
    src/blas.h \
    src/batchnorm_layer.h \
    src/avgpool_layer.h \
    src/activations.h \
    src/activation_layer.h \
    include/darknet.h

INCLUDEPATH += \
#/usr/local/opencv320/include \
#/usr/local/opencv320/include/opencv \
#/usr/local/opencv320/include/opencv2 \
/usr/local/opencv2.4.13/include \
/usr/local/opencv2.4.13/include/opencv \
/usr/local/opencv2.4.13/include/opencv2 \
/home/montafan/Qt5.6.2/project/yolov3/include \
/home/montafan/Qt5.6.2/project/yolov3/src \



# CUDA settings <-- may change depending on your system

CUDA_SOURCES += 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_SDK = "/usr/local/cuda-8.0"   # Path to cuda SDK install
CUDA_DIR = "/usr/local/cuda-8.0"            # Path to cuda toolkit install


# DO NOT EDIT BEYOND THIS UNLESS YOU KNOW WHAT YOU ARE DOING....

SYSTEM_NAME = ubuntu         # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 64            # '32' or '64', depending on your system
CUDA_ARCH = sm_50           # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math


# include paths
INCLUDEPATH += $$CUDA_DIR/include \

# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib64/

CUDA_OBJECTS_DIR = ./


# Add the necessary libraries
#CUDA_LIBS = -lcuda -lcudart
CUDA_LIBS += -lcudart -lcufft -lcuda -lcublas -lcurand -lcudnn

# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
#LIBS += $$join(CUDA_LIBS,'.so ', '', '.so')
LIBS += $$CUDA_LIBS \
/usr/local/opencv2.4.13/lib/libopencv_*.so \
#/usr/local/opencv320/lib/libopencv_*.so \


# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
    # Debug mode
    cuda_d.input = CUDA_SOURCES
    cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
    cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda_d.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
    # Release mode
    cuda.input = CUDA_SOURCES
    cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
    cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda
}

DISTFILES += \
    examples/detector-scipy-opencv.py \
    examples/detector.py            

 

你可能感兴趣的:(YOLO)