Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible improvements #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CNO1d_vanilla_torch_version/TraincCNO.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main():
test_relative_l2 = 0.0
for step, (input_batch, output_batch) in enumerate(testing_set):
output_pred_batch = cno(input_batch)
loss_f = (torch.mean((abs(output_pred_batch - output_batch))) / torch.mean(abs(output_batch))) ** 0.5 * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) ** 0.5 * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(testing_set)

Expand Down
2 changes: 1 addition & 1 deletion CNO2d_original_version/CNOModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
4 changes: 2 additions & 2 deletions CNO2d_original_version/TrainCNO.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
output_pred_batch[input_batch==1] = 1
output_batch[input_batch==1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(val_loader)

Expand All @@ -196,7 +196,7 @@
output_pred_batch[input_batch==1] = 1
output_batch[input_batch==1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
train_relative_l2 += loss_f.item()
train_relative_l2 /= len(train_loader)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
2 changes: 1 addition & 1 deletion CNO2d_vanilla_torch_version/TraincCNO.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main():
test_relative_l2 = 0.0
for step, (input_batch, output_batch) in enumerate(testing_set):
output_pred_batch = cno(input_batch)
loss_f = (torch.mean((abs(output_pred_batch - output_batch))) / torch.mean(abs(output_batch))) ** 0.5 * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) ** 0.5 * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(testing_set)

Expand Down
6 changes: 3 additions & 3 deletions _OtherModels/BaselinesModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down Expand Up @@ -229,7 +229,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down Expand Up @@ -275,7 +275,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
4 changes: 2 additions & 2 deletions _OtherModels/CNNModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down Expand Up @@ -298,7 +298,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
4 changes: 2 additions & 2 deletions _OtherModels/DeepONetModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down Expand Up @@ -145,7 +145,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
4 changes: 2 additions & 2 deletions _OtherModels/FNOModules.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down Expand Up @@ -264,7 +264,7 @@ def print_size(self):
nbytes = 0

for param in self.parameters():
nparams += param.numel()
nparams += param.numel()*(param.is_complex() + 1)
nbytes += param.data.element_size() * param.numel()

print(f'Total number of model parameters: {nparams} (~{format_tensor_size(nbytes)})')
Expand Down
2 changes: 1 addition & 1 deletion _OtherModels/TrainDON.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
if which_example == "airfoil":
output_pred_batch[input_batch == 1] = 1
output_batch[input_batch == 1] = 1
loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(test_loader)

Expand Down
8 changes: 4 additions & 4 deletions _OtherModels/TrainFNO.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
training_properties = {
"learning_rate": 0.001,
"weight_decay": 1e-8,
"scheduler_step": 0.97,
"scheduler_gamma": 10,
"scheduler_step": 10,
"scheduler_gamma": 0.97,
"epochs": 1000,
"batch_size": 16,
"exp": 1,
Expand Down Expand Up @@ -155,7 +155,7 @@
output_pred_batch[input_batch==1] = 1
output_batch[input_batch==1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(test_loader)

Expand All @@ -168,7 +168,7 @@
output_pred_batch[input_batch==1] = 1
output_batch[input_batch==1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
train_relative_l2 += loss_f.item()
train_relative_l2 /= len(train_loader)

Expand Down
2 changes: 1 addition & 1 deletion _OtherModels/TrainResNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
output_pred_batch[input_batch == 1] = 1
output_batch[input_batch == 1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(test_loader)

Expand Down
2 changes: 1 addition & 1 deletion _OtherModels/TrainUNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
output_pred_batch[input_batch == 1] = 1
output_batch[input_batch == 1] = 1

loss_f = torch.mean(abs(output_pred_batch - output_batch)) / torch.mean(abs(output_batch)) * 100
loss_f = torch.mean(torch.sum(abs(output_pred_batch - output_batch), dim=(1,2)) / torch.sum(abs(output_batch), dim=(1,2))) * 100
test_relative_l2 += loss_f.item()
test_relative_l2 /= len(test_loader)

Expand Down