Change README.md, add config.yaml, refactoring
Signed-off-by: xavier <micaelaverucchi@gmail.com>
This commit is contained in:
+3
-3
@@ -17,7 +17,7 @@ endif()
|
|||||||
find_package(CUDA 9.0 REQUIRED)
|
find_package(CUDA 9.0 REQUIRED)
|
||||||
SET(CUDA_SEPARABLE_COMPILATION ON)
|
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} -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)
|
find_package(CUDNN REQUIRED)
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ find_package(yaml-cpp REQUIRED)
|
|||||||
# Build Libraries
|
# Build Libraries
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
file(GLOB tkdnn_SRC "src/*.cpp")
|
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")
|
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})
|
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)
|
target_link_libraries(centernet_demo tkDNN)
|
||||||
|
|
||||||
add_executable(map_demo demo/demo/map.cpp)
|
add_executable(map_demo demo/demo/map.cpp)
|
||||||
target_link_libraries(map_demo tkDNN yaml-cpp)
|
target_link_libraries(map_demo tkDNN)
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ this branch actually work on every NVIDIA GPU that support the dependencies:
|
|||||||
* CUDNN 7.603
|
* CUDNN 7.603
|
||||||
* TENSORRT 6.01
|
* TENSORRT 6.01
|
||||||
* OPENCV 4.1
|
* OPENCV 4.1
|
||||||
|
* yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev)
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
The recommended workflow follow these step:
|
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 # launch detection on a demo video
|
||||||
./centernet_demo resnet101_cnet.rt /dev/video0 # launch detection on device 0
|
./centernet_demo resnet101_cnet.rt /dev/video0 # launch detection on device 0
|
||||||
./centernet_demo dla34_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 <network rt> <network type [y|c]> <labels file path> <config file path>
|
||||||
|
```
|
||||||
|
where
|
||||||
|
* <network rt>: rt file of a choosen network on wich compute the mAP.
|
||||||
|
* <network type [y|c]>: type of network. Right now only y(yolo) and c(centernet) are allowed
|
||||||
|
* <labels file path>: 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.
|
||||||
|
* <config file path>: 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
|
||||||
```
|
```
|
||||||
@@ -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
|
||||||
+22
-39
@@ -17,7 +17,7 @@
|
|||||||
#include "evaluation.h"
|
#include "evaluation.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <yaml-cpp/yaml.h>
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
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);
|
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<std::string>();
|
|
||||||
ntype = config["ntype"].as<char>();
|
|
||||||
labels_path = config["labels_path"].as<std::string>();
|
|
||||||
show = config["show"].as<bool>();
|
|
||||||
write_dets = config["write_dets"].as<bool>();
|
|
||||||
classes = config["classes"].as<int>();
|
|
||||||
n_images = config["n_images"].as<int>();
|
|
||||||
map_points = config["map_points"].as<int>();
|
|
||||||
map_levels = config["map_levels"].as<int>();
|
|
||||||
map_step = config["map_step"].as<float>();
|
|
||||||
IoU_thresh = config["IoU_thresh"].as<float>();
|
|
||||||
conf_thresh = config["conf_thresh"].as<float>();
|
|
||||||
verbose = config["verbose"].as<bool>();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
char ntype = 'y';
|
||||||
char *config_filename = "config.yaml";
|
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)
|
if(argc > 1)
|
||||||
config_filename = argv[1];
|
net = 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)
|
if(argc > 2)
|
||||||
net = argv[2];
|
ntype = argv[2][0];
|
||||||
if(argc > 3)
|
if(argc > 3)
|
||||||
ntype = argv[3][0];
|
labels_path = argv[3];
|
||||||
|
if(argc > 3)
|
||||||
|
config_filename = argv[4];
|
||||||
|
|
||||||
tk::dnn::Yolo3Detection yolo;
|
tk::dnn::Yolo3Detection yolo;
|
||||||
tk::dnn::CenternetDetection cnet;
|
tk::dnn::CenternetDetection cnet;
|
||||||
@@ -183,6 +158,14 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout<<"Done."<<std::endl;
|
std::cout<<"Done."<<std::endl;
|
||||||
|
|
||||||
|
bool verbose;
|
||||||
|
int classes, map_points, map_levels;
|
||||||
|
float map_step, IoU_thresh, conf_thresh;
|
||||||
|
|
||||||
|
//read mAP parameters
|
||||||
|
readParams( config_filename, classes, map_points, map_levels, map_step,
|
||||||
|
IoU_thresh, conf_thresh, verbose);
|
||||||
|
|
||||||
//compute mAP
|
//compute mAP
|
||||||
double AP = computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose);
|
double AP = computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
#include "tkdnn.h"
|
#include "tkdnn.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -45,6 +47,10 @@ float boxIntersection(const BoundingBox &a, const BoundingBox &b);
|
|||||||
float boxUnion(const BoundingBox &a, const BoundingBox &b);
|
float boxUnion(const BoundingBox &a, const BoundingBox &b);
|
||||||
float boxIoU(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<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh=0.3, const int map_points=101, const bool verbose=false);
|
double computeMap(std::vector<Frame> &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<Frame> &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);
|
double computeMapNIoULevels(std::vector<Frame> &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);
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,21 @@ float boxIoU(const BoundingBox &a, const BoundingBox &b)
|
|||||||
return I / U;
|
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<int>();
|
||||||
|
map_points = config["map_points"].as<int>();
|
||||||
|
map_levels = config["map_levels"].as<int>();
|
||||||
|
map_step = config["map_step"].as<float>();
|
||||||
|
IoU_thresh = config["IoU_thresh"].as<float>();
|
||||||
|
conf_thresh = config["conf_thresh"].as<float>();
|
||||||
|
verbose = config["verbose"].as<bool>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Credits to https://github.com/AlexeyAB/darknet/blob/master/src/detector.c*/
|
/* Credits to https://github.com/AlexeyAB/darknet/blob/master/src/detector.c*/
|
||||||
double computeMap(std::vector<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh, const int map_points, const bool verbose)
|
double computeMap(std::vector<Frame> &images,const int classes,const float IoU_thresh, const float conf_thresh, const int map_points, const bool verbose)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user