From 90fc7fdc6652beee28fd24ffd03700a3c43a50ec Mon Sep 17 00:00:00 2001 From: wang-xinyu Date: Wed, 20 Mar 2024 11:31:18 +0800 Subject: [PATCH 1/2] fix code style --- yolov9/include/block.h | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/yolov9/include/block.h b/yolov9/include/block.h index 9369fa9a..3b02d4bc 100644 --- a/yolov9/include/block.h +++ b/yolov9/include/block.h @@ -1,12 +1,12 @@ #include "config.h" #include "yololayer.h" -#include -#include -#include #include #include #include +#include +#include +#include using namespace nvinfer1; @@ -15,17 +15,30 @@ using namespace nvinfer1; void PrintDim(const ILayer* layer, std::string log = ""); std::map loadWeights(const std::string file); int get_width(int x, float gw, int divisor = 8); -int get_depth(int x, float gd) ; -ILayer* Proto(INetworkDefinition* network, std::map& weightMap, ITensor& input, int c_, int c2, std::string lname); +int get_depth(int x, float gd); +ILayer* Proto(INetworkDefinition* network, std::map& weightMap, ITensor& input, int c_, int c2, + std::string lname); std::vector> getAnchors(std::map& weightMap, std::string lname); // ---------------------------------------------------------------- -nvinfer1::ILayer* convBnSiLU(nvinfer1::INetworkDefinition* network, std::map& weightMap, nvinfer1::ITensor& input, int ch, int k, int s, int p, std::string lname, int g=1); -ILayer* RepNCSPELAN4(INetworkDefinition *network, std::map& weightMap, ITensor& input, int c1, int c2, int c3, int c4, int c5, std::string lname); -ILayer* ADown(INetworkDefinition *network, std::map& weightMap, ITensor& input, int c2, std::string lname); -std::vector CBLinear(INetworkDefinition *network, std::map& weightMap, ITensor& input, std::vector c2s, int k, int s, int p, int g, std::string lname); -ILayer* CBFuse(INetworkDefinition *network, std::vector> input, std::vector idx, std::vector strides); -ILayer* SPPELAN(INetworkDefinition *network, std::map& weightMap, ITensor& input, int c1, int c2, int c3, std::string lname); -std::vector DualDDetect(INetworkDefinition *network, std::map& weightMap, std::vector dets, int cls, std::vector ch, std::string lname); -nvinfer1::IPluginV2Layer* addYoLoLayer(nvinfer1::INetworkDefinition *network, std::vector dets, bool is_segmentation); -nvinfer1::IShuffleLayer* DFL(nvinfer1::INetworkDefinition* network, std::map weightMap, nvinfer1::ITensor& input, int ch, int k, int s, int p, std::string lname); -nvinfer1::ILayer* convBnNoAct(nvinfer1::INetworkDefinition* network, std::map& weightMap, nvinfer1::ITensor& input, int ch, int k, int s, int p, std::string lname, int g); +nvinfer1::ILayer* convBnSiLU(nvinfer1::INetworkDefinition* network, std::map& weightMap, + nvinfer1::ITensor& input, int ch, int k, int s, int p, std::string lname, int g = 1); +ILayer* RepNCSPELAN4(INetworkDefinition* network, std::map& weightMap, ITensor& input, int c1, + int c2, int c3, int c4, int c5, std::string lname); +ILayer* ADown(INetworkDefinition* network, std::map& weightMap, ITensor& input, int c2, + std::string lname); +std::vector CBLinear(INetworkDefinition* network, std::map& weightMap, ITensor& input, + std::vector c2s, int k, int s, int p, int g, std::string lname); +ILayer* CBFuse(INetworkDefinition* network, std::vector> input, std::vector idx, + std::vector strides); +ILayer* SPPELAN(INetworkDefinition* network, std::map& weightMap, ITensor& input, int c1, int c2, + int c3, std::string lname); +std::vector DualDDetect(INetworkDefinition* network, std::map& weightMap, + std::vector dets, int cls, std::vector ch, + std::string lname); +nvinfer1::IPluginV2Layer* addYoLoLayer(nvinfer1::INetworkDefinition* network, + std::vector dets, bool is_segmentation); +nvinfer1::IShuffleLayer* DFL(nvinfer1::INetworkDefinition* network, std::map weightMap, + nvinfer1::ITensor& input, int ch, int k, int s, int p, std::string lname); +nvinfer1::ILayer* convBnNoAct(nvinfer1::INetworkDefinition* network, + std::map& weightMap, nvinfer1::ITensor& input, int ch, + int k, int s, int p, std::string lname, int g); From 630a84711e4133f56fabf8541e886ed862fba025 Mon Sep 17 00:00:00 2001 From: wang-xinyu Date: Wed, 27 Mar 2024 13:15:29 +0800 Subject: [PATCH 2/2] add python flake8 check --- .pre-commit-config.yaml | 15 ++++++++++----- yolov9/yolov9_trt.py | 12 ++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 437541d7..88888037 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,8 +7,13 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: check-added-large-files -- repo: https://github.com/pre-commit/mirrors-clang-format - rev: v14.0.6 - hooks: - - id: clang-format - types_or: [c++, c, cuda] +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v14.0.6 + hooks: + - id: clang-format + types_or: [c++, c, cuda] +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + args: [--max-line-length=120] diff --git a/yolov9/yolov9_trt.py b/yolov9/yolov9_trt.py index 15a7737a..fe9d1df8 100644 --- a/yolov9/yolov9_trt.py +++ b/yolov9/yolov9_trt.py @@ -10,7 +10,7 @@ import time import cv2 import numpy as np -import pycuda.autoinit +import pycuda.autoinit # noqa: F401 import pycuda.driver as cuda import tensorrt as trt @@ -36,7 +36,7 @@ def plot_one_box(x, img, color=None, label=None, line_thickness=None): """ description: Plots one bounding box on image img, this function comes from yolov9 project. - param: + param: x: a box likes [x1,y1,x2,y2] img: a opencv image object color: color to draw rectangle, such as (0,255,0) @@ -129,7 +129,6 @@ def infer(self, raw_image_generator): # Restore stream = self.stream context = self.context - engine = self.engine host_inputs = self.host_inputs cuda_inputs = self.cuda_inputs host_outputs = self.host_outputs @@ -274,11 +273,12 @@ def xywh2xyxy(self, origin_h, origin_w, x): y /= r_h return y + def post_process(self, output, origin_h, origin_w): """ description: postprocess the prediction param: - output: A numpy likes [num_boxes,cx,cy,w,h,conf,cls_id, cx,cy,w,h,conf,cls_id, ...] + output: A numpy likes [num_boxes,cx,cy,w,h,conf,cls_id, cx,cy,w,h,conf,cls_id, ...] origin_h: height of original image origin_w: width of original image return: @@ -302,7 +302,7 @@ def bbox_iou(self, box1, box2, x1y1x2y2=True): description: compute the IoU of two bounding boxes param: box1: A box coordinate (can be (x1, y1, x2, y2) or (x, y, w, h)) - box2: A box coordinate (can be (x1, y1, x2, y2) or (x, y, w, h)) + box2: A box coordinate (can be (x1, y1, x2, y2) or (x, y, w, h)) x1y1x2y2: select the coordinate format return: iou: computed iou @@ -325,7 +325,7 @@ def bbox_iou(self, box1, box2, x1y1x2y2=True): inter_rect_y2 = np.minimum(b1_y2, b2_y2) # Intersection area inter_area = np.clip(inter_rect_x2 - inter_rect_x1 + 1, 0, None) * \ - np.clip(inter_rect_y2 - inter_rect_y1 + 1, 0, None) + np.clip(inter_rect_y2 - inter_rect_y1 + 1, 0, None) # Union Area b1_area = (b1_x2 - b1_x1 + 1) * (b1_y2 - b1_y1 + 1) b2_area = (b2_x2 - b2_x1 + 1) * (b2_y2 - b2_y1 + 1)