unknownBrain's picture
Release clean cross-corpus dysarthria code, unmodified logs/CSVs, figures, and compiled BSPC PDF
05ddf4d verified
Raw History Blame Contribute Delete
2.38 kB
"""Generate GRL diagnostic training curves from saved epoch metrics."""
import argparse
import os
import pandas as pd
import matplotlib.pyplot as plt
def plot_curves(input_csv: str, output_path: str):
"""Plot speaker and pathology accuracy/loss trajectories across GRL epochs."""
df = pd.read_csv(input_csv)
inv_df = df[df['condition'] == 'invariant']
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
# Top-Left: Speaker Accuracy
axes[0, 0].plot(inv_df['epoch'], inv_df['train_spk_acc'], label='Train Spk Acc')
axes[0, 0].plot(inv_df['epoch'], inv_df['val_spk_acc'], label='Val Spk Acc')
axes[0, 0].set_title('GRL Model: Speaker Accuracy over Epochs')
axes[0, 0].set_xlabel('Epoch')
axes[0, 0].legend()
# Top-Right: Speaker Loss
axes[0, 1].plot(inv_df['epoch'], inv_df['train_spk_loss'], label='Train Spk Loss')
axes[0, 1].plot(inv_df['epoch'], inv_df['val_spk_loss'], label='Val Spk Loss')
axes[0, 1].set_title('GRL Model: Speaker Loss over Epochs')
axes[0, 1].set_xlabel('Epoch')
axes[0, 1].legend()
# Bottom-Left: Pathology Accuracy
axes[1, 0].plot(inv_df['epoch'], inv_df['train_path_acc'], label='Train Path Acc')
axes[1, 0].plot(inv_df['epoch'], inv_df['val_path_acc'], label='Val Path Acc')
axes[1, 0].set_title('GRL Model: Pathology Accuracy over Epochs')
axes[1, 0].set_xlabel('Epoch')
axes[1, 0].legend()
# Bottom-Right: Pathology Loss
axes[1, 1].plot(inv_df['epoch'], inv_df['train_path_loss'], label='Train Path Loss')
axes[1, 1].plot(inv_df['epoch'], inv_df['val_path_loss'], label='Val Path Loss')
axes[1, 1].set_title('GRL Model: Pathology Loss over Epochs')
axes[1, 1].set_xlabel('Epoch')
axes[1, 1].legend()
plt.tight_layout()
plt.savefig(output_path, dpi=300)
plt.close(fig)
def parse_args():
default_csv = "results/grl_diagnostic.csv" if os.path.exists("results/grl_diagnostic.csv") else "grl_diagnostic.csv"
parser = argparse.ArgumentParser(description="Plot GRL epoch-level diagnostic curves.")
parser.add_argument("--input-csv", default=default_csv, help="Path to grl_diagnostic.csv")
parser.add_argument("--output", default="grl_curves.png", help="Output PNG figure path")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
plot_curves(args.input_csv, args.output)