From 76e3aea3097ee5da1065b3e3e00f55ba65e118ac Mon Sep 17 00:00:00 2001 From: Stephane Chavin <stephane.chavin@lis-lab.fr> Date: Fri, 28 Mar 2025 16:06:53 +0100 Subject: [PATCH] name option improve --- yolov5/detect.py | 10 ++++++---- yolov5/train.py | 7 +++++-- yolov5/val.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/yolov5/detect.py b/yolov5/detect.py index 33b8239..34beba0 100755 --- a/yolov5/detect.py +++ b/yolov5/detect.py @@ -81,7 +81,7 @@ def run( visualize=False, # visualize features update=False, # update all models project=ROOT / 'runs/detect', # save results to project/name - name='exp', # save results to project/name + name=None, # save results to project/name exist_ok=False, # existing project/name ok, do not increment line_thickness=3, # bounding box thickness (pixels) hide_labels=False, # hide labels @@ -98,8 +98,10 @@ def run( screenshot = source.lower().startswith('screen') if is_url and is_file: source = check_file(source) # download - - project_name = input('Please enter the name of your project : ') + if not args.name: + project_name = input('Please enter the name of your project : ') + else: + project_name = args.name date_now = date.today().strftime("%Y%m%d") if sound: @@ -268,7 +270,7 @@ def parse_opt(): parser.add_argument('--visualize', action='store_true', help='visualize features') parser.add_argument('--update', action='store_true', help='update all models') parser.add_argument('--project', default=ROOT / 'runs/detect', help='save results to project/name') - parser.add_argument('--name', default='exp', help='save results to project/name') + parser.add_argument('--name', default=None, help='save results to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--line-thickness', default=3, type=int, help='bounding box thickness (pixels)') parser.add_argument('--hide-labels', default=False, action='store_true', help='hide labels') diff --git a/yolov5/train.py b/yolov5/train.py index 304f95b..e18d4ea 100755 --- a/yolov5/train.py +++ b/yolov5/train.py @@ -459,7 +459,7 @@ def parse_opt(known=False): parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode') parser.add_argument('--workers', type=int, default=8, help='max dataloader workers (per RANK in DDP mode)') parser.add_argument('--project', default=ROOT / 'runs/train', help='save to project/name') - parser.add_argument('--name', default='exp', help='save to project/name') + parser.add_argument('--name', default=None, help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--quad', action='store_true', help='quad dataloader') parser.add_argument('--cos-lr', action='store_true', help='cosine LR scheduler') @@ -512,7 +512,10 @@ def main(opt, callbacks=Callbacks()): opt.exist_ok, opt.resume = opt.resume, False # pass resume to exist_ok and disable resume if opt.name == 'cfg': opt.name = Path(opt.cfg).stem # use model.yaml as name - project_name = input('Please enter the name of your project : ') + if not args.name: + project_name = input('Please enter the name of your project : ') + else: + project_name = args.name date_now = date.today().strftime("%Y%m%d") folder_name = '_'.join([project_name, date_now, opt.weights[-4:-3], str(opt.imgsz), opt.optimizer, opt.rf, opt.duration, 'YOLOV5',]) print(f'Your train results will be saved in {folder_name}') diff --git a/yolov5/val.py b/yolov5/val.py index 88e7454..7f9e9a0 100755 --- a/yolov5/val.py +++ b/yolov5/val.py @@ -359,7 +359,7 @@ def parse_opt(): parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels') parser.add_argument('--save-json', action='store_true', help='save a COCO-JSON results file') parser.add_argument('--project', default=ROOT / 'runs/val', help='save to project/name') - parser.add_argument('--name', default='exp', help='save to project/name') + parser.add_argument('--name', default=None, help='save to project/name') parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment') parser.add_argument('--half', action='store_true', help='use FP16 half-precision inference') parser.add_argument('--dnn', action='store_true', help='use OpenCV DNN for ONNX inference') -- GitLab