From 7e7f480e2ba1856a9004477a203bdf6ee8274532 Mon Sep 17 00:00:00 2001 From: fbagni Date: Mon, 23 Dec 2019 16:11:41 +0100 Subject: [PATCH] Yolov3_tiny works on tensorRT Signed-off-by: fbagni --- src/Conv2d.cpp | 4 ++-- src/NetworkRT.cpp | 36 ++++++++++++++---------------------- src/Pooling.cpp | 4 ---- src/Yolo.cpp | 4 ++-- src/kernels/resize.cu | 4 ++-- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index b8296ac..ef73e40 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -17,8 +17,8 @@ void Conv2d::initCUDNN(bool back) { idim = output_dim; odim = input_dim; } - idim.print(); - odim.print(); + //idim.print(); + //odim.print(); checkCUDNN( cudnnCreateFilterDescriptor(&filterDesc) ); checkCUDNN( cudnnCreateConvolutionDescriptor(&convDesc) ); diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index ed72c89..c744b86 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -291,31 +291,23 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Pooling *l) { if(l->pool_mode == tkdnnPoolingMode_t::POOLING_AVERAGE) ptype = PoolingType::kAVERAGE; if(l->pool_mode == tkdnnPoolingMode_t::POOLING_AVERAGE_EXCLUDE_PADDING) ptype = PoolingType::kMAX_AVERAGE_BLEND; - IPoolingLayer *lRT = networkRT->addPooling(*input, - ptype, DimsHW{l->winH, l->winW}); + + if(l->input_dim.h % 2 == 1 && l->input_dim.w % 2 == 1) + { + IPlugin *plugin = new ResizeLayerRT( l->output_dim.c,l->output_dim.h+1,l->output_dim.w+1 ); + IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin); + checkNULL(lRT); + lRT->setName( "Resize" ); + + input = lRT->getOutput(0); + } + + IPoolingLayer *lRT = networkRT->addPooling(*input, ptype, DimsHW{l->winH, l->winW}); checkNULL(lRT); lRT->setPadding(DimsHW{l->paddingH, l->paddingW}); lRT->setStride(DimsHW{l->strideH, l->strideW}); - - - ITensor *t = lRT->getOutput(0); - // for(int j=0; jgetDimensions().nbDims; j++) { - // std::cout<getDimensions().d[j]<<" "; - // } - // std::cout<<" (TensorRT)\n"; - - IPlugin *plugin = new ResizeLayerRT( l->output_dim.c,l->output_dim.h,l->output_dim.w ); - IPluginLayer *lRT1 = networkRT->addPlugin(&t, 1, *plugin); - checkNULL(lRT1); - - // ITensor *t1 = lRT1->getOutput(0); - // for(int j=0; jgetDimensions().nbDims; j++) { - // std::cout<getDimensions().d[j]<<" "; - // } - // std::cout<<" (TensorRT after resize )\n"; - - return lRT1; + return lRT; } ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) { @@ -551,7 +543,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa return r; } - if(name.find("Pooling") == 0) { + if(name.find("Resize") == 0) { ResizeLayerRT *r = new ResizeLayerRT(readBUF(buf), //o_c readBUF(buf), //o_h readBUF(buf)); //o_w diff --git a/src/Pooling.cpp b/src/Pooling.cpp index 0f3573d..236adbf 100644 --- a/src/Pooling.cpp +++ b/src/Pooling.cpp @@ -25,8 +25,6 @@ Pooling::Pooling( Network *net, int winH, int winW, int strideH, int strideW, int h = input_dim.h; int w = input_dim.w; int l = input_dim.l; - - printf("before: %d %d\n", h, w); poolOn3d = false; @@ -64,8 +62,6 @@ Pooling::Pooling( Network *net, int winH, int winW, int strideH, int strideW, checkCUDNN( cudnnSetTensor4dDescriptor(dstTensorDesc, net->tensorFormat, net->dataType, n, c, h, w) ); - - printf("after: %d %d\n", h, w); output_dim.n = n; output_dim.c = c; diff --git a/src/Yolo.cpp b/src/Yolo.cpp index ca6ebc5..634f5ff 100644 --- a/src/Yolo.cpp +++ b/src/Yolo.cpp @@ -24,8 +24,8 @@ Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_ readBinaryFile(fname_weights, n_masks, &mask_h, &mask_d, seek); seek += n_masks; readBinaryFile(fname_weights, n_masks*num*2, &bias_h, &bias_d, seek); - for(int i=0; i