Compute alignment map.
(
self,
tensor_src: torch.Tensor,
tensor_tgt: torch.Tensor,
depth_decoder_features: torch.Tensor | None = None,
)
| 94 | nn.init.constant_(self.conv_out.bias, bias_value) |
| 95 | |
| 96 | def forward( |
| 97 | self, |
| 98 | tensor_src: torch.Tensor, |
| 99 | tensor_tgt: torch.Tensor, |
| 100 | depth_decoder_features: torch.Tensor | None = None, |
| 101 | ) -> torch.Tensor: |
| 102 | """Compute alignment map.""" |
| 103 | # Since the tensors are usually given by depth which is >= 1.0, we invert |
| 104 | # the tensors to have them in a reasonable range. |
| 105 | tensor_src = 1.0 / tensor_src.clamp(min=1e-4) |
| 106 | tensor_tgt = 1.0 / tensor_tgt.clamp(min=1e-4) |
| 107 | tensor_input = torch.cat([tensor_src, tensor_tgt], dim=1) |
| 108 | if self.depth_decoder_features: |
| 109 | height, width = tensor_src.shape[-2:] |
| 110 | upsampled_encodings = F.interpolate( |
| 111 | depth_decoder_features, |
| 112 | size=(height, width), |
| 113 | mode="bilinear", |
| 114 | ) |
| 115 | tensor_input = torch.cat([tensor_input, upsampled_encodings], dim=1) |
| 116 | features = self.encoder(tensor_input) |
| 117 | output = self.conv_out(self.decoder(features)) |
| 118 | alignment_map_lowres = self.activation.forward(output) |
| 119 | if alignment_map_lowres.shape[-2:] != tensor_src.shape[-2]: |
| 120 | alignment_map = F.interpolate( |
| 121 | alignment_map_lowres, |
| 122 | size=tensor_src.shape[-2:], |
| 123 | mode="bilinear", |
| 124 | align_corners=False, |
| 125 | ) |
| 126 | return alignment_map |
nothing calls this directly
no outgoing calls
no test coverage detected