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<