Skip to content

Commit f7d224f

Browse files
authored
Add the coordinate clipping op before nms (wang-xinyu#704)
* add the coordinate clipping op before nms * modified the pytorch related codes * modified the pytorch related codes
1 parent 0e25408 commit f7d224f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

yolov5/yolov5_trt.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ def non_max_suppression(self, prediction, origin_h, origin_w, conf_thres=0.5, nm
351351
boxes = prediction[prediction[:, 4] >= conf_thres]
352352
# Trandform bbox from [center_x, center_y, w, h] to [x1, y1, x2, y2]
353353
boxes[:, :4] = self.xywh2xyxy(origin_h, origin_w, boxes[:, :4])
354+
# clip the coordinates
355+
boxes[:, 0] = np.clip(boxes[:, 0], 0, origin_w -1)
356+
boxes[:, 2] = np.clip(boxes[:, 2], 0, origin_w -1)
357+
boxes[:, 1] = np.clip(boxes[:, 1], 0, origin_h -1)
358+
boxes[:, 3] = np.clip(boxes[:, 3], 0, origin_h -1)
354359
# Object confidence
355360
confs = boxes[:, 4]
356361
# Sort by the confs

0 commit comments

Comments
 (0)