| 1215 | |
| 1216 | |
| 1217 | def plot_evolution(yaml_file='data/hyp.finetune.yaml'): # from utils.general import *; plot_evolution() |
| 1218 | # Plot hyperparameter evolution results in evolve.txt |
| 1219 | with open(yaml_file) as f: |
| 1220 | hyp = yaml.load(f, Loader=yaml.FullLoader) |
| 1221 | x = np.loadtxt('evolve.txt', ndmin=2) |
| 1222 | f = fitness(x) |
| 1223 | # weights = (f - f.min()) ** 2 # for weighted results |
| 1224 | plt.figure(figsize=(10, 12), tight_layout=True) |
| 1225 | matplotlib.rc('font', **{'size': 8}) |
| 1226 | for i, (k, v) in enumerate(hyp.items()): |
| 1227 | y = x[:, i + 7] |
| 1228 | # mu = (y * weights).sum() / weights.sum() # best weighted result |
| 1229 | mu = y[f.argmax()] # best single result |
| 1230 | plt.subplot(6, 5, i + 1) |
| 1231 | plt.scatter(y, f, c=hist2d(y, f, 20), cmap='viridis', alpha=.8, edgecolors='none') |
| 1232 | plt.plot(mu, f.max(), 'k+', markersize=15) |
| 1233 | plt.title('%s = %.3g' % (k, mu), fontdict={'size': 9}) # limit to 40 characters |
| 1234 | if i % 5 != 0: |
| 1235 | plt.yticks([]) |
| 1236 | print('%15s: %.3g' % (k, mu)) |
| 1237 | plt.savefig('evolve.png', dpi=200) |
| 1238 | print('\nPlot saved as evolve.png') |
| 1239 | |
| 1240 | |
| 1241 | def plot_results_overlay(start=0, stop=0): # from utils.general import *; plot_results_overlay() |