#include #include #include /* srand, rand */ #ifdef __linux__ #include #endif #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"; int n_batches = 1; float confidence_thresh = 0.3; bool show = false; bool write_dets = false; bool write_res_on_file = true; bool write_coco_json = false; 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; //read args 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(argc > 5) n_batches = atoi(argv[5]); if(argc > 6) confidence_thresh = atof(argv[6]); std::cout<<"conf t: "<init(net, n_classes, 1, conf_thresh); //read images std::ifstream all_labels(labels_path); std::string l_filename; std::vector images; std::vector detected_bbox; std::cout<<"Reading groundtruth and generating detections"< batch_frames; std::vector batch_dnn_input; std::vector cur_frames; for(;cur_batches> 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(batch_frames[cur_batches], cv::Point((b.x-b.w/2)*f.width, (b.y-b.h/2)*f.height), cv::Point((b.x+b.w/2)*f.width,(b.y+b.h/2)*f.height), cv::Scalar(0, 255, 0), 2); } } cur_frames.push_back(f); } if (!file_ok) break; //inference detNN->update(batch_dnn_input,cur_batches,write_res_on_file, ×, write_coco_json); detNN->draw(batch_frames); for(int j=0;jbatchDetected[j], classes, cur_frames[j].width, cur_frames[j].height); std::ofstream myfile; if(write_dets) myfile.open ("det/"+cur_frames[j].lFilename.substr(cur_frames[j].lFilename.find("labels/") + 7)); // save detections labels for(auto d:detNN->batchDetected[j]){ //convert detected bb in the same format as label /// / / / tk::dnn::BoundingBox b; b.x = (d.x + d.w/2) / cur_frames[j].width; b.y = (d.y + d.h/2) / cur_frames[j].height; b.w = d.w / cur_frames[j].width; b.h = d.h / cur_frames[j].height; b.prob = d.prob; b.cl = d.cl; cur_frames[j].det.push_back(b); if(write_dets) myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n"; if(show)// draw rectangle for detection cv::rectangle(batch_frames[j], 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(); images.push_back(cur_frames[j]); if(show){ cv::imshow("detection", batch_frames[j]); cv::waitKey(0); } } std::cout <