From f32d8a859bb9739864f055f713038b05e2fc89a6 Mon Sep 17 00:00:00 2001 From: xavier Date: Fri, 7 Feb 2020 09:09:40 +0100 Subject: [PATCH] Add mAP 0.5:0.95, other small fix Signed-off-by: xavier --- demo/demo/map.cpp | 73 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index 15825f7..8e4ec3f 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -21,6 +21,14 @@ struct BoundigBox : public tk::dnn::box friend std::ostream& operator<<(std::ostream& os, const BoundigBox& bb); int unique_truth_index = -1; int truth_flag = 0; + float max_IoU = 0; + + void clear() + { + unique_truth_index = -1; + truth_flag = 0; + max_IoU = 0; + } }; bool boxComparison (const BoundigBox& a,const BoundigBox& b) @@ -33,7 +41,8 @@ std::ostream& operator<<(std::ostream& os, const BoundigBox& bb) { os <<"w: "<< bb.w << ", h: "<< bb.h << ", x: "<< bb.x << ", y: "<< bb.y << ", cat: "<< bb.cl << ", conf: "<< bb.prob<< ", truth: "<< - bb.truth_flag<< ", assignedGT: "<< bb.unique_truth_index<<"\n"; + bb.truth_flag<< ", assignedGT: "<< bb.unique_truth_index<< + ", maxIoU: "<< bb.max_IoU<<"\n"; return os; } @@ -111,7 +120,7 @@ struct PR } }; -double computeMap(std::vector &images,const int classes,const int IoU_thresh, const int map_points, const bool verbose=false) +double computeMap(std::vector &images,const int classes,const float IoU_thresh, const int map_points, const bool verbose=false) { std::cout<<"Computing mAP"< &images,const int classes,const int IoU_thr // std::cout<<"det i:"< -1 && maxIoU > IoU_thresh) { + // std::cout<<"(INSIDE) IoU thresh:"< IoU_thresh:"<<(maxIoU > IoU_thresh)< &images,const int classes,const int IoU_thr mean_average_precision = mean_average_precision / classes; - std::cout<<"Classes: "< 1) net = argv[1]; - char *labels_path = "/media/887E650E7E64F67A/val2014/all_labels.txt"; + char type = 'y'; if(argc > 2) - labels_path = argv[2]; + type = argv[2][0]; + char *labels_path = "/media/887E650E7E64F67A/val2017/all_labels2017.txt"; + if(argc > 3) + labels_path = argv[3]; + + + networkType_t ntype; + switch(type) + { + case 'y': + ntype = YOLO; + break; + case 'c': + ntype = CENTERNET; + break; + default: + FatalError("type not allowed (3rd parameter)"); + } - networkType_t ntype = YOLO; bool show = false; tk::dnn::Yolo3Detection yolo; @@ -342,8 +369,10 @@ int main(int argc, char *argv[]) if(show) cv::namedWindow("detection", cv::WINDOW_NORMAL); + std::vector detected_bbox; + int i=0; - while (std::getline(all_labels, l_filename) && i < 1000) + while (std::getline(all_labels, l_filename)) // && i < 1000) { Frame f; f.l_filename = l_filename; @@ -363,7 +392,9 @@ int main(int argc, char *argv[]) dnn_input = frame.clone(); //inference - std::vector detected_bbox; + + detected_bbox.clear(); + switch(ntype) { case YOLO: @@ -378,6 +409,9 @@ int main(int argc, char *argv[]) FatalError("Network type not allowed "); } + // std::ofstream myfile; + // myfile.open ("det/"+f.l_filename.substr(l_filename.find("000"))); + // save detections labels for(auto d:detected_bbox) { @@ -392,10 +426,14 @@ int main(int argc, char *argv[]) b.cl = d.cl; f.det.push_back(b); + // myfile << d.cl << " "<< d.prob << " "<< d.x << " "<< d.y << " "<< d.w << " "<< d.h <<"\n"; + if(show)// draw rectangle for detection - cv::rectangle(frame, cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(255, 0, 0), 2); + cv::rectangle(frame, cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2); } + // myfile.close(); + // read and save groundtruth labels std::ifstream labels(l_filename); for(std::string line; std::getline(labels, line); ) @@ -423,11 +461,24 @@ int main(int argc, char *argv[]) std::cout<<"Done."<