From e9e7adbcd1223dd174e9a8c3fbf64ec203a48d44 Mon Sep 17 00:00:00 2001 From: lindsayshuo Date: Thu, 2 May 2024 16:47:27 +0800 Subject: [PATCH 1/4] Add the generation of multi-class pose engines --- yolov8/src/model.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/yolov8/src/model.cpp b/yolov8/src/model.cpp index cd2f8872..9901ab32 100644 --- a/yolov8/src/model.cpp +++ b/yolov8/src/model.cpp @@ -68,15 +68,9 @@ static nvinfer1::IShuffleLayer* cv4_conv_combined(nvinfer1::INetworkDefinition* output_channel = 32; } else if (algo_type == "pose") { - if (gw == 0.25 || gw == 0.5 || gw == 0.75) { - mid_channle = 51; - } else if (gw == 1.00) { - mid_channle = 64; - } else if (gw == 1.25) { - mid_channle = 80; - } - - output_channel = 51; + std::string bn_weight_key = lname + ".0.bn.weight"; + mid_channle = weightMap[bn_weight_key].count; + output_channel = kNumberOfPoints * 3; } auto cv0 = convBnSiLU(network, weightMap, input, mid_channle, 3, 1, 1, lname + ".0"); From 9be6384fb83eb7cb509b2cb225739490ebeba386 Mon Sep 17 00:00:00 2001 From: lindsayshuo Date: Tue, 14 May 2024 08:31:41 +0800 Subject: [PATCH 2/4] Change grids in forwardGpu to one-dimensional arrays --- yolov8/plugin/yololayer.cu | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) mode change 100755 => 100644 yolov8/plugin/yololayer.cu diff --git a/yolov8/plugin/yololayer.cu b/yolov8/plugin/yololayer.cu old mode 100755 new mode 100644 index 592914fa..c42b841c --- a/yolov8/plugin/yololayer.cu +++ b/yolov8/plugin/yololayer.cu @@ -258,25 +258,38 @@ void YoloLayerPlugin::forwardGpu(const float* const* inputs, float* output, cuda } int numElem = 0; - const int maxGrids = mStridesLength; - int grids[maxGrids][2]; + // const int maxGrids = mStridesLength; + // int grids[maxGrids][2]; + // for (int i = 0; i < maxGrids; ++i) { + // grids[i][0] = mYoloV8netHeight / mStrides[i]; + // grids[i][1] = mYoloV8NetWidth / mStrides[i]; + // } + + int maxGrids = mStridesLength; + int flatGridsLen = 2 * maxGrids; + int* flatGrids = new int[flatGridsLen]; + for (int i = 0; i < maxGrids; ++i) { - grids[i][0] = mYoloV8netHeight / mStrides[i]; - grids[i][1] = mYoloV8NetWidth / mStrides[i]; + flatGrids[2 * i] = mYoloV8netHeight / mStrides[i]; + flatGrids[2 * i + 1] = mYoloV8NetWidth / mStrides[i]; } for (unsigned int i = 0; i < maxGrids; i++) { - int grid_h = grids[i][0]; - int grid_w = grids[i][1]; + // Access the elements of the original 2D array from the flattened 1D array + int grid_h = flatGrids[2 * i]; // Corresponds to the access of grids[i][0] + int grid_w = flatGrids[2 * i + 1]; // Corresponds to the access of grids[i][1] int stride = mStrides[i]; - numElem = grid_h * grid_w * batchSize; - if (numElem < mThreadCount) + numElem = grid_h * grid_w * batchSize; // Calculate the total number of elements + if (numElem < mThreadCount) // Adjust the thread count if needed mThreadCount = numElem; + // The CUDA kernel call remains unchanged CalDetection<<<(numElem + mThreadCount - 1) / mThreadCount, mThreadCount, 0, stream>>>( inputs[i], output, numElem, mMaxOutObject, grid_h, grid_w, stride, mClassCount, mNumberofpoints, mConfthreshkeypoints, outputElem, is_segmentation_, is_pose_); } + + delete[] flatGrids; } PluginFieldCollection YoloPluginCreator::mFC{}; From 15e2e952c1bbce8d8975466f29b18a1c198e9e11 Mon Sep 17 00:00:00 2001 From: lindsayshuo <932695342@qq.com> Date: Tue, 14 May 2024 13:34:01 +0800 Subject: [PATCH 3/4] Update README.md --- yolov8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolov8/README.md b/yolov8/README.md index 4d4f683b..84868bc5 100644 --- a/yolov8/README.md +++ b/yolov8/README.md @@ -42,7 +42,7 @@ python gen_wts.py -w yolov8n.pt -o yolov8n.wts -t detect // For p2 model -// download https://github.com/lindsayshuo/yolov8-p2/releases/download/VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last.pt (only for 10 cls p2 model) +// download https://github.com/lindsayshuo/yolov8_p2_tensorrtx/releases/download/VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last/VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last.pt (only for 10 cls p2 model) python gen_wts.py -w VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last.pt -o VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last.wts -t detect (only for 10 cls p2 model) // a file 'VisDrone_train_yolov8x_p2_bs1_epochs_100_imgsz_1280_last.wts' will be generated. ``` From 045d739e2286a4909086af151c56a243beb3a498 Mon Sep 17 00:00:00 2001 From: lindsayshuo <932695342@qq.com> Date: Wed, 28 Aug 2024 17:23:53 +0800 Subject: [PATCH 4/4] Update types.h keypoints array with dynamic size based on kNumberOfPoints --- yolov8/include/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolov8/include/types.h b/yolov8/include/types.h index 472c7354..c43f589b 100644 --- a/yolov8/include/types.h +++ b/yolov8/include/types.h @@ -7,7 +7,7 @@ struct alignas(float) Detection { float conf; // bbox_conf * cls_conf float class_id; float mask[32]; - float keypoints[51]; // 17*3 keypoints + float keypoints[kNumberOfPoints * 3]; // keypoints array with dynamic size based on kNumberOfPoints }; struct AffineMatrix {