diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 50659e6..2005d9b 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -3,7 +3,7 @@ #include #include -#include /* srand, rand */ +#include #include #include #include "utils.h" @@ -14,7 +14,7 @@ #include "tkdnn.h" -// #define OPENCV_CUDA //if OPENCV has been compiled with CUDA and contrib. +#define OPENCV_CUDA //if OPENCV has been compiled with CUDA and contrib. namespace tk { namespace dnn { diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index 547b0e0..f9a5828 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -17,6 +17,8 @@ private: tk::dnn::Yolo* yolo[3]; tk::dnn::Yolo* getYoloLayer(int n=0); + + cv::Mat bgr_h; public: Yolo3Detection() {}; diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index 987924d..98449f8 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -62,9 +62,10 @@ void Yolo3Detection::preprocess(cv::Mat &frame) //write channels for(int i=0; iinput_dim.c; i++) { - int idx = i*imagePreproc.rows*imagePreproc.cols; + int size = imagePreproc.rows * imagePreproc.cols; int ch = netRT->input_dim.c-1 -i; - checkCuda( cudaMemcpy((void*)&input_d[idx], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType), cudaMemcpyDeviceToDevice)); + bgr[ch].download(bgr_h); //TODO: don't copy back on CPU + checkCuda( cudaMemcpy(input_d + i*size, (float*)bgr_h.data, size*sizeof(dnnType), cudaMemcpyHostToDevice)); } #else cv::resize(frame, frame, cv::Size(netRT->input_dim.w, netRT->input_dim.h)); @@ -77,7 +78,7 @@ void Yolo3Detection::preprocess(cv::Mat &frame) for(int i=0; iinput_dim.c; i++) { int idx = i*imagePreproc.rows*imagePreproc.cols; int ch = netRT->input_dim.c-1 -i; - memcpy((void*)&input[idx], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType)); + memcpy((void*)&input[idx], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType)); } checkCuda(cudaMemcpyAsync(input_d, input, netRT->input_dim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream)); #endif @@ -96,6 +97,9 @@ void Yolo3Detection::update(cv::Mat &frame) //do inference tk::dnn::dataDim_t dim = netRT->input_dim; + + // printDeviceVector(netRT->input_dim.tot()*sizeof(dnnType),input_d); + printCenteredTitle(" TENSORRT inference ", '=', 30); {