From 6a3e74c151edcf10374d14243018e63a37e5acb9 Mon Sep 17 00:00:00 2001 From: John San Soucie Date: Fri, 2 Jul 2021 12:02:10 -0400 Subject: [PATCH 1/5] evolve command accepts argument for number of generations --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 386f3d90dd73..a724d5ca878f 100644 --- a/train.py +++ b/train.py @@ -494,7 +494,7 @@ def parse_opt(known=False): parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') parser.add_argument('--notest', action='store_true', help='only test final epoch') parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') - parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters') + parser.add_argument('--evolve', type=int, required=False, help='evolve hyperparameters for this many generations') parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') From 9e7d5d3cd592d6f27ded8681b85fb34fba79f149 Mon Sep 17 00:00:00 2001 From: John San Soucie Date: Fri, 2 Jul 2021 12:05:17 -0400 Subject: [PATCH 2/5] evolve generations argument used in evolve for loop --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index a724d5ca878f..02ba35b9373d 100644 --- a/train.py +++ b/train.py @@ -603,7 +603,7 @@ def main(opt): if opt.bucket: os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt if exists - for _ in range(300): # generations to evolve + for _ in range(opt.evolve): # generations to evolve if Path('evolve.txt').exists(): # if evolve.txt exists: select best hyps and mutate # Select parent(s) parent = 'single' # parent selection method: 'single' or 'weighted' From 98ade071b0d28d5195d966aed542ea8dfbcbaf4b Mon Sep 17 00:00:00 2001 From: John San Soucie Date: Fri, 2 Jul 2021 14:17:16 -0400 Subject: [PATCH 3/5] evolve argument boolean fixes --- train.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/train.py b/train.py index 02ba35b9373d..56ecafbb0ce5 100644 --- a/train.py +++ b/train.py @@ -60,6 +60,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary save_dir, epochs, batch_size, weights, single_cls, evolve, data, cfg, resume, notest, nosave, workers, = \ opt.save_dir, opt.epochs, opt.batch_size, opt.weights, opt.single_cls, opt.evolve, opt.data, opt.cfg, \ opt.resume, opt.notest, opt.nosave, opt.workers + evolve = evolve is not None # Directories save_dir = Path(save_dir) @@ -542,7 +543,7 @@ def main(opt): assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified' opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test) opt.name = 'evolve' if opt.evolve else opt.name - opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | opt.evolve)) + opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | (opt.evolve is None))) # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) @@ -556,7 +557,7 @@ def main(opt): assert not opt.image_weights, '--image-weights argument is not compatible with DDP training' # Train - if not opt.evolve: + if opt.evolve is None: train(opt.hyp, opt, device) if WORLD_SIZE > 1 and RANK == 0: _ = [print('Destroying process group... ', end=''), dist.destroy_process_group(), print('Done.')] From 56efa6673307a5366ba3766bc7cc0df7baf327da Mon Sep 17 00:00:00 2001 From: san-soucie <44901782+san-soucie@users.noreply.github.com> Date: Sat, 3 Jul 2021 14:22:56 -0400 Subject: [PATCH 4/5] default to 300 evolve generations --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index 56ecafbb0ce5..6c72e173cc1f 100644 --- a/train.py +++ b/train.py @@ -495,7 +495,7 @@ def parse_opt(known=False): parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') parser.add_argument('--notest', action='store_true', help='only test final epoch') parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') - parser.add_argument('--evolve', type=int, required=False, help='evolve hyperparameters for this many generations') + parser.add_argument('--evolve', nargs='?', const=300, help='evolve hyperparameters for this many generations') parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') From 3c8a665ce15fdbe15c85f7aceb831fe50156cad1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 4 Jul 2021 12:11:04 +0200 Subject: [PATCH 5/5] Update train.py --- train.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index 6c72e173cc1f..2e864a60cefc 100644 --- a/train.py +++ b/train.py @@ -60,7 +60,6 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary save_dir, epochs, batch_size, weights, single_cls, evolve, data, cfg, resume, notest, nosave, workers, = \ opt.save_dir, opt.epochs, opt.batch_size, opt.weights, opt.single_cls, opt.evolve, opt.data, opt.cfg, \ opt.resume, opt.notest, opt.nosave, opt.workers - evolve = evolve is not None # Directories save_dir = Path(save_dir) @@ -495,7 +494,7 @@ def parse_opt(known=False): parser.add_argument('--nosave', action='store_true', help='only save final checkpoint') parser.add_argument('--notest', action='store_true', help='only test final epoch') parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check') - parser.add_argument('--evolve', nargs='?', const=300, help='evolve hyperparameters for this many generations') + parser.add_argument('--evolve', type=int, nargs='?', const=300, help='evolve hyperparameters for x generations') parser.add_argument('--bucket', type=str, default='', help='gsutil bucket') parser.add_argument('--cache-images', action='store_true', help='cache images for faster training') parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training') @@ -543,7 +542,7 @@ def main(opt): assert len(opt.cfg) or len(opt.weights), 'either --cfg or --weights must be specified' opt.img_size.extend([opt.img_size[-1]] * (2 - len(opt.img_size))) # extend to 2 sizes (train, test) opt.name = 'evolve' if opt.evolve else opt.name - opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok | (opt.evolve is None))) + opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok or opt.evolve)) # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) @@ -557,7 +556,7 @@ def main(opt): assert not opt.image_weights, '--image-weights argument is not compatible with DDP training' # Train - if opt.evolve is None: + if not opt.evolve: train(opt.hyp, opt, device) if WORLD_SIZE > 1 and RANK == 0: _ = [print('Destroying process group... ', end=''), dist.destroy_process_group(), print('Done.')]