san-soucie sansoucie glenn-jocher commited on
Commit
d3e9d69
1 Parent(s): 831773f

`--evolve 300` generations CLI argument (#3863)

Browse files

* evolve command accepts argument for number of generations

* evolve generations argument used in evolve for loop

* evolve argument boolean fixes

* default to 300 evolve generations

* Update train.py

Co-authored-by: John San Soucie <jsansoucie@whoi.edu>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>

Files changed (1) hide show
  1. train.py +3 -3
train.py CHANGED
@@ -494,7 +494,7 @@ def parse_opt(known=False):
494
  parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
495
  parser.add_argument('--notest', action='store_true', help='only test final epoch')
496
  parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check')
497
- parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters')
498
  parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
499
  parser.add_argument('--cache-images', action='store_true', help='cache images for faster training')
500
  parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
@@ -542,7 +542,7 @@ def main(opt):
542
  assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified'
543
  opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test)
544
  opt.name = 'evolve' if opt.evolve else opt.name
545
- opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | opt.evolve))
546
 
547
  # DDP mode
548
  device = select_device(opt.device, batch_size=opt.batch_size)
@@ -603,7 +603,7 @@ def main(opt):
603
  if opt.bucket:
604
  os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists
605
 
606
- for _ in range(300): # generations to evolve
607
  if Path('evolve.txt').exists(): # if evolve.txt exists: select best hyps and mutate
608
  # Select parent(s)
609
  parent = 'single' # parent selection method: 'single' or 'weighted'
 
494
  parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
495
  parser.add_argument('--notest', action='store_true', help='only test final epoch')
496
  parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check')
497
+ parser.add_argument('--evolve', type=int, nargs='?', const=300, help='evolve hyperparameters for x generations')
498
  parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
499
  parser.add_argument('--cache-images', action='store_true', help='cache images for faster training')
500
  parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
 
542
  assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified'
543
  opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test)
544
  opt.name = 'evolve' if opt.evolve else opt.name
545
+ opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok or opt.evolve))
546
 
547
  # DDP mode
548
  device = select_device(opt.device, batch_size=opt.batch_size)
 
603
  if opt.bucket:
604
  os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists
605
 
606
+ for _ in range(opt.evolve): # generations to evolve
607
  if Path('evolve.txt').exists(): # if evolve.txt exists: select best hyps and mutate
608
  # Select parent(s)
609
  parent = 'single' # parent selection method: 'single' or 'weighted'