From fe206ea24c12d7b07ecd6cd6f7047c975a3277e2 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 27 Feb 2020 16:48:10 +0100 Subject: [PATCH 1/7] Fix dependencies problems Signed-off-by: Micaela Verucchi --- demo/demo/demo_mobilenet.cpp | 5 -- include/sorting.h | 5 ++ include/tkDNN/MobilenetDetection.h | 3 +- include/tkDNN/Yolo3Detection.h | 5 ++ include/tkDNN/pluginsRT/SoftmaxRT.h | 64 ------------------------- src/CenternetDetection.cpp | 13 +++-- tests/mobilenetv2ssd/mobilenetv2ssd.cpp | 4 -- 7 files changed, 21 insertions(+), 78 deletions(-) delete mode 100644 include/tkDNN/pluginsRT/SoftmaxRT.h diff --git a/demo/demo/demo_mobilenet.cpp b/demo/demo/demo_mobilenet.cpp index 1c4099a..f46df39 100644 --- a/demo/demo/demo_mobilenet.cpp +++ b/demo/demo/demo_mobilenet.cpp @@ -3,12 +3,7 @@ #include /* srand, rand */ #include #include -#include "utils.h" -#include -#include -#include -#include #include "MobilenetDetection.h" diff --git a/include/sorting.h b/include/sorting.h index 7e90f11..5153f3c 100644 --- a/include/sorting.h +++ b/include/sorting.h @@ -1,3 +1,6 @@ +#ifndef SORTING_H +#define SORTING_H + #include #include #include @@ -32,3 +35,5 @@ void topKxyAddOffset(int * ids_begin, const int K, const int size, int *intxs_be float *xs_begin, float *ys_begin, dnnType *src_begin, float *src_out, int *ids_out); void bboxes(int * ids_begin, const int K, const int size, float *xs_begin, float *ys_begin, dnnType *src_begin, float *bbx0, float *bbx1, float *bby0, float *bby1, float *src_out, int *ids_out); + +#endif /*SORTING_H*/ \ No newline at end of file diff --git a/include/tkDNN/MobilenetDetection.h b/include/tkDNN/MobilenetDetection.h index 6bfd1b2..840a2cc 100644 --- a/include/tkDNN/MobilenetDetection.h +++ b/include/tkDNN/MobilenetDetection.h @@ -2,13 +2,14 @@ #define MOBILENETDETECTION_H #include -#include "tkdnn.h" #include #include #include #include +#include "tkdnn.h" + #define N_COORDS 4 diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index ac12a4f..72ea3f8 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -1,3 +1,6 @@ +#ifndef YOLODETECTION_H +#define YOLODETECTION_H + #include #include #include /* srand, rand */ @@ -66,3 +69,5 @@ class Yolo3Detection { }; }} + +#endif /* YOLODETECTION_H*/ \ No newline at end of file diff --git a/include/tkDNN/pluginsRT/SoftmaxRT.h b/include/tkDNN/pluginsRT/SoftmaxRT.h deleted file mode 100644 index 226f6f6..0000000 --- a/include/tkDNN/pluginsRT/SoftmaxRT.h +++ /dev/null @@ -1,64 +0,0 @@ -#include - -class SoftmaxRT : public IPlugin { - -public: - SoftmaxRT(const tk::dnn::dataDim_t* dim) { - assert(dim != nullptr); - this->dim.n = dim->n; - this->dim.c = dim->c; - this->dim.h = dim->h; - this->dim.w = dim->w; - this->dim.l = dim->l; - } - - ~SoftmaxRT(){ - - } - - int getNbOutputs() const override { - return 1; - } - - Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override { - return DimsNCHW{this->dim.n,this->dim.c,this->dim.h,this->dim.w }; - } - - void configure(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, int maxBatchSize) override { - } - - int initialize() override { - return 0; - } - - virtual void terminate() override { - } - - virtual size_t getWorkspaceSize(int maxBatchSize) const override { - return 0; - } - - virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) override { - dnnType *srcData = (dnnType*)reinterpret_cast(inputs[0]); - dnnType *dstData = reinterpret_cast(outputs[0]); - - - return 0; - } - - - virtual size_t getSerializationSize() override { - return 5*sizeof(int); - } - - virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); - tk::dnn::writeBUF(buf, this->dim.n); - tk::dnn::writeBUF(buf, this->dim.c); - tk::dnn::writeBUF(buf, this->dim.h); - tk::dnn::writeBUF(buf, this->dim.w); - tk::dnn::writeBUF(buf, this->dim.l); - } - - dataDim_t dim; -}; diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index edfe1c2..512d0e0 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -1,3 +1,6 @@ +#ifndef CENTERNETDETECTION_H +#define CENTERNETDETECTION_H + #include "CenternetDetection.h" namespace tk { namespace dnn { @@ -226,7 +229,7 @@ void CenternetDetection::update(cv::Mat &imageORIG) { sz_old = sz; cv::cuda::GpuMat im_Orig; im_Orig = cv::cuda::GpuMat(imageORIG); - // cv::cuda::resize (im_Orig, imageF1_d, cv::Size(new_width, new_height)); + cv::cuda::resize (im_Orig, imageF1_d, cv::Size(new_width, new_height)); checkCuda( cudaDeviceSynchronize() ); sz = imageF1_d.size(); @@ -235,7 +238,7 @@ void CenternetDetection::update(cv::Mat &imageORIG) { std::cout << " TIME resize: " << std::chrono::duration_cast(end_t - step_t).count() << " us" << std::endl; step_t = end_t; - // cv::cuda::warpAffine(imageF1_d, imageF2_d, trans, cv::Size(inp_width, inp_height), cv::INTER_LINEAR ); + cv::cuda::warpAffine(imageF1_d, imageF2_d, trans, cv::Size(inp_width, inp_height), cv::INTER_LINEAR ); checkCuda( cudaDeviceSynchronize() ); end_t = std::chrono::steady_clock::now(); std::cout << " TIME warpAffine: " << std::chrono::duration_cast(end_t - step_t).count() << " us" << std::endl; @@ -248,7 +251,7 @@ void CenternetDetection::update(cv::Mat &imageORIG) { step_t = end_t; dim2 = dim; - // cv::cuda::split(imageF1_d,bgr);//split source + cv::cuda::split(imageF1_d,bgr);//split source end_t = std::chrono::steady_clock::now(); std::cout << " TIME split: " << std::chrono::duration_cast(end_t - step_t).count() << " us" << std::endl; step_t = end_t; @@ -413,4 +416,6 @@ void CenternetDetection::update(cv::Mat &imageORIG) { TIMER_STOP stats.push_back(t_ns); } -}} \ No newline at end of file +}} + +#endif /*CENTERNETDETECTION_H*/ \ No newline at end of file diff --git a/tests/mobilenetv2ssd/mobilenetv2ssd.cpp b/tests/mobilenetv2ssd/mobilenetv2ssd.cpp index f2ec51b..cec97e2 100644 --- a/tests/mobilenetv2ssd/mobilenetv2ssd.cpp +++ b/tests/mobilenetv2ssd/mobilenetv2ssd.cpp @@ -1,10 +1,6 @@ #include #include "tkdnn.h" -#include -#include -#include -#include const char *output_bin1 = "../tests/mobilenetv2ssd/debug/classification_headers-5.bin"; const char *output_bin2 = "../tests/mobilenetv2ssd/debug/regression_headers-5.bin"; From 296a6cbc87912a12c662090a39d3d6522b65b85a Mon Sep 17 00:00:00 2001 From: Davide Sapienza Date: Tue, 3 Mar 2020 17:08:25 +0100 Subject: [PATCH 2/7] Add draw method to Yolo3Detection class. Update yolo demo Signed-off-by: Davide Sapienza --- demo/demo/demo_yolo3.cpp | 23 +---------------------- include/tkDNN/Yolo3Detection.h | 2 +- src/Yolo3Detection.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/demo/demo/demo_yolo3.cpp b/demo/demo/demo_yolo3.cpp index 2b34386..0abcc2c 100644 --- a/demo/demo/demo_yolo3.cpp +++ b/demo/demo/demo_yolo3.cpp @@ -67,28 +67,7 @@ int main(int argc, char *argv[]) { // TODO: async infer yolo.update(dnn_input); - // draw dets - for(int i=0; iclassesNames[b.cl]; - float prob = b.prob; - - // std::cout<classesNames[b.cl]; + prob = b.prob; + + // std::cout< Date: Tue, 3 Mar 2020 17:30:35 +0100 Subject: [PATCH 3/7] Move multiple demo files into one Signed-off-by: Davide Sapienza --- CMakeLists.txt | 14 +--- demo/demo/demo.cpp | 138 +++++++++++++++++++++++++++++++++++ demo/demo/demo_centernet.cpp | 88 ---------------------- demo/demo/demo_mobilenet.cpp | 88 ---------------------- demo/demo/demo_yolo3.cpp | 88 ---------------------- 5 files changed, 140 insertions(+), 276 deletions(-) create mode 100644 demo/demo/demo.cpp delete mode 100644 demo/demo/demo_centernet.cpp delete mode 100644 demo/demo/demo_mobilenet.cpp delete mode 100644 demo/demo/demo_yolo3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 421e53a..0a765a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,18 +115,8 @@ target_link_libraries(test_dla34_cnet tkDNN) add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) -add_executable(yolo3_demo demo/demo/demo_yolo3.cpp) -target_link_libraries(yolo3_demo tkDNN) - -add_executable(centernet_demo demo/demo/demo_centernet.cpp) -target_link_libraries(centernet_demo tkDNN) - -add_executable(mobilenet_demo demo/demo/demo_mobilenet.cpp) -target_link_libraries(mobilenet_demo tkDNN) - -add_executable(map_demo demo/demo/map.cpp) -target_link_libraries(map_demo tkDNN) - +add_executable(demo demo/demo/demo.cpp) +target_link_libraries(demo tkDNN) #------------------------------------------------------------------------------- # Install diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp new file mode 100644 index 0000000..a5a9d1a --- /dev/null +++ b/demo/demo/demo.cpp @@ -0,0 +1,138 @@ +#include +#include +#include /* srand, rand */ +#include +#include + +#include "CenternetDetection.h" +#include "MobilenetDetection.h" +#include "Yolo3Detection.h" + +bool gRun; +bool SAVE_RESULT = false; + +void sig_handler(int signo) { + std::cout<<"request gateway stop\n"; + gRun = false; +} + +int main(int argc, char *argv[]) { + + std::cout<<"detection\n"; + signal(SIGINT, sig_handler); + + + char *net = "yolo3_berkeley.rt"; + if(argc > 1) + net = argv[1]; + char *input = "../demo/yolo_test.mp4"; + if(argc > 2) + input = argv[2]; + char ntype = 'y'; + if(argc > 3) + ntype = argv[3][0]; + + tk::dnn::Yolo3Detection yolo; + tk::dnn::CenternetDetection cnet; + tk::dnn::MobilenetDetection mbnet; + switch(ntype) + { + case 'y': + yolo.init(net); + break; + case 'c': + cnet.init(net); + break; + case 'm': + mbnet.init(net); + break; + default: + FatalError("Network type not allowed (3rd parameter)\n"); + } + + gRun = true; + + cv::VideoCapture cap(input); + if(!cap.isOpened()) + gRun = false; + else + std::cout<<"camera started\n"; + + cv::VideoWriter resultVideo; + if(SAVE_RESULT) { + int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); + int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); + resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h)); + } + + cv::Mat frame; + cv::Mat dnn_input; + cv::namedWindow("detection", cv::WINDOW_NORMAL); + + std::vector detected_bbox; + + while(gRun) { + cap >> frame; + if(!frame.data) { + break; + } + + // this will be resized to the net format + dnn_input = frame.clone(); + // TODO: async infer + switch(ntype) + { + case 'y': + yolo.update(dnn_input); + frame = yolo.draw(frame); + break; + case 'c': + cnet.update(dnn_input); + frame = cnet.draw(dnn_input); + break; + case 'm': + mbnet.update(dnn_input); + frame = mbnet.draw(); + break; + default: + FatalError("Network type not allowed!\n"); + } + + cv::imshow("detection", frame); + cv::waitKey(1); + if(SAVE_RESULT) + resultVideo << frame; + } + + std::cout<<"detection end\n"; + double mean = 0; + switch(ntype) + { + case 'y': + std::cout< -#include -#include /* srand, rand */ -#include -#include -#include "utils.h" - -#include -#include -#include -#include - -#include "CenternetDetection.h" - -bool gRun; -bool SAVE_RESULT = false; - -void sig_handler(int signo) { - std::cout<<"request gateway stop\n"; - gRun = false; -} - -int main(int argc, char *argv[]) { - - std::cout<<"detection\n"; - signal(SIGINT, sig_handler); - - - char *net = "resnet101_cnet.rt"; - if(argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if(argc > 2) - input = argv[2]; - - tk::dnn::CenternetDetection cnet; - cnet.init(net); - - gRun = true; - - cv::VideoCapture cap(input); - if(!cap.isOpened()) - gRun = false; - else - std::cout<<"camera started\n"; - - - cv::VideoWriter resultVideo; - if(SAVE_RESULT) { - int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); - int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); - resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h)); - } - - cv::Mat frame; - cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); - - while(gRun) { - cap >> frame; - if(!frame.data) { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - cnet.update(dnn_input); - // draw dets - frame = cnet.draw(dnn_input); - - cv::imshow("detection", frame); - cv::waitKey(1); - if(SAVE_RESULT) - resultVideo << frame; - } - - std::cout<<"detection end\n"; - - - std::cout< -#include -#include /* srand, rand */ -#include -#include - - -#include "MobilenetDetection.h" - -bool gRun; -bool SAVE_RESULT = false; - -void sig_handler(int signo) -{ - std::cout << "request gateway stop\n"; - gRun = false; -} - -int main(int argc, char *argv[]) -{ - - std::cout << "detection\n"; - signal(SIGINT, sig_handler); - - char *net = "mobilenetv2ssd.rt"; - if (argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if (argc > 2) - input = argv[2]; - - tk::dnn::MobilenetDetection mbnet; - mbnet.init(net); - - gRun = true; - - cv::VideoCapture cap(input); - if (!cap.isOpened()) - gRun = false; - else - std::cout << "camera started\n"; - - cv::VideoWriter resultVideo; - if (SAVE_RESULT) - { - int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); - int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); - resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M', 'P', '4', 'V'), 30, cv::Size(w, h)); - } - - cv::Mat frame; - cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); - - while (gRun) - { - cap >> frame; - if (!frame.data) - { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - mbnet.update(dnn_input); - // draw dets - frame = mbnet.draw(); - - cv::imshow("detection", frame); - cv::waitKey(1); - if (SAVE_RESULT) - resultVideo << frame; - } - - std::cout << "detection end\n"; - - std::cout << COL_GREENB << "\n\nTime stats:\n"; - std::cout << "Min: " << *std::min_element(mbnet.stats.begin(), mbnet.stats.end()) << " ms\n"; - std::cout << "Max: " << *std::max_element(mbnet.stats.begin(), mbnet.stats.end()) << " ms\n"; - double mean = 0; - for (int i = 0; i < mbnet.stats.size(); i++) - mean += mbnet.stats[i]; - mean /= mbnet.stats.size(); - std::cout << "Avg: " << mean << " ms\n" - << COL_END; - return 0; -} diff --git a/demo/demo/demo_yolo3.cpp b/demo/demo/demo_yolo3.cpp deleted file mode 100644 index 0abcc2c..0000000 --- a/demo/demo/demo_yolo3.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include -#include -#include /* srand, rand */ -#include -#include -#include "utils.h" - -#include -#include -#include -#include - -#include "Yolo3Detection.h" - -bool gRun; -bool SAVE_RESULT = false; - -void sig_handler(int signo) { - std::cout<<"request gateway stop\n"; - gRun = false; -} - -int main(int argc, char *argv[]) { - - std::cout<<"detection\n"; - signal(SIGINT, sig_handler); - - - char *net = "yolo3_berkeley.rt"; - if(argc > 1) - net = argv[1]; - char *input = "../demo/yolo_test.mp4"; - if(argc > 2) - input = argv[2]; - - tk::dnn::Yolo3Detection yolo; - yolo.init(net); - - gRun = true; - - cv::VideoCapture cap(input); - if(!cap.isOpened()) - gRun = false; - else - std::cout<<"camera started\n"; - - - cv::VideoWriter resultVideo; - if(SAVE_RESULT) { - int w = cap.get(cv::CAP_PROP_FRAME_WIDTH); - int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT); - resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h)); - } - - cv::Mat frame; - cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); - - while(gRun) { - cap >> frame; - if(!frame.data) { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); - // TODO: async infer - yolo.update(dnn_input); - - frame = yolo.draw(frame); - - cv::imshow("detection", frame); - cv::waitKey(1); - if(SAVE_RESULT) - resultVideo << frame; - } - - std::cout<<"detection end\n"; - - - std::cout< Date: Tue, 3 Mar 2020 17:34:01 +0100 Subject: [PATCH 4/7] Update README Signed-off-by: Davide Sapienza --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f8a3262..d04d52f 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,8 @@ rm yolo3_berkeley.rt # be sure to delete(or move) old tensorRT files ``` this will genereate a yolo3_berkeley.rt file that can be used for live detection: ``` -./yolo3_demo # launch detection on a demo video -./yolo3_demo yolo3_berkeley.rt /dev/video0 # launch detection on device 0 +./demo # launch detection on a demo video +./demo yolo3_berkeley.rt /dev/video0 y # launch detection on device 0 ``` ![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) @@ -110,9 +110,9 @@ rm dla34_cnet.rt # be sure to delete(or move) old tensorRT files this will genereate resnet101_cnet.rt and dla34_cnet.rt file that can be used for live detection: ``` -./centernet_demo # launch detection on a demo video -./centernet_demo resnet101_cnet.rt /dev/video0 # launch detection on device 0 -./centernet_demo dla34_cnet.rt /dev/video0 # launch detection on device 0 +./demo dla34_cnet.rt ../demo/yolo_test.mp4 c # launch detection on a demo video +./demo resnet101_cnet.rt /dev/video0 c # launch detection on device 0 +./demo dla34_cnet.rt /dev/video0 c # launch detection on device 0 ``` ## mAP demo From 7ea31d123a1f6f1d80b2b2dd1557dbefeb2ef201 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Sun, 8 Mar 2020 18:12:08 +0100 Subject: [PATCH 5/7] Update README Signed-off-by: Micaela Verucchi --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index d04d52f..7fc1848 100644 --- a/README.md +++ b/README.md @@ -139,3 +139,36 @@ Example: cd build ./map_demo dla34_cnet.rt c ../demo/COCO_val2017/all_labels.txt ../demo/config.yaml ``` + +## Supported networks + +| Test Name | Network | Dataset | N Classes | Input size | Weights | +| :---------------- | :-------------------------------------------- | :-----------------------------------------------------------: | :-------: | :-----------: | :------------------------------------------------------------------------ | +| yolo | YOLO v21 | [COCO 2014](http://cocodataset.org/) | 80 | 608x608 | weights | +| yolo_224 | YOLO v21 | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights | +| yolo_berkeley | YOLO v21 | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 416x736 | weights | +| yolo_relu | YOLO v2 (with ReLU, not Leaky)1 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | weights | +| yolo_tiny | YOLO v2 tiny1 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | weights | +| yolo_voc | YOLO v21 | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 416x416 | weights | +| yolo3 | YOLO v32 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download) | +| yolo3_berkeley | YOLO v32 | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 320x544 | weights | +| yolo3_coco4 | YOLO v32 | [COCO 2014](http://cocodataset.org/) | 4 | 416x416 | weights | +| yolo3_flir | YOLO v32 | [FREE FLIR](https://www.flir.com/oem/adas/adas-dataset-form/) | 3 | 320x544 | weights | +| yolo3_tiny | YOLO v3 tiny2 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download) | +| yolo3_tiny512 | YOLO v3 tiny2 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/pjooA5DMrrEbrmA/download) | +| dla34 | Deep Leayer Aggreagtion (DLA) 343 | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights | +| dla34_cnet | Centernet (DLA34 backend)4 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/8AjXdgCeRzCa5AF/download) | +| mobilenetv2ssd | Mobilnet v2 SSD Lite5 | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 300x300 | [weights](https://cloud.hipert.unimore.it/s/x4ZfxBKN23zAJQp/download) | +| resnet101 | Resnet 1016 | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights | +| resnet101_cnet | Centernet (Resnet101 backend)4 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/B6mj33k7beECXsY/download) | + + + +## References + +1. Redmon, Joseph, and Ali Farhadi. "YOLO9000: better, faster, stronger." Proceedings of the IEEE conference on computer vision and pattern recognition. 2017. +2. Redmon, Joseph, and Ali Farhadi. "Yolov3: An incremental improvement." arXiv preprint arXiv:1804.02767 (2018). +3. Yu, Fisher, et al. "Deep layer aggregation." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018. +4. Zhou, Xingyi, Dequan Wang, and Philipp Krähenbühl. "Objects as points." arXiv preprint arXiv:1904.07850 (2019). +5. Sandler, Mark, et al. "Mobilenetv2: Inverted residuals and linear bottlenecks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018. +6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016. \ No newline at end of file From 4b85a2238aec4319c474ab4c28672b971ded81d0 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 10 Mar 2020 14:35:25 +0100 Subject: [PATCH 6/7] Add writing results on file for map demo Signed-off-by: Micaela Verucchi --- CMakeLists.txt | 3 +++ demo/demo/map.cpp | 22 +++++++++++++-- include/evaluation.h | 6 ++--- include/tkDNN/Yolo3Detection.h | 4 +-- src/evaluation.cpp | 49 +++++++++++++++++++++++++++++----- 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a765a4..139bd9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,9 @@ target_link_libraries(test_dla34_cnet tkDNN) add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) +add_executable(map_demo demo/demo/map.cpp) +target_link_libraries(map_demo tkDNN) + add_executable(demo demo/demo/demo.cpp) target_link_libraries(demo tkDNN) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index 88f879f..ac2b96a 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -34,7 +34,15 @@ int main(int argc, char *argv[]) char * labels_path = "../demo/COCO_val2017/all_labels.txt"; bool show = false; bool write_dets = false; + bool write_res_on_file = true; int n_images = 5000; + + std::ofstream times; + if(write_res_on_file) + { + times.open ("times.csv", std::ios_base::app); + times< 1) net = argv[1]; @@ -91,6 +99,7 @@ int main(int argc, char *argv[]) //inference detected_bbox.clear(); + TIMER_START switch(ntype) { case 'y': @@ -104,6 +113,9 @@ int main(int argc, char *argv[]) default: FatalError("Network type not allowed!\n"); } + TIMER_STOP + if(write_res_on_file) + times< &images,const int classes,const float IoU_thresh, const float conf_thresh=0.3, const int map_points=101, const bool verbose=false); -double computeMapNIoULevels(std::vector &images,const int classes,const float i_IoU_thresh=0.5, const float conf_thresh=0.3, const int map_points=101, const float map_step=0.05, const int map_levels=10, const bool verbose=false); +double computeMapNIoULevels(std::vector &images,const int classes,const float i_IoU_thresh=0.5, const float conf_thresh=0.3, const int map_points=101, const float map_step=0.05, const int map_levels=10, const bool verbose=false, const bool write_on_file = false, std::string net = ""); -void computeTPFPFN(std::vector &images,const int classes,const float IoU_thresh=0.5, const float conf_thresh=0.3, bool verbose=false); +void computeTPFPFN(std::vector &images,const int classes,const float IoU_thresh=0.5, const float conf_thresh=0.3, bool verbose=false, const bool write_on_file=false, std::string net=""); -#endif /*EVALUATION_H*/ \ No newline at end of file +#endif /*EVALUATION_H*/ diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index 3700fa6..51994e1 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -37,7 +37,7 @@ class Yolo3Detection { int classes = 0; int num = 0; int n_masks = 0; - float thresh = 0.3; + float thresh = 0.05; cv::Scalar colors[256]; // this is filled with results @@ -70,4 +70,4 @@ class Yolo3Detection { }} -#endif /* YOLODETECTION_H*/ \ No newline at end of file +#endif /* YOLODETECTION_H*/ diff --git a/src/evaluation.cpp b/src/evaluation.cpp index c65ce50..80b2e61 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -1,4 +1,5 @@ #include "evaluation.h" +#include void BoundingBox::clear() @@ -283,27 +284,51 @@ double computeMap(std::vector &images,const int classes,const float IoU_t return mean_average_precision; } -double computeMapNIoULevels(std::vector &images,const int classes,const float i_IoU_thresh, const float conf_thresh, const int map_points, const float map_step, const int map_levels, const bool verbose) +double computeMapNIoULevels(std::vector &images,const int classes,const float i_IoU_thresh, const float conf_thresh, const int map_points, const float map_step, const int map_levels, const bool verbose, const bool write_on_file, std::string net) { - double AP = 0; + std::ofstream out_file; + if(write_on_file) + { + out_file.open("map.csv", std::ios_base::app); + out_file< &images,const int classes,const float IoU_thresh, const float conf_thresh, bool verbose) +void computeTPFPFN(std::vector &images,const int classes,const float IoU_thresh, const float conf_thresh, bool verbose, const bool write_on_file, std::string net) { + + std::ofstream out_file; + if(write_on_file) + { + out_file.open("pr.csv", std::ios_base::app); + out_file< truth_classes_count(classes,0); std::vector dets_classes_count(classes,0); - std::vector pr( classes); + std::vector pr(classes); for(auto &img:images) { @@ -355,6 +380,8 @@ void computeTPFPFN(std::vector &images,const int classes,const float IoU_ double avg_precision = 0, avg_recall = 0, f1_score = 0; + + int TP = 0, FP = 0, FN = 0; for(size_t i=0; i 0 ? (double)pr[i].tp / (double)(pr[i].tp +pr[i].fp) : 0; @@ -364,13 +391,23 @@ void computeTPFPFN(std::vector &images,const int classes,const float IoU_ // std::cout< 0 ? 2 * ( avg_precision * avg_recall ) / ( avg_precision + avg_recall ) : 0; + if(write_on_file) + { + out_file< Date: Tue, 10 Mar 2020 15:26:57 +0100 Subject: [PATCH 7/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fc1848..93af488 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ cd build | yolo3_coco4 | YOLO v32 | [COCO 2014](http://cocodataset.org/) | 4 | 416x416 | weights | | yolo3_flir | YOLO v32 | [FREE FLIR](https://www.flir.com/oem/adas/adas-dataset-form/) | 3 | 320x544 | weights | | yolo3_tiny | YOLO v3 tiny2 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download) | -| yolo3_tiny512 | YOLO v3 tiny2 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/pjooA5DMrrEbrmA/download) | +| yolo3_tiny512 | YOLO v3 tiny2 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/njnYACnQfWQFKrn/download) | | dla34 | Deep Leayer Aggreagtion (DLA) 343 | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights | | dla34_cnet | Centernet (DLA34 backend)4 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/8AjXdgCeRzCa5AF/download) | | mobilenetv2ssd | Mobilnet v2 SSD Lite5 | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 300x300 | [weights](https://cloud.hipert.unimore.it/s/x4ZfxBKN23zAJQp/download) | @@ -171,4 +171,4 @@ cd build 3. Yu, Fisher, et al. "Deep layer aggregation." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018. 4. Zhou, Xingyi, Dequan Wang, and Philipp Krähenbühl. "Objects as points." arXiv preprint arXiv:1904.07850 (2019). 5. Sandler, Mark, et al. "Mobilenetv2: Inverted residuals and linear bottlenecks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018. -6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016. \ No newline at end of file +6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.