strategies tested
This commit is contained in:
24
Util.py
24
Util.py
@@ -1,13 +1,14 @@
|
||||
|
||||
from pathlib import Path
|
||||
from architectures.Model import Model
|
||||
import time
|
||||
import os
|
||||
|
||||
def _log_to_csv(model:Model, mode, accuracy, report_dict, strategy):
|
||||
def _log_to_csv(arch, mode, accuracy, report_dict, strategy):
|
||||
"""Handles directory structures, file setups, and distinct CSV column formatting."""
|
||||
arch_name = model.__class__.__name__.lower()
|
||||
#arch_name = model.__class__.__name__.lower()
|
||||
save_dir = Path(f"reports/{strategy}")
|
||||
save_dir.mkdir(parents=True, exist_ok=True)
|
||||
csv_path = save_dir / f"{arch_name}-{mode}.csv"
|
||||
csv_path = save_dir / f"{arch}-{mode}.csv"
|
||||
|
||||
file_exists = csv_path.exists()
|
||||
|
||||
@@ -31,4 +32,17 @@ def _log_to_csv(model:Model, mode, accuracy, report_dict, strategy):
|
||||
f.write(",".join(headers) + "\n")
|
||||
f.write(",".join(row) + "\n")
|
||||
|
||||
print(f">> Direct CSV metrics appended to {csv_path}")
|
||||
print(f">> Direct CSV metrics appended to {csv_path}")
|
||||
|
||||
|
||||
def _initialize_log_file(log_file):
|
||||
"""Creates a unique log file for this strategy with a header if it doesn't exist."""
|
||||
log_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not os.path.exists(log_file):
|
||||
with open(log_file, "w") as f:
|
||||
f.write("execution_time_sec\n")
|
||||
|
||||
def log_metric(log_file, execution_time: float):
|
||||
"""Appends the execution time to this strategy's specific file."""
|
||||
with open(log_file, "a") as f:
|
||||
f.write(f"{execution_time:.6f}\n")
|
||||
Reference in New Issue
Block a user