Add json detection creation for codalab check
Signed-off-by: Micaela Verucchi <micaelaverucchi@gmail.com>
This commit is contained in:
+39
-18
@@ -34,6 +34,7 @@ int main(int argc, char *argv[])
|
||||
bool show = false;
|
||||
bool write_dets = false;
|
||||
bool write_res_on_file = true;
|
||||
bool write_coco_json = true;
|
||||
int n_images = 5000;
|
||||
|
||||
bool verbose;
|
||||
@@ -43,6 +44,7 @@ int main(int argc, char *argv[])
|
||||
double vm_total = 0, rss_total = 0;
|
||||
double vm, rss;
|
||||
|
||||
//read args
|
||||
if(argc > 1)
|
||||
net = argv[1];
|
||||
if(argc > 2)
|
||||
@@ -52,6 +54,7 @@ int main(int argc, char *argv[])
|
||||
if(argc > 4)
|
||||
config_filename = argv[4];
|
||||
|
||||
//check if files needed exist
|
||||
if(!fileExist(config_filename))
|
||||
FatalError("Wrong config file path.");
|
||||
if(!fileExist(net))
|
||||
@@ -63,26 +66,31 @@ int main(int argc, char *argv[])
|
||||
tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step,
|
||||
IoU_thresh, conf_thresh, verbose);
|
||||
|
||||
std::ofstream times, memory;
|
||||
//extract network name from rt path
|
||||
std::string net_name;
|
||||
removePathAndExtension(net, net_name);
|
||||
std::cout<<"Network: "<<net_name<<std::endl;
|
||||
|
||||
//open files (if needed)
|
||||
std::ofstream times, memory, coco_json;
|
||||
|
||||
if(write_coco_json){
|
||||
coco_json.open(net_name+"_COCO_res.json");
|
||||
coco_json << "[\n";
|
||||
}
|
||||
|
||||
if(write_res_on_file){
|
||||
times.open("times_"+net_name+".csv");
|
||||
memory.open("memory.csv", std::ios_base::app);
|
||||
memory<<net<<";";
|
||||
}
|
||||
|
||||
// instantiate detector
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
tk::dnn::CenternetDetection cnet;
|
||||
tk::dnn::MobilenetDetection mbnet;
|
||||
|
||||
tk::dnn::DetectionNN *detNN;
|
||||
|
||||
int n_classes = classes;
|
||||
|
||||
|
||||
switch(ntype){
|
||||
case 'y':
|
||||
detNN = &yolo;
|
||||
@@ -97,9 +105,9 @@ int main(int argc, char *argv[])
|
||||
default:
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
|
||||
detNN->init(net, n_classes);
|
||||
|
||||
//read images
|
||||
std::ifstream all_labels(labels_path);
|
||||
std::string l_filename;
|
||||
std::vector<tk::dnn::Frame> images;
|
||||
@@ -135,10 +143,13 @@ int main(int argc, char *argv[])
|
||||
//inference
|
||||
|
||||
detected_bbox.clear();
|
||||
detNN->update(dnn_input, write_res_on_file, ×);
|
||||
detNN->update(dnn_input, write_res_on_file, ×, write_coco_json);
|
||||
frame = detNN->draw(frame);
|
||||
detected_bbox = detNN->detected;
|
||||
|
||||
|
||||
if(write_coco_json)
|
||||
printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height);
|
||||
|
||||
std::ofstream myfile;
|
||||
if(write_dets)
|
||||
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000")));
|
||||
@@ -167,17 +178,20 @@ int main(int argc, char *argv[])
|
||||
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(fileExist(f.lFilename.c_str()))
|
||||
{
|
||||
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);
|
||||
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);
|
||||
@@ -193,6 +207,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(write_coco_json){
|
||||
coco_json.seekp (coco_json.tellp()-2);
|
||||
coco_json << "\n]\n";
|
||||
coco_json.close();
|
||||
}
|
||||
|
||||
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
|
||||
|
||||
//compute mAP
|
||||
|
||||
Reference in New Issue
Block a user