c++ - Qt 与 Dlib 和 CUDA

标签 c++ qt dlib

我正在尝试使用 Dlib 运行 Qt。发生的情况是,Dlib 中需要 CUDA 的每个算法都会无错误地崩溃,如果我在 visual studio 上运行相同的代码,它会完美运行。 Qt 和 Dlib 使用 Visual Studio 2015 x64 构建,CUDA 版本为 8.0。

代码是来自 Dlib 的一些示例,可以使用 CUDA 以获得更好的性能:

    #include <iostream>
    #include <dlib/dnn.h>
    #include <dlib/data_io.h>
    #include <dlib/image_processing.h>
    #include <dlib/gui_widgets.h>


    using namespace std;
    using namespace dlib;

    // ----------------------------------------------------------------------------------------

    template <long num_filters, typename SUBNET> using con5d = con<num_filters,5,5,2,2,SUBNET>;
    template <long num_filters, typename SUBNET> using con5  = con<num_filters,5,5,1,1,SUBNET>;

    template <typename SUBNET> using downsampler  = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16,SUBNET>>>>>>>>>;
    template <typename SUBNET> using rcon5  = relu<affine<con5<45,SUBNET>>>;

    using net_type = loss_mmod<con<1,9,9,1,1,rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;

    // ----------------------------------------------------------------------------------------


int main(int argc, char** argv) try
{
    if (argc == 1)
    {
        cout << "Call this program like this:" << endl;
        cout << "./dnn_mmod_face_detection_ex mmod_human_face_detector.dat faces/*.jpg" << endl;
        cout << "\nYou can get the mmod_human_face_detector.dat file from:\n";
        cout << "http://dlib.net/files/mmod_human_face_detector.dat.bz2" << endl;
        return 0;
    }


    net_type net;
    deserialize(argv[1]) >> net;  

    image_window win;
    for (int i = 2; i < argc; ++i)
    {
        matrix<rgb_pixel> img;
        load_image(img, argv[i]);

        // Upsampling the image will allow us to detect smaller faces but will cause the
        // program to use more RAM and run longer.
        while(img.size() < 1800*1800)
            pyramid_up(img);

        // Note that you can process a bunch of images in a std::vector at once and it runs
        // much faster, since this will form mini-batches of images and therefore get
        // better parallelism out of your GPU hardware.  However, all the images must be
        // the same size.  To avoid this requirement on images being the same size we
        // process them individually in this example.
        auto dets = net(img);
        win.clear_overlay();
        win.set_image(img);
        for (auto&& d : dets)
            win.add_overlay(d);

        cout << "Hit enter to process the next image." << endl;
        cin.get();
    }
}
catch(std::exception& e)
{
    cout << e.what() << endl;
}

程序在“auto dets = net(img);”行崩溃

我的 .pro 文件:

INCLUDEPATH += C:\dlib\dlib-19.4
LIBS += -LC:\dlib\dlib-19.4\mybuild\dlib_build\Release -ldlib

INCLUDEPATH += "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include"
LIBS +="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\curand.lib"
LIBS +="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cublas.lib"
LIBS +="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cublas_device.lib"
LIBS +="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudnn.lib"
LIBS +="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart_static.lib"

感谢关注。

最佳答案

试试这个:

LIBS += L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64"

LIBS += -lcurand -lcublas -lcublas_device -lcudnn -lcudart_static

关于c++ - Qt 与 Dlib 和 CUDA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45463106/

相关文章:

c++ - LNK2019 未解析的外部符号 SHGetFolderPathW

c++ - string_view 和 basic_string<char> 有什么联系,为什么 string_view 示例代码不起作用?

c++ - 在 C++11 中禁用复制类的最简洁方法

c++ - Qt Creator - Project ERROR : Xcode not set up properly. 您可能需要通过运行/usr/bin/xcodebuild 来确认许可协议(protocol)

qt - QML StackView 自定义过渡

python - 如何使用 python 和 opencv 从彼此中减去两个图像?

c++ - 避免在 C++20 中进行互斥函数调用的预处理器

c++ - Libav多线程解码

opencv - 如何在 Dlib C++ 中获取头部姿势估计的 3D 坐标轴

c++ - lsqnonlin(Matlab) 或 C++ 中的 SciPy 最小二乘法等价物