This commit is contained in:
Glenn Jocher 2019-04-18 15:17:31 +02:00
parent b177d01695
commit 48f6529fd1
1 changed files with 13 additions and 10 deletions

View File

@ -243,6 +243,17 @@ def train(
return results return results
def print_mutation(hyp, results):
# Write mutation results
sl = '%11s' * len(hyp) % tuple(hyp.keys()) # hyperparam keys
sr = '%11.3g' * len(results) % results # results (P, R, mAP, F1, test_loss)
sh = '%11.4g' * len(hyp) % tuple(hyp.values()) # hyperparam values
print('\n%s\n%s\nEvolved fitness: %s\n' % (sl, sh, sr))
with open('evolve.txt', 'a') as f:
f.write(sr + sh + '\n')
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--epochs', type=int, default=273, help='number of epochs') parser.add_argument('--epochs', type=int, default=273, help='number of epochs')
@ -289,11 +300,7 @@ if __name__ == '__main__':
best_fitness = results[2] # use mAP for fitness best_fitness = results[2] # use mAP for fitness
# Write mutation results # Write mutation results
sr = '%11.3g' * 5 % results # results string (P, R, mAP, F1, test_loss) print_mutation(hyp, results)
sh = '%11.4g' * len(hyp) % tuple(hyp.values()) # hyp string
print('Evolved hyperparams: %s\nEvolved fitness: %s' % (sh, sr))
with open('evolve.txt', 'a') as f:
f.write(sr + sh + '\n')
gen = 30 # generations to evolve gen = 30 # generations to evolve
for _ in range(gen): for _ in range(gen):
@ -333,11 +340,7 @@ if __name__ == '__main__':
mutation_fitness = results[2] mutation_fitness = results[2]
# Write mutation results # Write mutation results
sr = '%11.3g' * 5 % results # results string (P, R, mAP, F1, test_loss) print_mutation(hyp, results)
sh = '%11.4g' * len(hyp) % tuple(hyp.values()) # hyp string
print('Evolved hyperparams: %s\nEvolved fitness: %s' % (sh, sr))
with open('evolve.txt', 'a') as f:
f.write(sr + sh + '\n')
# Update hyperparameters if fitness improved # Update hyperparameters if fitness improved
if mutation_fitness > best_fitness: if mutation_fitness > best_fitness: