This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gr.py
72 lines (62 loc) · 2.02 KB
/
gr.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import matplotlib.pyplot as plt
import os
import re
# List of file paths
file_paths = [
"/mnt/twoterra/outputs/14-02-2024/LSTM_200_epoch_125.pth",
"/mnt/oneterra/outputs/08-02-2024/LSTM_170_epoch_92.pth",
"/mnt/oneterra/outputs/07-02-2024/LSTM_120_epoch_44.pth",
"/mnt/oneterra/outputs/04-12-2023/LSTM_100_cont_epoch_25.pth",
"/mnt/oneterra/outputs/06-12-2023/LSTM_100_epoch_54.pth"
]
tipe = "train_losses"
# tipe = "val_losses"
cutoff = 180
# Reverse the list of paths
file_paths.reverse()
# Step 1: Modify the filepaths
def modify_path(path):
# Replace "oneterra" with "threeterra"
new_path = path.replace("oneterra", "threeterra")
# Remove ".pth" and add "_train_losses.npy"
new_path = re.sub(r'\.pth$', f'_{tipe}.npy', new_path)
return new_path
modified_paths = [modify_path(path) for path in file_paths]
# Step 2: Load and concatenate numpy arrays
def load_and_concatenate(paths, cutoff=120):
arrays = []
for path in paths:
# Load the numpy array if it exists
if os.path.exists(path):
arrays.append(np.load(path))
else:
print(f"File not found: {path}")
# Concatenate arrays if there are any to concatenate
if arrays:
return np.concatenate(arrays)[:cutoff]
else:
return None
# Concatenate the numpy data
concatenated_data = load_and_concatenate(modified_paths, cutoff=cutoff)
# save this data
np.save(f"all_{tipe}.npy", concatenated_data)
# Step 3: Plot the data
def plot_data(data):
if data is not None:
plt.figure(figsize=(10, 5))
plt.plot(data)
if tipe == "train_losses":
plt.title('Training Losses Over Time')
elif tipe == "val_losses":
plt.title('Validation Losses Over Time')
else:
plt.title('Losses Over Time')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.show()
plt.savefig(f"{tipe}_{cutoff}.pdf")
else:
print("No data to plot.")
# Call the plot function
plot_data(concatenated_data)