From 1bff0142e51856d24380715671dfbfccc779950f Mon Sep 17 00:00:00 2001 From: GarbageHaus <90212322+GarbageHaus@users.noreply.github.com> Date: Sun, 12 May 2024 18:48:41 -0400 Subject: [PATCH 1/2] added cmd line arg for saving only positives Added a simple command line argument (default False) where if set to true, only the images and videos which contain a positive identification are saved to the output. Location in code is not extremely efficient, but is present at that location for readability and minimal intrusiveness. Signed-off-by: GarbageHaus <90212322+GarbageHaus@users.noreply.github.com> --- detect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/detect.py b/detect.py index c58aa80a68fc..94766d41715a 100644 --- a/detect.py +++ b/detect.py @@ -82,6 +82,7 @@ def run( save_conf=False, # save confidences in --save-txt labels save_crop=False, # save cropped prediction boxes nosave=False, # do not save images/videos + savepositives=False, # save only positive detections classes=None, # filter by class: --class 0, or --class 0 2 3 agnostic_nms=False, # class-agnostic NMS augment=False, # augmented inference @@ -233,7 +234,7 @@ def write_to_csv(image_name, prediction, confidence): cv2.waitKey(1) # 1 millisecond # Save results (image with detections) - if save_img: + if save_img and ( (savepositives and len(det) ) or not savepositives ): if dataset.mode == "image": cv2.imwrite(save_path, im0) else: # 'video' or 'stream' @@ -281,6 +282,7 @@ def parse_opt(): parser.add_argument("--save-conf", action="store_true", help="save confidences in --save-txt labels") parser.add_argument("--save-crop", action="store_true", help="save cropped prediction boxes") parser.add_argument("--nosave", action="store_true", help="do not save images/videos") + parser.add_argument("--savepositives", action="store_true", help="save files only with a positive detection") parser.add_argument("--classes", nargs="+", type=int, help="filter by class: --classes 0, or --classes 0 2 3") parser.add_argument("--agnostic-nms", action="store_true", help="class-agnostic NMS") parser.add_argument("--augment", action="store_true", help="augmented inference") From 5b77e7eee2df76ce0c75164c1eed8153c9289251 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Sun, 12 May 2024 23:03:52 +0000 Subject: [PATCH 2/2] Auto-format by https://ultralytics.com/actions --- detect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index 94766d41715a..fca73267a4b0 100644 --- a/detect.py +++ b/detect.py @@ -82,7 +82,7 @@ def run( save_conf=False, # save confidences in --save-txt labels save_crop=False, # save cropped prediction boxes nosave=False, # do not save images/videos - savepositives=False, # save only positive detections + savepositives=False, # save only positive detections classes=None, # filter by class: --class 0, or --class 0 2 3 agnostic_nms=False, # class-agnostic NMS augment=False, # augmented inference @@ -234,7 +234,7 @@ def write_to_csv(image_name, prediction, confidence): cv2.waitKey(1) # 1 millisecond # Save results (image with detections) - if save_img and ( (savepositives and len(det) ) or not savepositives ): + if save_img and ((savepositives and len(det)) or not savepositives): if dataset.mode == "image": cv2.imwrite(save_path, im0) else: # 'video' or 'stream'