Created
February 21, 2017 15:39
-
-
Save lebedov/85840f17dbfa264a4c16612279c4d0d9 to your computer and use it in GitHub Desktop.
Pairwise distance module for pytorch.
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
#!/usr/bin/env python | |
""" | |
Pairwise distance module for pytorch. | |
""" | |
import torch.autograd as autograd | |
import torch.nn as nn | |
class PairwiseDistance(nn.Module): | |
def __init__(self, norm_type, dim=1): | |
super(PairwiseDistance, self).__init__() | |
self.norm_type = norm_type | |
self.dim = dim | |
def forward(self, input): | |
return autograd.variable.Norm(self.norm_type, | |
self.dim)(input[1]-input[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment