CoolFace
Apppublic

procgne/Plonk

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
postprocessing.py24 linesDownload Raw Back to models
1import torch.nn as nn2import torch3import numpy as np4 5class UnormGPS(nn.Module):6    def __init__(self):7        super().__init__()8        self.register_buffer("gps_normalize", torch.Tensor([np.pi * 0.5, np.pi]).unsqueeze(0))9 10    def forward(self, x):11        """Unormalize latitude longtitude radians to -1, 1."""12        x = torch.clamp(x, -1, 1)13        return x * self.gps_normalize14 15class CartesiantoGPS(nn.Module):16    def __init__(self):17        super().__init__()18    def forward(self, cartesian):19        x = cartesian[:, 0]20        y = cartesian[:, 1]21        z = cartesian[:, 2]22        lat = z.arcsin()23        lon = y.atan2(x)24        return torch.stack([lat, lon], dim=-1)