-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
after latitudeDecoder the latitude_field has asin but in the LM , the latitude_field sin return why?
class LatitudeDecoder(nn.Module):
"""Minimal implementation of LatitudeDecoder."""
def __init__(self):
"""Latitude decoder."""
super().__init__()
self.decoder = LightHamHead()
self.linear_pred_latitude = nn.Conv2d(self.decoder.out_channels, 1, kernel_size=1)
def forward(self, data: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
"""Forward pass."""
x, log_confidence = self.decoder(data["features"])
eps = 1e-5 # avoid nan in backward of asin
lat = torch.tanh(self.linear_pred_latitude(x))
lat = torch.asin(torch.clamp(lat, -1 + eps, 1 - eps))
return {"latitude_field": lat, "latitude_confidence": torch.sigmoid(log_confidence)}
def calculate_residuals(
self, camera: BaseCamera, gravity: Gravity, data: Dict[str, torch.Tensor]
) -> Dict[str, torch.Tensor]:
"""Calculate the residuals for the optimization.
Args:
camera (BaseCamera): Optimized camera.
gravity (Gravity): Optimized gravity.
data (Dict[str, torch.Tensor]): Input data containing the up and latitude fields.
Returns:
Dict[str, torch.Tensor]: Residuals for the optimization.
"""
perspective_up, perspective_lat = get_perspective_field(camera, gravity)
perspective_lat = torch.sin(perspective_lat)
residuals = {}
if "up_field" in data:
up_residual = (data["up_field"] - perspective_up).permute(0, 2, 3, 1)
residuals["up_residual"] = up_residual.reshape(up_residual.shape[0], -1, 2)
if "latitude_field" in data:
target_lat = torch.sin(data["latitude_field"])
lat_residual = (target_lat - perspective_lat).permute(0, 2, 3, 1)
residuals["latitude_residual"] = lat_residual.reshape(lat_residual.shape[0], -1, 1)
return residuals
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels