From c4e955eab54332eb8483629b0df42cd0ed94fae0 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 11 Jun 2020 12:43:34 +0200 Subject: [PATCH 1/8] Add different yolov4 size tests Signed-off-by: Micaela Verucchi --- include/tkDNN/utils.h | 2 +- src/utils.cpp | 16 +- tests/darknet/cfg/yolo4_320.cfg | 1156 +++++++++++++++++ .../darknet/cfg/{yolo4.cfg => yolo4_416.cfg} | 0 tests/darknet/cfg/yolo4_512.cfg | 1156 +++++++++++++++++ tests/darknet/cfg/yolo4_608.cfg | 1156 +++++++++++++++++ tests/darknet/{yolo4.cpp => yolo4_320.cpp} | 6 +- tests/darknet/yolo4_416.cpp | 34 + tests/darknet/yolo4_512.cpp | 34 + tests/darknet/yolo4_608.cpp | 34 + tests/test_rtinference/rtinference.cpp | 16 +- 11 files changed, 3596 insertions(+), 14 deletions(-) create mode 100644 tests/darknet/cfg/yolo4_320.cfg rename tests/darknet/cfg/{yolo4.cfg => yolo4_416.cfg} (100%) create mode 100644 tests/darknet/cfg/yolo4_512.cfg create mode 100644 tests/darknet/cfg/yolo4_608.cfg rename tests/darknet/{yolo4.cpp => yolo4_320.cpp} (85%) create mode 100644 tests/darknet/yolo4_416.cpp create mode 100644 tests/darknet/yolo4_512.cpp create mode 100644 tests/darknet/yolo4_608.cpp diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index aa73e9e..bca99f8 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -105,7 +105,7 @@ void printCenteredTitle(const char *title, char fill, int dim = 30); bool fileExist(const char *fname); void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string& test_folder, const std::string& weights_url); void readBinaryFile(std::string fname, int size, dnnType** data_h, dnnType** data_d, int seek = 0); -int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true, int limit = 10); +int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device = true, int limit = 10, bool verbose=true); void printDeviceVector(int size, dnnType* vec_d, bool device = true); float getColor(const int c, const int x, const int max); void resize(int size, dnnType **data); diff --git a/src/utils.cpp b/src/utils.cpp index 65030f0..1ab57ad 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -83,7 +83,7 @@ void printDeviceVector(int size, dnnType* vec_d, bool device){ delete [] vec; } -int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device, int limit) { +int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device, int limit, bool verbose) { dnnType *data_h, *correct_h; const float eps = 0.02f; @@ -117,13 +117,15 @@ int checkResult(int size, dnnType *data_d, dnnType *correct_d, bool device, int delete [] correct_h; } - std::cout<<" | "; - if(diffs == 0) - std::cout< input_bins = { bin_path + "/layers/input.bin" }; @@ -15,9 +15,9 @@ int main() { bin_path + "/debug/layer161_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo4.cfg"; + std::string cfg_path = "../tests/darknet/cfg/yolo4_320.cfg"; std::string name_path = "../tests/darknet/names/coco.names"; - downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download"); + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/64PHAwrM6RCZbiR/download"); // parse darknet network tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); diff --git a/tests/darknet/yolo4_416.cpp b/tests/darknet/yolo4_416.cpp new file mode 100644 index 0000000..984b265 --- /dev/null +++ b/tests/darknet/yolo4_416.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_416"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo4_416.cfg"; + std::string name_path = "../tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/982LxTQcNQfFQc4/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4_512.cpp b/tests/darknet/yolo4_512.cpp new file mode 100644 index 0000000..414e9be --- /dev/null +++ b/tests/darknet/yolo4_512.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_512"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo4_512.cfg"; + std::string name_path = "../tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/XN3FNXs3fnMaK5i/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4_608.cpp b/tests/darknet/yolo4_608.cpp new file mode 100644 index 0000000..dda084f --- /dev/null +++ b/tests/darknet/yolo4_608.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_608"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo4_608.cfg"; + std::string name_path = "../tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/Bg9r7kqDFJiFB4c/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/test_rtinference/rtinference.cpp b/tests/test_rtinference/rtinference.cpp index a629168..e128ae8 100644 --- a/tests/test_rtinference/rtinference.cpp +++ b/tests/test_rtinference/rtinference.cpp @@ -1,4 +1,5 @@ #include +#include #include "tkdnn.h" #include /* srand, rand */ @@ -29,6 +30,7 @@ int main(int argc, char *argv[]) { int ret_tensorrt = 0; std::cout<<"Testing with batchsize: "< stats; printCenteredTitle(" TENSORRT inference ", '=', 30); float total_time = 0; for(int i=0; i<1200; i++) { @@ -46,18 +48,26 @@ int main(int argc, char *argv[]) { netRT.infer(dim, input_d); TKDNN_TSTOP total_time+= t_ns; + if(i> 1) + stats.push_back(t_ns); // control output - std::cout<<"Output Buffers: "< Date: Thu, 11 Jun 2020 16:09:01 +0200 Subject: [PATCH 2/8] Add script for inference FPS Signed-off-by: Micaela Verucchi --- scripts/test_inference.sh | 51 ++++++++++++++++++++++++++ tests/test_rtinference/rtinference.cpp | 25 +++++++++++-- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 scripts/test_inference.sh diff --git a/scripts/test_inference.sh b/scripts/test_inference.sh new file mode 100644 index 0000000..fe8dac3 --- /dev/null +++ b/scripts/test_inference.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +function test_inference { + ./test_$1 + ./test_rtinference $1_$2.rt 1 + ./test_rtinference $1_$2.rt 4 +} + +sudo jeston_clock + +# modes=( 1 ) # only FP32 +# modes=( 1 2 ) # FP32 and FP16 +modes=( 1 2 3 ) # FP32, FP16 and INT8 + +rm times_rtinference.csv +for i in "${modes[@]}" +do + rm *rt + if [ $i -eq 1 ] + then + export TKDNN_MODE=FP32 + mode=fp32 + echo -e "${ORANGE}Test FP32${NC}" + fi + if [ $i -eq 2 ] + then + export TKDNN_MODE=FP16 + mode=fp16 + echo -e "${ORANGE}Test FP16${NC}" + fi + if [ $i -eq 3 ] + then + export TKDNN_MODE=INT8 + export TKDNN_CALIB_LABEL_PATH=../demo/COCO_val2017/all_labels.txt + export TKDNN_CALIB_IMG_PATH=../demo/COCO_val2017/all_images.txt + mode=int8 + echo -e "${ORANGE}Test INT8${NC}" + + fi + + export TKDNN_BATCHSIZE=4 + echo -e "${ORANGE}Batch $TKDNN_BATCHSIZE ${NC}" + + test_inference yolo4_320 $mode + test_inference yolo4_416 $mode + test_inference yolo4_512 $mode + test_inference yolo4_608 $mode +done + + + diff --git a/tests/test_rtinference/rtinference.cpp b/tests/test_rtinference/rtinference.cpp index e128ae8..76c2a33 100644 --- a/tests/test_rtinference/rtinference.cpp +++ b/tests/test_rtinference/rtinference.cpp @@ -18,6 +18,8 @@ int main(int argc, char *argv[]) { //convert network to tensorRT tk::dnn::NetworkRT netRT(NULL, argv[1]); + + tk::dnn::dataDim_t idim = netRT.input_dim; tk::dnn::dataDim_t odim = netRT.output_dim; @@ -63,11 +65,28 @@ int main(int argc, char *argv[]) { } } } - std::cout<<"Min: "<<*std::min_element(stats.begin(), stats.end())/BATCH_SIZE<<" ms\n"; - std::cout<<"Max: "<<*std::max_element(stats.begin(), stats.end())/BATCH_SIZE<<" ms\n"; + + double min = *std::min_element(stats.begin(), stats.end())/BATCH_SIZE; + double max = *std::max_element(stats.begin(), stats.end())/BATCH_SIZE; double mean =0; for(int i=0; i Date: Thu, 11 Jun 2020 20:54:17 +0200 Subject: [PATCH 3/8] New yolo4_512 download link Signed-off-by: Micaela Verucchi --- tests/darknet/yolo4_512.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/darknet/yolo4_512.cpp b/tests/darknet/yolo4_512.cpp index 414e9be..df3c2d0 100644 --- a/tests/darknet/yolo4_512.cpp +++ b/tests/darknet/yolo4_512.cpp @@ -17,7 +17,7 @@ int main() { std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo4_512.cfg"; std::string name_path = "../tests/darknet/names/coco.names"; - downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/XN3FNXs3fnMaK5i/download"); + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/fjFDqFmiSARKxFe/download"); // parse darknet network tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); From e7779ad773baacc42f30c0c1485f1dc65ffd8f57 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Wed, 8 Jul 2020 09:52:36 +0200 Subject: [PATCH 4/8] Add conf_thresh parameter to detectors, add batches handling in map demo Signed-off-by: Micaela Verucchi --- demo/demo/demo.cpp | 3 +- demo/demo/map.cpp | 171 +++++++++++++++++------------ include/tkDNN/CenternetDetection.h | 2 +- include/tkDNN/DetectionNN.h | 2 +- include/tkDNN/MobilenetDetection.h | 2 +- include/tkDNN/Yolo3Detection.h | 2 +- include/tkDNN/evaluation.h | 2 + src/CenternetDetection.cpp | 3 +- src/MobilenetDetection.cpp | 3 +- src/Yolo3Detection.cpp | 3 +- 10 files changed, 113 insertions(+), 80 deletions(-) diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 76b451d..85538a8 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -69,7 +69,8 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } - detNN->init(net, n_classes, n_batch); + float conf_thresh = 0.3; + detNN->init(net, conf_thresh, n_classes, n_batch); gRun = true; diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index d724db0..ea6eba4 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -31,6 +31,8 @@ int main(int argc, char *argv[]) const char *config_filename = "../demo/config.yaml"; const char * net = "yolo3.rt"; const char * labels_path = "../demo/COCO_val2017/all_labels.txt"; + int n_batches = 1; + float confidence_thresh = 0.3; bool show = false; bool write_dets = false; bool write_res_on_file = true; @@ -53,6 +55,12 @@ int main(int argc, char *argv[]) labels_path = argv[3]; if(argc > 4) config_filename = argv[4]; + if(argc > 5) + n_batches = atoi(argv[5]); + if(argc > 6) + confidence_thresh = atof(argv[6]); + + std::cout<<"conf t: "<init(net, n_classes); + detNN->init(net, confidence_thresh, n_classes, n_batches); //read images std::ifstream all_labels(labels_path); @@ -118,90 +126,109 @@ int main(int argc, char *argv[]) if(show) cv::namedWindow("detection", cv::WINDOW_NORMAL); + bool file_ok = false; + int images_done; - for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) { - std::cout < batch_frames; - batch_frames.push_back(frame); - int height = frame.rows; - int width = frame.cols; - - if(!frame.data) - break; std::vector batch_dnn_input; - batch_dnn_input.push_back(frame.clone()); + + std::vector cur_frames; + for(;cur_batches> 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(batch_frames[cur_batches], cv::Point((b.x-b.w/2)*f.width, (b.y-b.h/2)*f.height), cv::Point((b.x+b.w/2)*f.width,(b.y+b.h/2)*f.height), cv::Scalar(0, 255, 0), 2); + } + } + + cur_frames.push_back(f); + } + if (!file_ok) + break; //inference - detected_bbox.clear(); - detNN->update(batch_dnn_input,1,write_res_on_file, ×, write_coco_json); + detNN->update(batch_dnn_input,cur_batches,write_res_on_file, ×, write_coco_json); detNN->draw(batch_frames); - detected_bbox = detNN->detected; - if(write_coco_json) - printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height); + for(int j=0;jbatchDetected[j], classes, cur_frames[j].width, cur_frames[j].height); - std::ofstream myfile; - if(write_dets) - myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("labels/") + 7)); + std::ofstream myfile; + if(write_dets) + myfile.open ("det/"+cur_frames[j].lFilename.substr(cur_frames[j].lFilename.find("labels/") + 7)); - // save detections labels - for(auto d:detected_bbox){ - //convert detected bb in the same format as label - /// / / / - tk::dnn::BoundingBox b; - b.x = (d.x + d.w/2) / width; - b.y = (d.y + d.h/2) / height; - b.w = d.w / width; - b.h = d.h / height; - b.prob = d.prob; - b.cl = d.cl; - f.det.push_back(b); + // save detections labels + for(auto d:detNN->batchDetected[j]){ + //convert detected bb in the same format as label + /// / / / + tk::dnn::BoundingBox b; + b.x = (d.x + d.w/2) / cur_frames[j].width; + b.y = (d.y + d.h/2) / cur_frames[j].height; + b.w = d.w / cur_frames[j].width; + b.h = d.h / cur_frames[j].height; + b.prob = d.prob; + b.cl = d.cl; + cur_frames[j].det.push_back(b); + + if(write_dets) + myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n"; + + if(show)// draw rectangle for detection + cv::rectangle(batch_frames[j], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2); + } if(write_dets) - myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n"; - - if(show)// draw rectangle for detection - cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2); - } - - if(write_dets) - myfile.close(); - - // read and save groundtruth labels - 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(batch_frames[0], 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); - } - } + myfile.close(); - images.push_back(f); + images.push_back(cur_frames[j]); - if(show){ - cv::imshow("detection", batch_frames[0]); - cv::waitKey(0); + if(show){ + cv::imshow("detection", batch_frames[j]); + cv::waitKey(0); + } + } - + std::cout < gt; std::vector det; + int width; + int height; void print() const; }; diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 9d8df38..9c3436c 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -3,11 +3,12 @@ namespace tk { namespace dnn { -bool CenternetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches){ +bool CenternetDetection::init(const std::string& tensor_path, const float conf_threshold, const int n_classes, const int n_batches){ std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() ); classes = n_classes; nBatches = n_batches; + confThreshold = conf_threshold; dim = netRT->input_dim; diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index c905fea..af20f9e 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -126,12 +126,13 @@ float MobilenetDetection::iou(const tk::dnn::box &a, const tk::dnn::box &b){ return iou; } -bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches){ +bool MobilenetDetection::init(const std::string& tensor_path, const float conf_threshold, const int n_classes, const int n_batches){ std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str()); imageSize = netRT->input_dim.h; classes = n_classes; nBatches = n_batches; + confThreshold = conf_threshold; SSDSpec specs[N_SSDSPEC]; diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index c76af20..09eb151 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -3,13 +3,14 @@ namespace tk { namespace dnn { -bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches) { +bool Yolo3Detection::init(const std::string& tensor_path, const float conf_threshold, const int n_classes, const int n_batches) { //convert network to tensorRT std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() ); nBatches = n_batches; + confThreshold = conf_threshold; tk::dnn::dataDim_t idim = netRT->input_dim; idim.n = nBatches; From 594947f3014b585b8d333ded07fc36fcdb2f8250 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Wed, 8 Jul 2020 11:27:09 +0200 Subject: [PATCH 5/8] Update file names map demo Signed-off-by: Micaela Verucchi --- demo/demo/map.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index ea6eba4..facb8f7 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -36,7 +36,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; + bool write_coco_json = false; int n_images = 5000; bool verbose; @@ -88,9 +88,9 @@ int main(int argc, char *argv[]) } if(write_res_on_file){ - times.open("times_"+net_name+".csv"); + times.open("times_"+net_name+"_"+ std::to_string(n_batches)+"_"+std::to_string(confidence_thresh)+".csv"); memory.open("memory.csv", std::ios_base::app); - memory< Date: Mon, 23 Nov 2020 13:07:54 +0100 Subject: [PATCH 6/8] Add computation of #parameters, #MACC, and max feature map size in the tests Signed-off-by: Micaela Verucchi --- include/tkDNN/Layer.h | 4 ++++ include/tkDNN/Network.h | 1 + src/Conv2d.cpp | 5 +++++ src/DeformConv2d.cpp | 6 ++++++ src/Layer.cpp | 2 ++ src/LayerWgs.cpp | 5 ++++- src/Network.cpp | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index 790a431..91a6af0 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -54,6 +54,10 @@ public: int id = 0; bool final; //if the layer is the final one + uint n_params = 0; + uint feature_map_size = 0; + long unsigned MACC = 0; + std::string getLayerName() { layerType_t type = getLayerType(); diff --git a/include/tkDNN/Network.h b/include/tkDNN/Network.h index b78acff..6edf248 100644 --- a/include/tkDNN/Network.h +++ b/include/tkDNN/Network.h @@ -50,6 +50,7 @@ public: bool addLayer(Layer *l); void print(); const char *getNetworkRTName(const char *network_name); + void adjustFeatureMapSizeWithShortcuts(); cudnnDataType_t dataType; cudnnTensorFormat_t tensorFormat; diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index b57cf58..2901a70 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -166,6 +166,11 @@ Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW, } initCUDNN(deConv); + if(this->groups != 1) + MACC = kernelH*kernelW*output_dim.c*output_dim.w*output_dim.h; + else + MACC = input_dim.c*kernelH*kernelW*output_dim.c*output_dim.w*output_dim.h; + // allocate warkspace if (ws_sizeInBytes!=0) { checkCuda( cudaMalloc(&workSpace, ws_sizeInBytes) ); diff --git a/src/DeformConv2d.cpp b/src/DeformConv2d.cpp index dbb71e1..826cbb0 100644 --- a/src/DeformConv2d.cpp +++ b/src/DeformConv2d.cpp @@ -73,6 +73,12 @@ DeformConv2d::DeformConv2d( Network *net, int out_ch, int deformable_group, int output_dim.c = out_ch; initCUDNN(); + + if(this->deformableGroup != 1) + MACC = kernelH*kernelW*output_dim.c*output_dim.w*output_dim.h; + else + MACC = input_dim.c*kernelH*kernelW*output_dim.c*output_dim.w*output_dim.h; + //allocate data for infer result checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) ); } diff --git a/src/Layer.cpp b/src/Layer.cpp index a355b90..7e13a48 100644 --- a/src/Layer.cpp +++ b/src/Layer.cpp @@ -18,6 +18,8 @@ Layer::Layer(Network *net) { if(!net->addLayer(this)) FatalError("Net reached max number of layers"); } + + feature_map_size = input_dim.tot() + output_dim.tot(); } Layer::~Layer() { diff --git a/src/LayerWgs.cpp b/src/LayerWgs.cpp index a761327..2f875a4 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -19,6 +19,8 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, int seek = 0; readBinaryFile(weights_path.c_str(), inputs*outputs*kh*kw*kl, &data_h, &data_d, seek); seek += inputs*outputs*kh*kw*kl; + n_params = seek; + this->additional_bias = additional_bias; if(additional_bias) { readBinaryFile(weights_path.c_str(), outputs, &bias2_h, &bias2_d, seek); @@ -26,15 +28,16 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, } readBinaryFile(weights_path.c_str(), outputs, &bias_h, &bias_d, seek); + seek += outputs; this->batchnorm = batchnorm; if(batchnorm) { - seek += outputs; readBinaryFile(weights_path.c_str(), outputs, &scales_h, &scales_d, seek); seek += outputs; readBinaryFile(weights_path.c_str(), outputs, &mean_h, &mean_d, seek); seek += outputs; readBinaryFile(weights_path.c_str(), outputs, &variance_h, &variance_d, seek); + seek += outputs; float eps = TKDNN_BN_MIN_EPSILON; diff --git a/src/Network.cpp b/src/Network.cpp index 7fa291f..2c3c8c7 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -96,6 +96,28 @@ dataDim_t Network::getOutputDim() { return layers[num_layers-1]->output_dim; } +void Network::adjustFeatureMapSizeWithShortcuts(){ + layerType_t layer_type; + int shortcutted_idx; + + for(int i=0; igetLayerType(); + if(layer_type == LAYER_SHORTCUT){ + shortcutted_idx = -1; + for(int j=0; j(layers[i])->backLayer == layers[j]){ + shortcutted_idx = j; + break; + } + } + if(shortcutted_idx == -1) + FatalError("Problem when computing featuer_map_size with shortcuts"); + for(int j=shortcutted_idx+1; jfeature_map_size += layers[shortcutted_idx]->output_dim.tot(); + } + } +} + void Network::print() { printCenteredTitle(" NETWORK MODEL ", '=', 60); @@ -106,10 +128,21 @@ void Network::print() { std::cout.width(16); std::cout<input_dim; dataDim_t out = layers[i]->output_dim; + tot_params += layers[i]->n_params; + tot_MACC += layers[i]->MACC; + if(layers[i]->feature_map_size> max_feature_map_size) + max_feature_map_size = layers[i]->feature_map_size; + std::cout.width(3); std::cout<getLayerName(); @@ -128,6 +161,9 @@ void Network::print() { } printCenteredTitle("", '=', 60); std::cout<<"\n"; + std::cout<<"N params: "< Date: Thu, 25 Feb 2021 09:57:10 +0100 Subject: [PATCH 7/8] Add yolo4_320_coco2 (pedestrian and stop sign) Signed-off-by: Micaela Verucchi --- tests/darknet/cfg/yolo4_320_coco2.cfg | 1158 +++++++++++++++++++++++++ tests/darknet/names/coco2.names | 2 + tests/darknet/yolo4_320_coco2.cpp | 34 + 3 files changed, 1194 insertions(+) create mode 100644 tests/darknet/cfg/yolo4_320_coco2.cfg create mode 100644 tests/darknet/names/coco2.names create mode 100644 tests/darknet/yolo4_320_coco2.cpp diff --git a/tests/darknet/cfg/yolo4_320_coco2.cfg b/tests/darknet/cfg/yolo4_320_coco2.cfg new file mode 100644 index 0000000..9585fca --- /dev/null +++ b/tests/darknet/cfg/yolo4_320_coco2.cfg @@ -0,0 +1,1158 @@ +[net] +batch=64 +subdivisions=32 +# Training +#width=512 +#height=512 +width=320 +height=320 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.0013 +burn_in=1000 +max_batches = 6000 +policy=steps +steps=4800,5400 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + +#:104x104 54:52x52 85:26x26 104:13x13 for 416 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-7 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-10 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-16 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 54 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.2 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=leaky + +[route] +layers = -1, -16 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.1 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=leaky + +[route] +layers = -1, -37 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + diff --git a/tests/darknet/names/coco2.names b/tests/darknet/names/coco2.names new file mode 100644 index 0000000..e2f8903 --- /dev/null +++ b/tests/darknet/names/coco2.names @@ -0,0 +1,2 @@ +person +stop sign \ No newline at end of file diff --git a/tests/darknet/yolo4_320_coco2.cpp b/tests/darknet/yolo4_320_coco2.cpp new file mode 100644 index 0000000..877e604 --- /dev/null +++ b/tests/darknet/yolo4_320_coco2.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_320_coco2"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo4_320_coco2.cfg"; + std::string name_path = "../tests/darknet/names/coco2.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/f3wk99iG5y7tEr8/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} From 89b1bb7beeb5f84a93bf5eb98b8b0d45941357c4 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 20 Jul 2021 18:39:25 +0200 Subject: [PATCH 8/8] Add missing files Signed-off-by: Micaela Verucchi --- tests/darknet/cfg/yolo4.cfg | 1156 +++++++++++++++++++++++++++++++++++ tests/darknet/yolo4.cpp | 34 ++ 2 files changed, 1190 insertions(+) create mode 100644 tests/darknet/cfg/yolo4.cfg create mode 100644 tests/darknet/yolo4.cpp diff --git a/tests/darknet/cfg/yolo4.cfg b/tests/darknet/cfg/yolo4.cfg new file mode 100644 index 0000000..88fc3c4 --- /dev/null +++ b/tests/darknet/cfg/yolo4.cfg @@ -0,0 +1,1156 @@ +[net] +# Testing +batch=1 +subdivisions=1 +# Training +#batch=64 +#subdivisions=8 +width=416 +height=416 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + +#:104x104 54:52x52 85:26x26 104:13x13 for 416 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-7 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-10 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-16 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 54 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.2 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=leaky + +[route] +layers = -1, -16 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.1 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=leaky + +[route] +layers = -1, -37 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 + diff --git a/tests/darknet/yolo4.cpp b/tests/darknet/yolo4.cpp new file mode 100644 index 0000000..8de8651 --- /dev/null +++ b/tests/darknet/yolo4.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo4.cfg"; + std::string name_path = "../tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/982LxTQcNQfFQc4/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +}