From a9970f43fb5843d1ab87b5b02cbb7d8ca7bcc376 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 18 Dec 2018 18:07:37 +0100 Subject: [PATCH] tests/yolo_berkeley/yolo_berkeley.cpp --- demo/live/live.cpp | 40 ++++++------------- tests/yolo_berkeley/yolo_berkeley.cpp | 56 +++++++++++++-------------- 2 files changed, 40 insertions(+), 56 deletions(-) diff --git a/demo/live/live.cpp b/demo/live/live.cpp index e04d605..690112a 100644 --- a/demo/live/live.cpp +++ b/demo/live/live.cpp @@ -7,15 +7,7 @@ #include #include -#define VOC - -#ifdef VOC -const char *reg_bias = "../tests/yolo_voc/layers/g31.bin"; -#define CLASS 20 -#else -const char *reg_bias = "../tests/yolo/layers/g31.bin"; -#define CLASS 80 -#endif +const char *reg_bias = "../tests/yolo_berkeley/layers/g31.bin"; int prob_sort(const void *pa, const void *pb) { tk::dnn::box a = *(tk::dnn::box *)pa; @@ -26,30 +18,22 @@ int prob_sort(const void *pa, const void *pb) { return 0; } -cv::Mat GetSquareImage(const cv::Mat& img, int target_width) { +cv::Mat GetSquareImage(const cv::Mat& img, int target_height, int target_width) { int width = img.cols, height = img.rows; - cv::Mat square = cv::Mat::zeros( target_width, target_width, img.type() ); + cv::Mat square = cv::Mat::zeros( target_height, target_width, img.type() ); int max_dim = ( width >= height ) ? width : height; float scale = ( ( float ) target_width ) / max_dim; cv::Rect roi; - if ( width >= height ) - { + roi.width = target_width; roi.x = 0; - roi.height = height * scale; - roi.y = ( target_width - roi.height ) / 2; - } - else - { + roi.height = target_height; roi.y = 0; - roi.height = target_width; - roi.width = width * scale; - roi.x = ( target_width - roi.width ) / 2; - } - cv::resize( img, square( roi ), roi.size() ); + + cv::resize( img, square(roi), roi.size() ); return square; } @@ -61,7 +45,7 @@ double compute_image( cv::Mat imageORIG, TIMER_START //Resize with padding and convert to float - cv::Mat image = GetSquareImage(imageORIG, netRT->input_dim.w); + cv::Mat image = GetSquareImage(imageORIG, netRT->input_dim.h, netRT->input_dim.w); cv::Mat imageF; image.convertTo(imageF, CV_32FC3, 1/255.0); @@ -109,7 +93,7 @@ int main(int argc, char *argv[]) { //params char *tensor_path = NULL; - int device = 0; + char *device = 0; float thresh = 0.3f; bool show = false; @@ -127,7 +111,7 @@ int main(int argc, char *argv[]) { if(argc - optind == 2) { tensor_path = argv[optind]; - device = atoi(argv[optind+1]); + device = argv[optind+1]; } else { std::cout<<"not enough arguments.\n"; return print_usage(); @@ -149,7 +133,7 @@ int main(int argc, char *argv[]) { //convert network to tensorRT tk::dnn::NetworkRT netRT(NULL, tensor_path); - tk::dnn::RegionInterpret rI(netRT.input_dim, netRT.output_dim, CLASS, 4, 5, thresh, reg_bias); + tk::dnn::RegionInterpret rI(netRT.input_dim, netRT.output_dim, 10, 4, 5, thresh, reg_bias); dnnType *input = new float[netRT.input_dim.tot()]; dnnType *output = new float[netRT.output_dim.tot()]; @@ -163,7 +147,7 @@ int main(int argc, char *argv[]) { //LOAD IMAGE cv::Mat img; //= cv::imread("../demo/live/test.jpeg", CV_LOAD_IMAGE_COLOR); cap >> img; - + //show results if(!img.data) FatalError("Could not open image"); std::cout<<"Image size: ("< #include "tkdnn.h" -const char *input_bin = "../tests/yolo_berkely/layers/input.bin"; -const char *c0_bin = "../tests/yolo_berkely/layers/c0.bin"; -const char *c2_bin = "../tests/yolo_berkely/layers/c2.bin"; -const char *c4_bin = "../tests/yolo_berkely/layers/c4.bin"; -const char *c5_bin = "../tests/yolo_berkely/layers/c5.bin"; -const char *c6_bin = "../tests/yolo_berkely/layers/c6.bin"; -const char *c8_bin = "../tests/yolo_berkely/layers/c8.bin"; -const char *c9_bin = "../tests/yolo_berkely/layers/c9.bin"; -const char *c10_bin = "../tests/yolo_berkely/layers/c10.bin"; -const char *c12_bin = "../tests/yolo_berkely/layers/c12.bin"; -const char *c13_bin = "../tests/yolo_berkely/layers/c13.bin"; -const char *c14_bin = "../tests/yolo_berkely/layers/c14.bin"; -const char *c15_bin = "../tests/yolo_berkely/layers/c15.bin"; -const char *c16_bin = "../tests/yolo_berkely/layers/c16.bin"; -const char *c18_bin = "../tests/yolo_berkely/layers/c18.bin"; -const char *c19_bin = "../tests/yolo_berkely/layers/c19.bin"; -const char *c20_bin = "../tests/yolo_berkely/layers/c20.bin"; -const char *c21_bin = "../tests/yolo_berkely/layers/c21.bin"; -const char *c22_bin = "../tests/yolo_berkely/layers/c22.bin"; -const char *c23_bin = "../tests/yolo_berkely/layers/c23.bin"; -const char *c24_bin = "../tests/yolo_berkely/layers/c24.bin"; -const char *c26_bin = "../tests/yolo_berkely/layers/c26.bin"; -const char *c29_bin = "../tests/yolo_berkely/layers/c29.bin"; -const char *c30_bin = "../tests/yolo_berkely/layers/c30.bin"; -const char *g31_bin = "../tests/yolo_berkely/layers/g31.bin"; -const char *output_bin = "../tests/yolo_berkely/layers/output.bin"; +const char *input_bin = "../tests/yolo_berkeley/layers/input.bin"; +const char *c0_bin = "../tests/yolo_berkeley/layers/c0.bin"; +const char *c2_bin = "../tests/yolo_berkeley/layers/c2.bin"; +const char *c4_bin = "../tests/yolo_berkeley/layers/c4.bin"; +const char *c5_bin = "../tests/yolo_berkeley/layers/c5.bin"; +const char *c6_bin = "../tests/yolo_berkeley/layers/c6.bin"; +const char *c8_bin = "../tests/yolo_berkeley/layers/c8.bin"; +const char *c9_bin = "../tests/yolo_berkeley/layers/c9.bin"; +const char *c10_bin = "../tests/yolo_berkeley/layers/c10.bin"; +const char *c12_bin = "../tests/yolo_berkeley/layers/c12.bin"; +const char *c13_bin = "../tests/yolo_berkeley/layers/c13.bin"; +const char *c14_bin = "../tests/yolo_berkeley/layers/c14.bin"; +const char *c15_bin = "../tests/yolo_berkeley/layers/c15.bin"; +const char *c16_bin = "../tests/yolo_berkeley/layers/c16.bin"; +const char *c18_bin = "../tests/yolo_berkeley/layers/c18.bin"; +const char *c19_bin = "../tests/yolo_berkeley/layers/c19.bin"; +const char *c20_bin = "../tests/yolo_berkeley/layers/c20.bin"; +const char *c21_bin = "../tests/yolo_berkeley/layers/c21.bin"; +const char *c22_bin = "../tests/yolo_berkeley/layers/c22.bin"; +const char *c23_bin = "../tests/yolo_berkeley/layers/c23.bin"; +const char *c24_bin = "../tests/yolo_berkeley/layers/c24.bin"; +const char *c26_bin = "../tests/yolo_berkeley/layers/c26.bin"; +const char *c29_bin = "../tests/yolo_berkeley/layers/c29.bin"; +const char *c30_bin = "../tests/yolo_berkeley/layers/c30.bin"; +const char *g31_bin = "../tests/yolo_berkeley/layers/g31.bin"; +const char *output_bin = "../tests/yolo_berkeley/layers/output.bin"; int main() { @@ -97,7 +97,7 @@ int main() { tk::dnn::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true); tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); tk::dnn::Conv2d c30(&net, 75, 1, 1, 1, 1, 0, 0, c30_bin, false); - tk::dnn::Region g31(&net, 20, 4, 5); + tk::dnn::Region g31(&net, 10, 4, 5); tk::dnn::RegionInterpret rI(dim, g31.output_dim, 10, 4, 5, 0.3f, g31_bin); @@ -110,7 +110,7 @@ int main() { net.print(); //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, "yolo_berkely.rt"); + tk::dnn::NetworkRT netRT(&net, "yolo_berkeley.rt"); dnnType *out_data, *out_data2; // cudnn output, tensorRT output