Skip to content

Instantly share code, notes, and snippets.

@l-bat
Created November 18, 2019 13:29
Show Gist options
  • Save l-bat/4baff6d9405375920faf7f3de172cc6c to your computer and use it in GitHub Desktop.
Save l-bat/4baff6d9405375920faf7f3de172cc6c to your computer and use it in GitHub Desktop.
class FeatureL2Norm(torch.nn.Module):
def __init__(self):
super(FeatureL2Norm, self).__init__()
def forward(self, feature):
norm = torch.norm(feature, p=2, dim=1, keepdim=True)
return torch.div(feature, norm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment