From fef3eed606cff6a8720c2abaf811311be9d9315f Mon Sep 17 00:00:00 2001 From: Alan Ng <15185920+alanngnet@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:34:57 -0500 Subject: [PATCH] train_tune bugfix loss experiments had bad log name --- tools/train_tune.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/train_tune.py b/tools/train_tune.py index 819d1df..f502398 100644 --- a/tools/train_tune.py +++ b/tools/train_tune.py @@ -82,11 +82,11 @@ def run_experiment( t.configure_scheduler() t.train(max_epochs=hp["max_epochs"]) # ensure log files are saved before retrieving metrics - t.summary_writer.close() + t.summary_writer.close() del t.model del t print(f"Completed experiment with seed {seed}") - time.sleep(1) # give OS time to save log file + time.sleep(1) # give OS time to save log file return log_path @@ -208,7 +208,9 @@ def get_final_metrics_from_logs(log_dir, test_name): for seed in seeds: hp_summary = f"m_per_class{m_per_class}" log_path = run_experiment(hp_summary, checkpoint_dir, hp, seed) - final_val_loss, final_map = get_final_metrics_from_logs(log_path, test_name) + final_val_loss, final_map = get_final_metrics_from_logs( + log_path, test_name + ) results["val_loss"].append(final_val_loss) results["map"].append(final_map) mean_loss = np.mean(results["val_loss"]) @@ -248,7 +250,9 @@ def get_final_metrics_from_logs(log_dir, test_name): ) ) log_path = run_experiment(hp_summary, checkpoint_dir, hp, seed) - final_val_loss, final_map = get_final_metrics_from_logs(log_path, test_name) + final_val_loss, final_map = get_final_metrics_from_logs( + log_path, test_name + ) results["val_loss"].append(final_val_loss) results["map"].append(final_map) mean_loss = np.mean(results["val_loss"]) @@ -261,7 +265,7 @@ def get_final_metrics_from_logs(log_dir, test_name): } print(f"Results for {hp_summary}") pprint.pprint(all_results[hp_summary]) - + # loss experiments hp = load_hparams(os.path.join(model_dir, "config/hparams.yaml")) hp["every_n_epoch_to_save"] = 100 @@ -280,11 +284,15 @@ def get_final_metrics_from_logs(log_dir, test_name): center_weight = center["weight"] for seed in seeds: - hp_summary = f"CE_dims{ce_dims}_wt{ce_weight}_gamma{ce_gamma}_" - f"TRIP_marg{triplet_margin}_wt{triplet_weight}_" - f"CNTR_wt{center_weight}" + hp_summary = ( + f"CE_dims{ce_dims}_wt{ce_weight}_gamma{ce_gamma}_" + + f"TRIP_marg{triplet_margin}_wt{triplet_weight}_" + + f"CNTR_wt{center_weight}" + ) log_path = run_experiment(hp_summary, checkpoint_dir, hp, seed) - final_val_loss, final_map = get_final_metrics_from_logs(log_path, test_name) + final_val_loss, final_map = get_final_metrics_from_logs( + log_path, test_name + ) results["val_loss"].append(final_val_loss) results["map"].append(final_map) mean_loss = np.mean(results["val_loss"]) @@ -301,5 +309,9 @@ def get_final_metrics_from_logs(log_dir, test_name): print("\nSummary of Experiments:") for hp_summary, result in all_results.items(): print(f"\nExperiment: {hp_summary}") - print(f" Validation Loss: mean = {result['val_loss']['mean']:.4f}, std = {result['val_loss']['std']:.4f}") - print(f" mAP: mean = {result['map']['mean']:.4f}, std = {result['map']['std']:.4f}") \ No newline at end of file + print( + f" Validation Loss: mean = {result['val_loss']['mean']:.4f}, std = {result['val_loss']['std']:.4f}" + ) + print( + f" mAP: mean = {result['map']['mean']:.4f}, std = {result['map']['std']:.4f}" + )