|
|
import os
|
|
|
import pandas as pd
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
def plot_training_loss(exp_dir, epoch):
|
|
|
|
|
|
|
|
|
log_dir = os.path.join(exp_dir, 'log')
|
|
|
train_pkl = os.path.join(log_dir, f'temp_train_loss_{epoch}.pkl')
|
|
|
if not os.path.isfile(train_pkl):
|
|
|
raise FileNotFoundError(f"Training pickle not found: {train_pkl}")
|
|
|
|
|
|
|
|
|
df = pd.read_pickle(train_pkl)
|
|
|
|
|
|
epoch_losses = [float(x) for x in df['train_epoch_losses']]
|
|
|
|
|
|
|
|
|
|
|
|
lrs = df['learning_rate']
|
|
|
epochs = list(range(1, len(epoch_losses) + 1))
|
|
|
print("min training loss", df['train_min_epoch_loss'])
|
|
|
|
|
|
|
|
|
fig, ax1 = plt.subplots(figsize=(10,5))
|
|
|
ax1.plot(epochs, epoch_losses, marker='o', linestyle='-', label='Total Train Loss', color = 'blue')
|
|
|
|
|
|
|
|
|
|
|
|
ax1.set_xlabel('Epoch')
|
|
|
ax1.set_ylabel('Loss', color='blue')
|
|
|
ax1.tick_params(axis='y', labelcolor='blue')
|
|
|
|
|
|
ax2 = ax1.twinx()
|
|
|
ax2.plot(epochs, lrs, linestyle='--', label='Learning Rate', color='red')
|
|
|
ax2.set_ylabel('Learning Rate', color='red')
|
|
|
ax2.tick_params(axis='y', labelcolor='red')
|
|
|
|
|
|
|
|
|
lines, labels = ax1.get_legend_handles_labels()
|
|
|
lines2, labels2 = ax2.get_legend_handles_labels()
|
|
|
ax1.legend(lines + lines2, labels + labels2, loc='upper right')
|
|
|
|
|
|
ax1.set_title(f'Training Loss & Learning Rate (epoch {epoch})')
|
|
|
ax1.grid(True)
|
|
|
|
|
|
|
|
|
save_dir = os.path.join(exp_dir, 'plots_lr')
|
|
|
os.makedirs(save_dir, exist_ok=True)
|
|
|
out_path = os.path.join(save_dir, f'training_loss_epoch_{epoch}.png')
|
|
|
plt.tight_layout()
|
|
|
plt.savefig(out_path)
|
|
|
plt.close(fig)
|
|
|
print(f"Saved training plot to {out_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
exp_dir = '/home/rachit/GlassForming/t_dest_output/regDGCNN_seg/train/EXPERIMENT_2/Mon-Jul-14-10-01-31-2025/'
|
|
|
epoch = 40
|
|
|
plot_training_loss(exp_dir, epoch)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
main() |