From d857d4d58cfed4ac3976117b280c141f3eea5588 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 17 May 2021 17:58:02 +0200 Subject: [PATCH 1/6] Added max_det parameters in various places --- detect.py | 3 ++- models/common.py | 6 ++++-- utils/general.py | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/detect.py b/detect.py index 0001f93704bf..28b6ed05b5f2 100644 --- a/detect.py +++ b/detect.py @@ -68,7 +68,7 @@ def detect(opt): pred = model(img, augment=opt.augment)[0] # Apply NMS - pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms) + pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms, max_det=opt.max_det) t2 = time_synchronized() # Apply Classifier @@ -153,6 +153,7 @@ def detect(opt): parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)') parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold') parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS') + parser.add_argument('--max-det', type=int, default=300, help='maximum number of detections per image') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser.add_argument('--view-img', action='store_true', help='display results') parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') diff --git a/models/common.py b/models/common.py index 689aa0f3ed7c..27b76b0dbeee 100644 --- a/models/common.py +++ b/models/common.py @@ -215,12 +215,13 @@ class NMS(nn.Module): conf = 0.25 # confidence threshold iou = 0.45 # IoU threshold classes = None # (optional list) filter by class + max_det = 300 # maximum number of detections per image def __init__(self): super(NMS, self).__init__() def forward(self, x): - return non_max_suppression(x[0], conf_thres=self.conf, iou_thres=self.iou, classes=self.classes) + return non_max_suppression(x[0], conf_thres=self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) class AutoShape(nn.Module): @@ -228,6 +229,7 @@ class AutoShape(nn.Module): conf = 0.25 # NMS confidence threshold iou = 0.45 # NMS IoU threshold classes = None # (optional list) filter by class + max_det = 300 # maximum number of detections per image def __init__(self, model): super(AutoShape, self).__init__() @@ -285,7 +287,7 @@ def forward(self, imgs, size=640, augment=False, profile=False): t.append(time_synchronized()) # Post-process - y = non_max_suppression(y, conf_thres=self.conf, iou_thres=self.iou, classes=self.classes) # NMS + y = non_max_suppression(y, conf_thres=self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) # NMS for i in range(n): scale_coords(shape1, y[i][:, :4], shape0[i]) diff --git a/utils/general.py b/utils/general.py index a4c745d1dcaf..4b3d4ab3b189 100755 --- a/utils/general.py +++ b/utils/general.py @@ -482,7 +482,7 @@ def wh_iou(wh1, wh2): def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=None, agnostic=False, multi_label=False, - labels=()): + labels=(), max_det=300): """Runs Non-Maximum Suppression (NMS) on inference results Returns: @@ -498,7 +498,6 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non # Settings min_wh, max_wh = 2, 4096 # (pixels) minimum and maximum box width and height - max_det = 300 # maximum number of detections per image max_nms = 30000 # maximum number of boxes into torchvision.ops.nms() time_limit = 10.0 # seconds to quit after redundant = True # require redundant detections From a2d21c936bbf1ac977b863a71692e865def9bb3e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 May 2021 22:33:53 +0200 Subject: [PATCH 2/6] 120 character line --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index 27b76b0dbeee..f3c98ac417c2 100644 --- a/models/common.py +++ b/models/common.py @@ -287,7 +287,7 @@ def forward(self, imgs, size=640, augment=False, profile=False): t.append(time_synchronized()) # Post-process - y = non_max_suppression(y, conf_thres=self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) # NMS + y = non_max_suppression(y, self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) # NMS for i in range(n): scale_coords(shape1, y[i][:, :4], shape0[i]) From 68564b9892f1820e609c63000ed09a8711c9c8d1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 May 2021 22:35:22 +0200 Subject: [PATCH 3/6] PEP8 --- models/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/common.py b/models/common.py index f3c98ac417c2..838764411417 100644 --- a/models/common.py +++ b/models/common.py @@ -215,13 +215,13 @@ class NMS(nn.Module): conf = 0.25 # confidence threshold iou = 0.45 # IoU threshold classes = None # (optional list) filter by class - max_det = 300 # maximum number of detections per image + max_det = 300 # maximum number of detections per image def __init__(self): super(NMS, self).__init__() def forward(self, x): - return non_max_suppression(x[0], conf_thres=self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) + return non_max_suppression(x[0], self.conf, iou_thres=self.iou, classes=self.classes, max_det=self.max_det) class AutoShape(nn.Module): @@ -229,7 +229,7 @@ class AutoShape(nn.Module): conf = 0.25 # NMS confidence threshold iou = 0.45 # NMS IoU threshold classes = None # (optional list) filter by class - max_det = 300 # maximum number of detections per image + max_det = 300 # maximum number of detections per image def __init__(self, model): super(AutoShape, self).__init__() From b03e907790880a25922158fcff1baea512cbd496 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 May 2021 22:38:36 +0200 Subject: [PATCH 4/6] 120 character line --- detect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/detect.py b/detect.py index 28b6ed05b5f2..a7015b7a24be 100644 --- a/detect.py +++ b/detect.py @@ -68,7 +68,8 @@ def detect(opt): pred = model(img, augment=opt.augment)[0] # Apply NMS - pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms, max_det=opt.max_det) + pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, opt.classes, opt.agnostic_nms, + max_det=opt.max_det) t2 = time_synchronized() # Apply Classifier From fe77b976e0e02161a9bb90afbf88fa39c389c16b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 May 2021 22:41:43 +0200 Subject: [PATCH 5/6] Update inference default to 1000 instances --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index a7015b7a24be..732fec698006 100644 --- a/detect.py +++ b/detect.py @@ -154,7 +154,7 @@ def detect(opt): parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)') parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold') parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS') - parser.add_argument('--max-det', type=int, default=300, help='maximum number of detections per image') + parser.add_argument('--max-det', type=int, default=1000, help='maximum number of detections per image') parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser.add_argument('--view-img', action='store_true', help='display results') parser.add_argument('--save-txt', action='store_true', help='save results to *.txt') From ab4f824a68c5d3354391f609abadc78f1ab7c2aa Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 17 May 2021 22:42:28 +0200 Subject: [PATCH 6/6] Update inference default to 1000 instances --- models/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/common.py b/models/common.py index 838764411417..4211db406c3d 100644 --- a/models/common.py +++ b/models/common.py @@ -215,7 +215,7 @@ class NMS(nn.Module): conf = 0.25 # confidence threshold iou = 0.45 # IoU threshold classes = None # (optional list) filter by class - max_det = 300 # maximum number of detections per image + max_det = 1000 # maximum number of detections per image def __init__(self): super(NMS, self).__init__() @@ -229,7 +229,7 @@ class AutoShape(nn.Module): conf = 0.25 # NMS confidence threshold iou = 0.45 # NMS IoU threshold classes = None # (optional list) filter by class - max_det = 300 # maximum number of detections per image + max_det = 1000 # maximum number of detections per image def __init__(self, model): super(AutoShape, self).__init__()