Rename single photon files
This commit is contained in:
@@ -38,7 +38,7 @@ task = 'SiemenStarLowerLeft'
|
|||||||
config = configs[task]
|
config = configs[task]
|
||||||
|
|
||||||
BinningFactor = 10
|
BinningFactor = 10
|
||||||
numberOfAugOps = 1
|
numberOfAugOps = 8
|
||||||
flag_normalize = False
|
flag_normalize = False
|
||||||
Roi = config['roi']
|
Roi = config['roi']
|
||||||
X_st, X_ed, Y_st, Y_ed = Roi
|
X_st, X_ed, Y_st, Y_ed = Roi
|
||||||
@@ -76,7 +76,7 @@ def apply_inverse_transforms(predictions: torch.Tensor, numberOfAugOps: int) ->
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
model = models.get_model_class(config['modelVersion'])().cuda()
|
model = models.get_model_class(config['modelVersion'])().cuda()
|
||||||
modelName = f'singlePhoton{config["modelVersion"]}_{config["energy"]}keV_Noise{config["noise"]}keV_aug1'
|
modelName = f'singlePhoton{config["modelVersion"]}_{config["energy"]}keV_Noise{config["noise"]}keV_E500_aug1'
|
||||||
if flag_normalize:
|
if flag_normalize:
|
||||||
modelName += '_normalized'
|
modelName += '_normalized'
|
||||||
model.load_state_dict(torch.load(f'/home/xie_x1/MLXID/DeepLearning/Models/{modelName}.pth', weights_only=True))
|
model.load_state_dict(torch.load(f'/home/xie_x1/MLXID/DeepLearning/Models/{modelName}.pth', weights_only=True))
|
||||||
@@ -23,7 +23,7 @@ TestLoss = -1
|
|||||||
model = models.get_model_class(modelVersion)().cuda()
|
model = models.get_model_class(modelVersion)().cuda()
|
||||||
# summary(model, input_size=(128, 1, 3, 3))
|
# summary(model, input_size=(128, 1, 3, 3))
|
||||||
LearningRate = 1e-3
|
LearningRate = 1e-3
|
||||||
Noise = 0.13 # in keV
|
Noise = 0.23 # in keV
|
||||||
NoiseThreshold = 0 * Noise # in keV, set values below this threshold to zero
|
NoiseThreshold = 0 * Noise # in keV, set values below this threshold to zero
|
||||||
numberOfAugOps = 1 # 1 (no augmentation) or (1,8] (with augmentation)
|
numberOfAugOps = 1 # 1 (no augmentation) or (1,8] (with augmentation)
|
||||||
flag_normalize = False
|
flag_normalize = False
|
||||||
@@ -141,27 +141,8 @@ testLoader = torch.utils.data.DataLoader(
|
|||||||
|
|
||||||
optimizer = torch.optim.Adam(model.parameters(), lr=LearningRate)
|
optimizer = torch.optim.Adam(model.parameters(), lr=LearningRate)
|
||||||
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, 'min', factor=0.7, patience = 3)
|
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, 'min', factor=0.7, patience = 3)
|
||||||
if __name__ == "__main__":
|
|
||||||
for epoch in tqdm(range(1, 1001)):
|
|
||||||
train(model, trainLoader, optimizer)
|
|
||||||
test(model, valLoader)
|
|
||||||
scheduler.step(ValLosses[-1])
|
|
||||||
print(f"Learning Rate: {optimizer.param_groups[0]['lr']}")
|
|
||||||
if epoch in [20, 30, 50, 100, 200, 300, 500, 750, 1000]:
|
|
||||||
modelName = f'singlePhoton{modelVersion}_{Energy}_Noise{Noise}keV_E{epoch}_aug{numberOfAugOps}'
|
|
||||||
if flag_normalize == True:
|
|
||||||
modelName += '_normalized'
|
|
||||||
torch.save(model.state_dict(), f'Models/{modelName}.pth')
|
|
||||||
print(f"Saved model checkpoint: {modelName}.pth")
|
|
||||||
|
|
||||||
test(model, testLoader)
|
def plot_loss_curve(TrainLosses, ValLosses, modelVersion, TestLoss=0):
|
||||||
modelName = f'singlePhoton{modelVersion}_{Energy}_Noise{Noise}keV_E{epoch}_aug{numberOfAugOps}'
|
|
||||||
if flag_normalize == True:
|
|
||||||
modelName += '_normalized'
|
|
||||||
torch.save(model.state_dict(), f'Models/{modelName}.pth')
|
|
||||||
print(f"Saved final model checkpoint: {modelName}.pth")
|
|
||||||
|
|
||||||
def plot_loss_curve(TrainLosses, ValLosses, TestLoss, modelVersion):
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
plt.figure(figsize=(8,6))
|
plt.figure(figsize=(8,6))
|
||||||
plt.plot(TrainLosses, label='Train Loss', color='blue')
|
plt.plot(TrainLosses, label='Train Loss', color='blue')
|
||||||
@@ -177,4 +158,25 @@ def plot_loss_curve(TrainLosses, ValLosses, TestLoss, modelVersion):
|
|||||||
if flag_normalize:
|
if flag_normalize:
|
||||||
plotName += '_normalized'
|
plotName += '_normalized'
|
||||||
plt.savefig(f'Results/{plotName}.png')
|
plt.savefig(f'Results/{plotName}.png')
|
||||||
plot_loss_curve(TrainLosses, ValLosses, TestLoss, modelVersion=modelVersion)
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
for epoch in tqdm(range(1, 151)):
|
||||||
|
train(model, trainLoader, optimizer)
|
||||||
|
test(model, valLoader)
|
||||||
|
scheduler.step(ValLosses[-1])
|
||||||
|
print(f"Learning Rate: {optimizer.param_groups[0]['lr']}")
|
||||||
|
if epoch in [20, 30, 50, 100, 150]:
|
||||||
|
modelName = f'singlePhoton{modelVersion}_{Energy}_Noise{Noise}keV_E{epoch}_aug{numberOfAugOps}'
|
||||||
|
if flag_normalize == True:
|
||||||
|
modelName += '_normalized'
|
||||||
|
torch.save(model.state_dict(), f'Models/{modelName}.pth')
|
||||||
|
print(f"Saved model checkpoint: {modelName}.pth")
|
||||||
|
plot_loss_curve(TrainLosses, ValLosses, modelVersion=modelVersion)
|
||||||
|
|
||||||
|
test(model, testLoader)
|
||||||
|
modelName = f'singlePhoton{modelVersion}_{Energy}_Noise{Noise}keV_E{epoch}_aug{numberOfAugOps}'
|
||||||
|
if flag_normalize == True:
|
||||||
|
modelName += '_normalized'
|
||||||
|
torch.save(model.state_dict(), f'Models/{modelName}.pth')
|
||||||
|
print(f"Saved final model checkpoint: {modelName}.pth")
|
||||||
|
plot_loss_curve(TrainLosses, ValLosses, modelVersion=modelVersion, TestLoss=TestLoss)
|
||||||
Reference in New Issue
Block a user