-Modified Dockerfile.base to cudagl

-Changed demo to take in input from demoConfig.yaml file
-Readme changes for demo.md
This commit is contained in:
perseusdg
2021-11-24 03:39:57 +05:30
parent a8c98e3c31
commit 9cecc5051a
11 changed files with 422 additions and 124 deletions
+55 -57
View File
@@ -18,64 +18,57 @@ void sig_handler(int signo) {
int main(int argc, char *argv[]) {
std::cout<<"detection\n";
signal(SIGINT, sig_handler);
#ifdef __linux__
std::string config_file = "../demo/demoConfig.yaml";
#elif _WIN32
std::string config_file = "..\\..\\..\\demo\\demoConfig.yaml";
#endif
std::string net = "yolo4tiny_fp32.rt";
#ifdef __linux__
std::string cfgPath = "../tests/darknet/cfg/yolo4tiny.cfg";
#elif _WIN32
std::string cfgPath = "..\\tests\\darknet\\cfg\\yolo4tiny.cfg";
#endif
#ifdef __linux__
std::string namePath = "../tests/darknet/names/coco.names";
#elif _WIN32
std::string namePath = "..\\tests\\darknet\\names\\coco.names";
#endif
if(argc > 1)
net = argv[1];
#ifdef __linux__
std::string input = "../demo/yolo_test.mp4";
#elif _WIN32
std::string input = "..\\demo\\yolo_test.mp4";
#endif
char ntype = 'y';
if(argc > 2)
input = argv[2];
if(argc > 3)
ntype = argv[3][0];
int n_classes = 80;
if(argc > 4)
n_classes = atoi(argv[4]);
if(argc > 5)
cfgPath = argv[5];
if(argc > 6)
namePath = argv[6];
int n_batch = 1;
if(argc > 7)
n_batch = atoi(argv[7]);
bool show = true;
if(argc > 8)
show = atoi(argv[8]);
float conf_thresh=0.3;
if(argc >= 9)
conf_thresh = atof(argv[9]);
if(n_batch < 1 || n_batch > 64)
FatalError("Batch dim not supported");
if(!show)
SAVE_RESULT = true;
if(ntype == 'c' || ntype == 'm'){
cfgPath = "";
namePath = "";
if(argc > 1){
config_file = argv[1];
}
YAML::Node conf = YAMLloadConf(config_file);
if(!conf){
FatalError("Problem with config file");
}
std::string net = YAMLgetConf<std::string>(conf,"net","yolo4tiny_fp32.rt");
if(!fileExist(net.c_str())) {
FatalError("The given network does not exist. Create the rt first.");
}
#ifdef __linux__
std::string input = YAMLgetConf<std::string>(conf, "input", "../demo/yolo_test.mp4");
std::string cfgPath = YAMLgetConf<std::string>(conf,"cfg_input", "../tests/darknet/cfg/yolo4tiny.cfg");
std::string namePath = YAMLgetConf<std::string>(conf,"name_input","../tests/darknet/names/coco.names");
#elif _WIN32
std::string input = YAMLgetConf(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4");
std::string cfgPath = YAMLgetConf(conf,"cfg_win_input","..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg");
std::string namePath = YAMLgetConf(conf,"name_win_input","..\\..\\..\\tests\\darknet\\names\\coco.names");
#endif
if(!fileExist(input.c_str()))
FatalError("The given input video does not exist.");
char ntype = YAMLgetConf<char>(conf, "ntype", 'y');
int n_classes = YAMLgetConf<int>(conf, "n_classes", 80);
int n_batch = YAMLgetConf<int>(conf, "n_batch", 1);
if(n_batch < 1 || n_batch > 64)
FatalError("Batch dim not supported");
float conf_thresh = YAMLgetConf<float>(conf, "conf_thresh", 0.3);
bool show = YAMLgetConf<bool>(conf, "show", true);
bool save = YAMLgetConf<bool>(conf, "save", false);
tk::dnn::Yolo3Detection yolo;
tk::dnn::CenternetDetection cnet;
tk::dnn::MobilenetDetection mbnet;
@@ -98,6 +91,11 @@ int main(int argc, char *argv[]) {
FatalError("Network type not allowed (3rd parameter)\n");
}
if(ntype == 'c' || ntype == 'm'){
cfgPath = "";
namePath = "";
}
detNN->init(net,cfgPath,namePath,n_classes,n_batch,conf_thresh);
gRun = true;
@@ -109,7 +107,7 @@ int main(int argc, char *argv[]) {
std::cout<<"camera started\n";
cv::VideoWriter resultVideo;
if(SAVE_RESULT) {
if(save) {
int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h));
@@ -149,7 +147,7 @@ int main(int argc, char *argv[]) {
cv::waitKey(1);
}
}
if(n_batch == 1 && SAVE_RESULT)
if(n_batch == 1 && save)
resultVideo << frame;
}
@@ -157,7 +155,7 @@ int main(int argc, char *argv[]) {
double mean = 0;
std::cout<<COL_GREENB<<"\n\nTime stats:\n";
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
for(int i=0; i<detNN->stats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size();
std::cout<<"Avg: "<<mean/n_batch<<" ms\t"<<1000/(mean/n_batch)<<" FPS\n"<<COL_END;
+22
View File
@@ -0,0 +1,22 @@
# video input
input : "../demo/yolo_test.mp4"
win_input : "..\\..\\..\\demo\\yolo_test.mp4"
#cfg input
cfg_input : "../tests/darknet/cfg/yolo4tiny.cfg"
cfg_win_input : "..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg"
#name input
name_input : "../tests/darknet/names/coco.names"
name_win_input : "..\\..\\..\\tests\\darknet\\names\\coco.names"
# network config
net : "yolo4tiny_fp32.rt"
ntype : 'y'
n_classes : 80
n_batch : 1
conf_thresh : 0.3
# demo config
show : true
save : false