Displacement¶
- class src.displacement_layer.Displacement[source]¶
Displacement Layer computes the displacement vector for each point in the source image, with its corresponding point (or points) in target image.
The output is a displacement matrix constructed from all displacement vectors. This metric measures the shift from source point to predicted target point, and can be applied for matching accuracy.
Together with displacement matrix d, this function will also return a grad_mask, which helps to filter out dummy nodes in practice.
\[\mathbf{d}_i = \sum_{j \in V_2} \left( \mathbf{S}_{i, j} P_{2j} \right)- P_{1i}\]Proposed by “Zanfir et al. Deep Learning of Graph Matching. CVPR 2018.”
- forward(s: torch.Tensor, P_src: torch.Tensor, P_tgt: torch.Tensor, ns_gt: Optional[torch.Tensor] = None)[source]¶
- Parameters
s – \((b\times n_1 \times n_2)\) permutation or doubly stochastic matrix. \(b\): batch size. \(n_1\): number of nodes in source image. \(n_2\): number of nodes in target image
P_src – \((b\times n_1 \times 2)\) point set on source image
P_tgt – \((b\times n_2 \times 2)\) point set on target image
ns_gt – \((b)\) number of exact pairs. We support batched instances with different number of nodes, therefore
ns_gt
is required to specify the exact number of nodes of each instance in the batch.
- Returns
displacement matrix d, mask for dummy nodes grad_mask. If
ns_gt=None
, it will not be calculated and None is returned.
- training: bool¶