#include #include #include /* srand, rand */ #include #include #include "utils.h" #include #include #include #include #include "Yolo3Detection.h" #include "CenternetDetection.h" #include "MobilenetDetection.h" #include "evaluation.h" #include void convertFilename(std::string &filename,const std::string l_folder, const std::string i_folder, const std::string l_ext,const std::string i_ext) { filename.replace(filename.find(l_folder),l_folder.length(),i_folder); filename.replace(filename.find(l_ext),l_ext.length(),i_ext); } int main(int argc, char *argv[]) { char ntype = 'y'; const char *config_filename = "../demo/config.yaml"; const char * net = "yolo3.rt"; const 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; bool verbose; int classes, map_points, map_levels; float map_step, IoU_thresh, conf_thresh; double vm_total = 0, rss_total = 0; double vm, rss; if(argc > 1) net = argv[1]; if(argc > 2) ntype = argv[2][0]; if(argc > 3) labels_path = argv[3]; if(argc > 4) config_filename = argv[4]; if(!fileExist(config_filename)) FatalError("Wrong config file path."); if(!fileExist(net)) FatalError("Wrong net file path."); if(!fileExist(labels_path)) FatalError("Wrong labels file path."); //read mAP parameters tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step, IoU_thresh, conf_thresh, verbose); std::ofstream times, memory; std::string net_name; removePathAndExtension(net, net_name); std::cout<<"Network: "<init(net, n_classes); std::ifstream all_labels(labels_path); std::string l_filename; std::vector images; std::vector detected_bbox; std::cout<<"Reading groundtruth and generating detections"<update(dnn_input, write_res_on_file, ×); frame = detNN->draw(frame); detected_bbox = detNN->detected; std::ofstream myfile; if(write_dets) myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000"))); // save detections labels for(auto d:detected_bbox){ //convert detected bb in the same format as label /// / / / tk::dnn::BoundingBox b; b.x = (d.x + d.w/2) / width; b.y = (d.y + d.h/2) / height; b.w = d.w / width; b.h = d.h / height; b.prob = d.prob; b.cl = d.cl; f.det.push_back(b); if(write_dets) 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(0, 0, 255), 2); } if(write_dets) myfile.close(); // read and save groundtruth labels std::ifstream labels(l_filename); for(std::string line; std::getline(labels, line); ){ std::istringstream in(line); tk::dnn::BoundingBox b; in >> b.cl >> b.x >> b.y >> b.w >> b.h; b.prob = 1; b.truthFlag = 1; f.gt.push_back(b); if(show)// draw rectangle for groundtruth cv::rectangle(frame, cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2); } images.push_back(f); if(show){ cv::imshow("detection", frame); cv::waitKey(0); } getMemUsage(vm, rss); vm_total += vm; rss_total += rss; } std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl; //compute mAP double AP = tk::dnn::computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose, write_res_on_file, net_name); std::cout<<"mAP "<