cleaned up for submission

This commit is contained in:
2026-07-10 20:13:13 +02:00
parent 47fbb19761
commit 7eff030e89
38 changed files with 39 additions and 4175 deletions

View File

@@ -31,13 +31,13 @@ class Model(ABC):
optimizer = optim.Adam(filter(lambda p: p.requires_grad, self.model.parameters()), lr=rate, weight_decay=0.1)
scheduler = CosineAnnealingLR(optimizer, T_max=epochs, eta_min=1e-6)
# to save reports
# file_path = Path(f"{mode}/{self.__class__.__name__.lower()}/time_metrics.txt")
# Util._initialize_log_file(file_path)
# to save training time to reports
file_path = Path(f"{mode}/{self.__class__.__name__.lower()}/time_metrics.txt")
Util._initialize_log_file(file_path)
print(f"Starting training on {self.device}...")
# start_time = time.time()
start_time = time.time()
# training phase
self.model.train()
@@ -49,7 +49,7 @@ class Model(ABC):
optimizer.zero_grad()
# forward pass
outputs = self.model(inputs)
# comoutew loss
# comopute loss
loss = criterion(outputs, labels)
# backward pass
loss.backward()
@@ -58,9 +58,9 @@ class Model(ABC):
scheduler.step()
print(f"Epoch {epoch+1}/{epochs} | Loss: {total_loss / len(loader):.4f}")
#end_time = time.time()
#execution_time = end_time - start_time
#Util.log_metric(log_file=file_path, execution_time=execution_time)
end_time = time.time()
execution_time = end_time - start_time
Util.log_metric(log_file=file_path, execution_time=execution_time)
if self.device.type == 'cuda': torch.cuda.synchronize()
print(f"Training complete.")
@@ -123,10 +123,10 @@ class Model(ABC):
print(f"Test Accuracy: {accuracy:.2f}%")
# 1. Print standard text report to terminal
print(classification_report(all_labels, all_preds, labels=classes, zero_division=0))
# Print standard text report to terminal
#print(classification_report(all_labels, all_preds, labels=classes, zero_division=0))
# 2. Extract structured dictionary metrics
# Structured dictionary metrics
report_dict = classification_report(
all_labels,
all_preds,
@@ -135,8 +135,7 @@ class Model(ABC):
zero_division=0
)
# 3. Delegate file tracking to isolated helper method
#self._log_to_csv(mode, accuracy,report_dict)
# report metrics to choriographer
return accuracy, report_dict