File size: 1,107 Bytes
8c48cce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import matplotlib.pyplot as plt

def plot_loss_log(loss_file="output/steak/loss.txt"):
    """Plot training loss values on a logarithmic scale from loss.txt"""
    
    # Load loss values from txt file
    with open(loss_file, 'r') as f:
        losses = [float(line.strip()) for line in f if line.strip()]
    
    # Create figure with log scale
    plt.figure(figsize=(12, 6))
    plt.semilogy(losses, label='Training Loss')
    
    # Customize plot
    plt.grid(True, which="both", ls="-", alpha=0.2)
    plt.xlabel('Iteration')
    plt.ylabel('Loss (log scale)')
    plt.title('Training Loss over Time (Log Scale)')
    plt.legend()
    
    # Save plot
    output_path = loss_file.replace('.txt', '_plot_log.png')
    plt.savefig(output_path, dpi=300, bbox_inches='tight')
    plt.close()
    
    print(f"Saved loss plot to: {output_path}")
    print(f"Loss statistics:")
    print(f"  Min: {min(losses):.6f}")
    print(f"  Max: {max(losses):.6f}")
    print(f"  Mean: {np.mean(losses):.6f}")
    print(f"  Final: {losses[-1]:.6f}")

if __name__ == "__main__":
    plot_loss_log()