updates
This commit is contained in:
parent
e92a8afae1
commit
7d43ee0d02
11
train.py
11
train.py
|
@ -319,7 +319,7 @@ def train(cfg,
|
||||||
def print_mutation(hyp, results):
|
def print_mutation(hyp, results):
|
||||||
# Write mutation results
|
# Write mutation results
|
||||||
a = '%11s' * len(hyp) % tuple(hyp.keys()) # hyperparam keys
|
a = '%11s' * len(hyp) % tuple(hyp.keys()) # hyperparam keys
|
||||||
b = '%11.4g' * len(hyp) % tuple(hyp.values()) # hyperparam values
|
b = '%11.3g' * len(hyp) % tuple(hyp.values()) # hyperparam values
|
||||||
c = '%11.3g' * len(results) % results # results (P, R, mAP, F1, test_loss)
|
c = '%11.3g' * len(results) % results # results (P, R, mAP, F1, test_loss)
|
||||||
print('\n%s\n%s\nEvolved fitness: %s\n' % (a, b, c))
|
print('\n%s\n%s\nEvolved fitness: %s\n' % (a, b, c))
|
||||||
|
|
||||||
|
@ -327,12 +327,18 @@ def print_mutation(hyp, results):
|
||||||
os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt
|
os.system('gsutil cp gs://%s/evolve.txt .' % opt.bucket) # download evolve.txt
|
||||||
with open('evolve.txt', 'a') as f: # append result
|
with open('evolve.txt', 'a') as f: # append result
|
||||||
f.write(c + b + '\n')
|
f.write(c + b + '\n')
|
||||||
|
x = np.loadtxt('evolve.txt', ndmin=2)
|
||||||
|
np.savetxt('evolve.txt', x[np.argsort(-fitness(x))], '%11.3g') # save sorted by fitness
|
||||||
os.system('gsutil cp evolve.txt gs://%s' % opt.bucket) # upload evolve.txt
|
os.system('gsutil cp evolve.txt gs://%s' % opt.bucket) # upload evolve.txt
|
||||||
else:
|
else:
|
||||||
with open('evolve.txt', 'a') as f:
|
with open('evolve.txt', 'a') as f:
|
||||||
f.write(c + b + '\n')
|
f.write(c + b + '\n')
|
||||||
|
|
||||||
|
|
||||||
|
def fitness(x): # returns fitness of hyp evolution vectors
|
||||||
|
return x[:, 2] * 0.5 + x[:, 3] * 0.5 # fitness = weighted combination of mAP and F1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--epochs', type=int, default=100, help='number of epochs')
|
parser.add_argument('--epochs', type=int, default=100, help='number of epochs')
|
||||||
|
@ -373,8 +379,7 @@ if __name__ == '__main__':
|
||||||
for _ in range(1000): # generations to evolve
|
for _ in range(1000): # generations to evolve
|
||||||
# Get best hyperparameters
|
# Get best hyperparameters
|
||||||
x = np.loadtxt('evolve.txt', ndmin=2)
|
x = np.loadtxt('evolve.txt', ndmin=2)
|
||||||
fitness = x[:, 2] * 0.5 + x[:, 3] * 0.5 # fitness as weighted combination of mAP and F1
|
x = x[fitness(x).argmax()] # select best fitness hyps
|
||||||
x = x[fitness.argmax()] # select best fitness hyps
|
|
||||||
for i, k in enumerate(hyp.keys()):
|
for i, k in enumerate(hyp.keys()):
|
||||||
hyp[k] = x[i + 5]
|
hyp[k] = x[i + 5]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue