Created
November 1, 2023 10:14
-
-
Save sadimanna/8cd4f3c93e84ea4215fceed2fa40e2a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reg_loss = 0 | |
for mod in self.model.modules(): | |
if isinstance(mod, _BatchNorm): | |
if self.decay_bn: | |
for name, param in mod.named_parameters(recurse=False): | |
reg_loss = reg_loss + param.norm(2) | |
else: | |
for name, param in mod.named_parameters(recurse=False): | |
if not name.endswith("bias"): | |
reg_loss = reg_loss + param.norm(2) | |
else: | |
if self.decay_bias: | |
reg_loss = reg_loss + param.norm(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment