Created
May 18, 2024 09:55
-
-
Save sergeyprokudin/9db387861ff5452a64f2463f52c331e7 to your computer and use it in GitHub Desktop.
Simple NeRF positional embedding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple positional embedding (NeRF style) | |
# as in https://arxiv.org/pdf/2003.08934 (Equation 4) | |
def positional_embedding(x, k): | |
batch_size, n_dims = x.shape | |
x_rep = x.unsqueeze(-1).expand(-1, -1, k) | |
k_pows = torch.pow(2, torch.arange(0, k, device=x.device)).view(1, 1, k) | |
x_k = k_pows * torch.pi * x_rep | |
x_pos = torch.cat([torch.sin(x_k), torch.cos(x_k)], dim=-1) | |
return x_pos.view(batch_size, -1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment