Distance functions

class torch.nn.PairwiseDistance(p=2, eps=1e-06)

按批计算向量v1, v2之间的距离:

$$\Vert x \Vert p := \left( \sum{i=1}^n \vert x_i \vert ^ p \right) ^ {1/p}$$

参数:

  • x (Tensor): 包含两个输入batch的张量
  • p (real): 范数次数,默认值:2

形状:

  • 输入: ((N, D)),其中D=向量维数
  • 输出: ((N, 1))

>>> pdist = nn.PairwiseDistance(2)>>> input1 = autograd.Variable(torch.randn(100, 128))>>> input2 = autograd.Variable(torch.randn(100, 128))>>> output = pdist(input1, input2)

results matching ""

    No results matching ""