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

Make regularization loss weight a cfg parameter #17

Merged
merged 1 commit into from
Aug 24, 2021
Merged
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
4 changes: 3 additions & 1 deletion nidn/training/run_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def run_training(
loss += spectrum_loss

if run_cfg.type == "classification" and run_cfg.use_regularization_loss:
loss += 0.05 * _likelihood_regularization_loss_fn(material_ids, run_cfg.L)
loss += run_cfg.reg_loss_weight * _likelihood_regularization_loss_fn(
material_ids, run_cfg.L
)

# We store the model if it has the lowest loss yet
# (this is to avoid losing good results during a run that goes wild)
Expand Down
3 changes: 3 additions & 0 deletions nidn/training/utils/validate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _validate_config(cfg: DotMap):
"absorption_loss",
"type",
"use_regularization_loss",
"reg_loss_weight",
"add_noise",
"noise_scale",
]
Expand Down Expand Up @@ -59,6 +60,7 @@ def _validate_config(cfg: DotMap):
"imag_max_eps",
"siren_omega",
"noise_scale",
"reg_loss_weight",
]
boolean_keys = ["use_regularization_loss", "add_noise"]
string_keys = ["model_type", "type"]
Expand Down Expand Up @@ -99,6 +101,7 @@ def _validate_config(cfg: DotMap):
"iterations",
"eps_oversampling",
"noise_scale",
"reg_loss_weight",
]
for key in positive_value_keys:
if not (cfg[key] > 0):
Expand Down
4 changes: 2 additions & 2 deletions nidn/utils/print_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def print_cfg(cfg: DotMap):
print()
else:
if idx % 3 == 2:
print(f"{key:<20}: {value:<20}")
print(f"{key:<23}: {value:<15}|")
else:
print(f"{key:<20}: {value:<20}", end="")
print(f"{key:<23}: {value:<15}|", end="")
idx += 1
print()
1 change: 1 addition & 0 deletions nidn/utils/resources/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ model_type = "siren"
iterations = 2000
learning_rate = 6.5e-5
type = "classification" # "classification" or "regression"
reg_loss_weight = 0.05 # weighting of the regularization loss
use_regularization_loss = true # only relevant for classification

# Loss
Expand Down