Add 'matplotlib.use('Agg')'; update output path
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from pathlib import Path
|
||||
from omegaconf import OmegaConf
|
||||
import torch
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from pathlib import Path
|
||||
from omegaconf import OmegaConf
|
||||
import torch
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from pathlib import Path
|
||||
from omegaconf import OmegaConf
|
||||
import torch
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from omegaconf import OmegaConf ### for yaml config parsing
|
||||
import torch
|
||||
import numpy as np
|
||||
@@ -173,6 +176,7 @@ def plot_loss_curve(train_losses, val_losses, test_loss, exp_name, conf):
|
||||
if conf.data.normalize:
|
||||
plotName += '_normalized'
|
||||
plt.savefig(f'Results/{exp_name}/Plots/{plotName}.png')
|
||||
plt.close()
|
||||
|
||||
def plot_rms_curve(train_rms_x, train_rms_y, val_rms_x, val_rms_y, test_rms_x, test_rms_y, exp_name, conf):
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -192,6 +196,7 @@ def plot_rms_curve(train_rms_x, train_rms_y, val_rms_x, val_rms_y, test_rms_x, t
|
||||
if conf.data.normalize:
|
||||
plotName += '_normalized'
|
||||
plt.savefig(f'Results/{exp_name}/Plots/{plotName}.png')
|
||||
plt.close()
|
||||
|
||||
def get_model_name(epoch, conf):
|
||||
modelName = f'singlePhoton{conf.model.version}_{conf.data.energy}keV_Noise{conf.data.noise_keV}keV_E{epoch}_aug{conf.data.num_aug_ops}'
|
||||
|
||||
+13
-9
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from omegaconf import OmegaConf ### for yaml config parsing
|
||||
import torch
|
||||
from torch import nn
|
||||
@@ -27,14 +30,14 @@ def prepare_output_folder(conf):
|
||||
# find the next index for experiment name
|
||||
exp_index = 0
|
||||
while True:
|
||||
exp_name = f'{date}_2ph_{conf.data.energy}keV_v{conf.model.version}_{exp_index:02d}'
|
||||
if not Path(f'Results/{exp_name}').exists():
|
||||
exp_name = f'{date}_{conf.data.energy}keV_v{conf.model.version}_{exp_index:02d}'
|
||||
if not Path(f'Results/2ph/{exp_name}').exists():
|
||||
break
|
||||
exp_index += 1
|
||||
Path(f'Results/{exp_name}').mkdir(parents=True, exist_ok=True)
|
||||
Path(f'Results/{exp_name}/Models').mkdir(parents=True, exist_ok=True)
|
||||
Path(f'Results/{exp_name}/Plots').mkdir(parents=True, exist_ok=True)
|
||||
OmegaConf.save(conf, f'Results/{exp_name}/config.yaml')
|
||||
Path(f'Results/2ph/{exp_name}').mkdir(parents=True, exist_ok=True)
|
||||
Path(f'Results/2ph/{exp_name}/Models').mkdir(parents=True, exist_ok=True)
|
||||
Path(f'Results/2ph/{exp_name}/Plots').mkdir(parents=True, exist_ok=True)
|
||||
OmegaConf.save(conf, f'Results/2ph/{exp_name}/config.yaml')
|
||||
return exp_name
|
||||
|
||||
def get_loss_function(conf):
|
||||
@@ -208,7 +211,7 @@ def plot_loss_curves(train_losses, val_losses, test_loss, exp_name, conf):
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
plotName = f'loss_curve_doublePhoton_{conf.model.version}.png'
|
||||
plt.savefig(f'Results/{exp_name}/Plots/{plotName}')
|
||||
plt.savefig(f'Results/2ph/{exp_name}/Plots/{plotName}')
|
||||
plt.close()
|
||||
|
||||
def plot_rms_curve(train_rms_x, train_rms_y, val_rms_x, val_rms_y, test_rms_x, test_rms_y, exp_name, conf):
|
||||
@@ -226,7 +229,8 @@ def plot_rms_curve(train_rms_x, train_rms_y, val_rms_x, val_rms_y, test_rms_x, t
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
plotName = f'rms_curve_doublePhoton_{conf.model.version}'
|
||||
plt.savefig(f'Results/{exp_name}/Plots/{plotName}.png')
|
||||
plt.savefig(f'Results/2ph/{exp_name}/Plots/{plotName}.png')
|
||||
plt.close()
|
||||
|
||||
def get_model_name(conf):
|
||||
modelName = f'doublePhoton{conf.model.version}_{conf.data.energy}keV_Noise{conf.data.noise_keV}keV'
|
||||
@@ -260,7 +264,7 @@ if __name__ == "__main__":
|
||||
print(f"Learning Rate: {optimizer.param_groups[0]['lr']:.2e}")
|
||||
if epoch in conf.training.checkpoint_epochs or epoch == conf.training.epochs:
|
||||
modelName = get_model_name(conf)
|
||||
torch.save(model.state_dict(), f'Results/{exp_name}/Models/{modelName}_E{epoch}.pth')
|
||||
torch.save(model.state_dict(), f'Results/2ph/{exp_name}/Models/{modelName}_E{epoch}.pth')
|
||||
print(f"Saved model checkpoint: {modelName}_E{epoch}.pth")
|
||||
plot_loss_curves(TrainLosses, ValLosses, test_loss=-1, exp_name=exp_name, conf=conf)
|
||||
plot_rms_curve(train_rms_xs, train_rms_ys, val_rms_xs, val_rms_ys, test_rms_x = -1, test_rms_y = -1, exp_name=exp_name, conf=conf)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import sys
|
||||
sys.path.append('./src')
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
from omegaconf import OmegaConf ### for yaml config parsing
|
||||
import torch
|
||||
import numpy as np
|
||||
@@ -134,6 +137,7 @@ def plot_loss_curves(train_losses, val_losses, test_loss, exp_name, conf):
|
||||
plt.grid()
|
||||
plotName = f'loss_curve_triplePhoton_{conf.model.version}.png'
|
||||
plt.savefig(f'Results/{exp_name}/Plots/{plotName}')
|
||||
plt.close()
|
||||
|
||||
def get_model_name(conf):
|
||||
modelName = f'triplePhoton{conf.model.version}_{conf.data.energy}keV'
|
||||
|
||||
Reference in New Issue
Block a user