diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b2551e..b430195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ endif() find_package(CUDA 9.0 REQUIRED) SET(CUDA_SEPARABLE_COMPILATION ON) #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30 --compiler-options '-fPIC'") -#set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) +set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) find_package(CUDNN REQUIRED) @@ -39,7 +39,7 @@ find_package(yaml-cpp REQUIRED) # Build Libraries #------------------------------------------------------------------------------- file(GLOB tkdnn_SRC "src/*.cpp") -set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS}) +set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS} yaml-cpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES}) @@ -120,7 +120,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 yaml-cpp) +target_link_libraries(map_demo tkDNN) #------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 12bb124..b4ab4a6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ this branch actually work on every NVIDIA GPU that support the dependencies: * CUDNN 7.603 * TENSORRT 6.01 * OPENCV 4.1 +* yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev) ## Workflow The recommended workflow follow these step: @@ -112,4 +113,23 @@ this will genereate resnet101_cnet.rt and dla34_cnet.rt file that can be used fo ./centernet_demo # launch detection on a demo video ./centernet_demo resnet101_cnet.rt /dev/video0 # launch detection on device 0 ./centernet_demo dla34_cnet.rt /dev/video0 # launch detection on device 0 +``` + +## mAP demo +To compute mAP, precision, recall and f1score, run the map_demo. + +The following parameters are needed: +``` +./map_demo +``` +where +* : rt file of a choosen network on wich compute the mAP. +* : type of network. Right now only y(yolo) and c(centernet) are allowed +* : path to a text file containing all the paths of the groundtruth labels. It is important that all the labels of the groundtruth are in a folder called 'labels'. In the folder containing the folder 'labels' there should be also a folder 'images', containing all the groundtruth images having the same same as the labels. To better understand, if there is a label path/to/labels/000001.txt there should be a corresponding image path/to/images/000001.jpg. +* : path to a yaml file with the parameters needed for the mAP computation, similar to demo/config.yaml + +Example: + +``` +./map_demo dla34_cnet.rt c path/to/labelsCOCO_val2017.txt ../demo/config.yaml ``` \ No newline at end of file diff --git a/demo/config.yaml b/demo/config.yaml new file mode 100644 index 0000000..3577abf --- /dev/null +++ b/demo/config.yaml @@ -0,0 +1,7 @@ +classes : 80 #number of classes +map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC) +map_levels : 10 #number of IoU step for the AP +map_step : 0.05 #step of IoU +IoU_thresh : 0.5 #starting IoU threshold +conf_thresh : 0.3 #threshold on the condifence of the bbox +verbose : false #print on screen information \ No newline at end of file diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index 80c56dd..bc578d8 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -17,7 +17,7 @@ #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) @@ -26,49 +26,24 @@ 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 *config_filename = "config.yaml"; + char ntype = 'y'; + char *config_filename = "../demo/config.yaml"; + char * net = "yolo3.rt"; + char * labels_path = "/media/887E650E7E64F67A/val2017/all_labels2017.txt"; + bool show = false; + bool write_dets = false; + int n_images = 1000; + if(argc > 1) - 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); - + net = argv[1]; if(argc > 2) - net = argv[2]; + ntype = argv[2][0]; if(argc > 3) - ntype = argv[3][0]; + labels_path = argv[3]; + if(argc > 3) + config_filename = argv[4]; tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; @@ -183,6 +158,14 @@ int main(int argc, char *argv[]) } std::cout<<"Done."< #include +#include + #include "tkdnn.h" @@ -45,6 +47,10 @@ float boxIntersection(const BoundingBox &a, const BoundingBox &b); float boxUnion(const BoundingBox &a, const BoundingBox &b); float boxIoU(const BoundingBox &a, const BoundingBox &b); +void readParams(char* config_filename, int& classes, int& map_points, + int& map_levels, float& map_step, float& IoU_thresh, + float& conf_thresh, bool& verbose); + double computeMap(std::vector &images,const int classes,const float IoU_thresh, const float conf_thresh=0.3, const int map_points=101, const bool verbose=false); double computeMapNIoULevels(std::vector &images,const int classes,const float i_IoU_thresh=0.5, const float conf_thresh=0.3, const int map_points=101, const float map_step=0.05, const int map_levels=10, const bool verbose=false); diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 65f7708..c65ce50 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -76,6 +76,21 @@ float boxIoU(const BoundingBox &a, const BoundingBox &b) return I / U; } +void readParams(char* config_filename, int& classes, int& map_points, + int& map_levels, float& map_step, float& IoU_thresh, + float& conf_thresh, bool& verbose) +{ + YAML::Node config = YAML::LoadFile(config_filename); + classes = config["classes"].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(); + +} + /* Credits to https://github.com/AlexeyAB/darknet/blob/master/src/detector.c*/ double computeMap(std::vector &images,const int classes,const float IoU_thresh, const float conf_thresh, const int map_points, const bool verbose) {