From 801b8b56416436e1df0515a806c64f67b212ae66 Mon Sep 17 00:00:00 2001 From: xavier Date: Tue, 11 Feb 2020 10:32:42 +0100 Subject: [PATCH] Read parameters for mAP from yaml, add yampl-cpp dependency Signed-off-by: xavier --- CMakeLists.txt | 3 +- demo/demo/map.cpp | 75 +++++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d99ea..a7eb12e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ cuda_add_library(kernels SHARED ${tkdnn_CUSRC}) find_package(OpenCV REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") +find_package(yaml-cpp REQUIRED) #------------------------------------------------------------------------------- # Build Libraries @@ -118,7 +119,7 @@ add_executable(centernet_demo demo/demo/demo_centernet.cpp) target_link_libraries(centernet_demo tkDNN) add_executable(map_demo demo/demo/map.cpp) -target_link_libraries(map_demo tkDNN) +target_link_libraries(map_demo tkDNN yaml-cpp) #------------------------------------------------------------------------------- diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index bbbd77a..80c56dd 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -17,6 +17,8 @@ #include "evaluation.h" #include +#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) { @@ -24,27 +26,53 @@ void convertFilename(std::string &filename,const std::string l_folder, const std filename.replace(filename.find(l_ext),l_ext.length(),i_ext); } +void readParams(char* config_filename, std::string& net, char &ntype, std::string& labels_path, + bool &show, bool& write_dets, int& classes, int& n_images, + int& map_points, int& map_levels, float& map_step, + float& IoU_thresh, float& conf_thresh, bool& verbose) +{ + YAML::Node config = YAML::LoadFile(config_filename); + net = config["net"].as(); + ntype = config["ntype"].as(); + labels_path = config["labels_path"].as(); + show = config["show"].as(); + write_dets = config["write_dets"].as(); + classes = config["classes"].as(); + n_images = config["n_images"].as(); + map_points = config["map_points"].as(); + map_levels = config["map_levels"].as(); + map_step = config["map_step"].as(); + IoU_thresh = config["IoU_thresh"].as(); + conf_thresh = config["conf_thresh"].as(); + verbose = config["verbose"].as(); + +} + int main(int argc, char *argv[]) { - // char *net = "resnet101_cnet_FP32.rt"; - char *net = "yolo3.rt"; + + char *config_filename = "config.yaml"; if(argc > 1) - net = argv[1]; - char ntype = 'y'; + config_filename = argv[1]; + + char ntype; + std::string net, labels_path; + bool show, write_dets, verbose; + int classes, map_points, map_levels, n_images; + float map_step, IoU_thresh, conf_thresh; + + readParams( config_filename, net, ntype, labels_path, show, write_dets, + classes, n_images, map_points, map_levels, map_step, + IoU_thresh, conf_thresh, verbose); + if(argc > 2) - ntype = argv[2][0]; - //path to txt file with all realpath of images labels - char *labels_path = "/media/887E650E7E64F67A/val2017/all_labels2017.txt"; + net = argv[2]; if(argc > 3) - labels_path = argv[3]; - - bool show = false; - bool write_dets = false; + ntype = argv[3][0]; tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; - switch(ntype) { case 'y': @@ -57,29 +85,26 @@ int main(int argc, char *argv[]) FatalError("Network type not allowed (3rd parameter)\n"); } - std::ifstream all_labels(labels_path); std::string l_filename; std::vector images; + std::vector detected_bbox; std::cout<<"Reading groundtruth and generating detections"< detected_bbox; - - int i=0; - while (std::getline(all_labels, l_filename) && i < 1000) + for (int images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) { - std::cout <