From 2151aab63f0b7661f75f0b2dda532d23068fc33e Mon Sep 17 00:00:00 2001 From: enazoe Date: Mon, 31 Aug 2020 13:27:06 +0800 Subject: [PATCH] yolov5-2.0 --- configs/yolov5-3.0/yolov5s.cfg | 4 ++-- modules/hardswish.cu | 9 +++++++-- modules/trt_utils.h | 4 ++-- samples/sample_detector.cpp | 9 ++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/configs/yolov5-3.0/yolov5s.cfg b/configs/yolov5-3.0/yolov5s.cfg index 999635a..bd47f57 100644 --- a/configs/yolov5-3.0/yolov5s.cfg +++ b/configs/yolov5-3.0/yolov5s.cfg @@ -1,7 +1,7 @@ [net] -width=672 -height=672 +width=320 +height=320 channels=3 nc=80 depth_multiple=0.33 diff --git a/modules/hardswish.cu b/modules/hardswish.cu index 088942f..fe5dc31 100644 --- a/modules/hardswish.cu +++ b/modules/hardswish.cu @@ -27,6 +27,7 @@ namespace nvinfer1 cudaDeviceProp prop; cudaGetDeviceProperties(&prop, 0); _n_max_thread_pre_block = prop.maxThreadsPerBlock; + // printf("Hardswish():%d\n", _n_max_thread_pre_block); } Hardswish::Hardswish(const void* data, size_t length) @@ -34,6 +35,7 @@ namespace nvinfer1 const char *d = reinterpret_cast(data), *a = d; r(d, _n_max_thread_pre_block); r(d, _n_output_size); +// printf("r:threads:%d,size:%d\n", _n_max_thread_pre_block, _n_output_size); assert(d == a + length); } @@ -66,6 +68,7 @@ namespace nvinfer1 cudaStream_t stream_) { int n_data_size = n_batch_size_ * n_output_size_; +// printf("cuda_hardswish_layer:%d,size:%d\n", n_batch_size_, n_output_size_); kernel_hardswish << <(n_data_size + threads_ -1)/threads_, threads_ >> >( reinterpret_cast(input_), reinterpret_cast(output_), @@ -76,7 +79,7 @@ namespace nvinfer1 int Hardswish::enqueue(int batchSize, const void* const* inputs, void** outputs, void* workspace, cudaStream_t stream) { - //printf("batch_size:%d,output_size:%d,threads:%d\n", batchSize, _n_output_size, _n_max_thread_pre_block); +// printf("batch_size:%d,output_size:%d,threads:%d\n", batchSize, _n_output_size, _n_max_thread_pre_block); NV_CUDA_CHECK(cuda_hardswish_layer(inputs[0], outputs[0], batchSize, _n_output_size , _n_max_thread_pre_block,stream)); return 0; } @@ -91,6 +94,7 @@ namespace nvinfer1 char *d = static_cast(buffer), *a = d; w(d, _n_max_thread_pre_block); w(d, _n_output_size); +// printf("serialize:%d,%d\n", _n_max_thread_pre_block, _n_output_size); assert(d == a + getSerializationSize()); } @@ -98,7 +102,7 @@ namespace nvinfer1 { _n_output_size = in->dims.d[0] * in->dims.d[1] * in->dims.d[2]; - // printf("output_size:%d,threads:%d\n", _n_output_size, _n_max_thread_pre_block); +// printf("configurePlugin:%d,%d,%d\n", in->dims.d[0], in->dims.d[1], in->dims.d[2]); } IPluginV2IOExt* Hardswish::clone() const { @@ -106,6 +110,7 @@ namespace nvinfer1 p->setPluginNamespace(_s_plugin_namespace.c_str()); p->_n_max_thread_pre_block = _n_max_thread_pre_block; p->_n_output_size = _n_output_size; +// printf("clone:%d,%d\n", _n_max_thread_pre_block, _n_output_size); return p; } diff --git a/modules/trt_utils.h b/modules/trt_utils.h index 7fd0959..14d22c4 100644 --- a/modules/trt_utils.h +++ b/modules/trt_utils.h @@ -215,11 +215,11 @@ nvinfer1::ILayer * layer_conv_bn_act( const int group_ =1, const bool b_padding_ = true, const bool b_bn_ = true, - const std::string s_act_ = "hardswish"); + const std::string s_act_ = "leaky"); nvinfer1::ILayer * layer_act(nvinfer1::ITensor* input_, nvinfer1::INetworkDefinition* network_, - const std::string s_act_ = "hardswish"); + const std::string s_act_ = "leaky"); nvinfer1::ILayer * layer_bottleneck_csp( std::string s_model_name_, diff --git a/samples/sample_detector.cpp b/samples/sample_detector.cpp index 362937a..3e2f332 100644 --- a/samples/sample_detector.cpp +++ b/samples/sample_detector.cpp @@ -39,11 +39,10 @@ int main() Config config_v5; config_v5.net_type = YOLOV5; config_v5.detect_thresh = 0.5; - config_v5.file_model_cfg = "../configs/yolov5-3.0/yolov5s.cfg"; - config_v5.file_model_weights = "../configs/yolov5-3.0/yolov5s.weights"; - config_v5.calibration_image_list_file_txt = "../configs/calibration_images.txt"; + config_v5.file_model_cfg = "../configs/yolov5-2.0/yolov5s.cfg"; + config_v5.file_model_weights = "../configs/yolov5-2.0/yolov5s.weights"; config_v5.inference_precison = FP32; - config_v5.n_max_batch = 1; + //config_v5.n_max_batch = 2; cv::Mat image0 = cv::imread("../configs/dog.jpg", cv::IMREAD_UNCHANGED); cv::Mat image1 = cv::imread("../configs/person.jpg", cv::IMREAD_UNCHANGED); @@ -58,7 +57,7 @@ int main() cv::Mat temp0 = image0.clone(); cv::Mat temp1 = image1.clone(); batch_img.push_back(temp0); - //batch_img.push_back(temp1); + batch_img.push_back(temp1); //detect timer.reset();