Concatenate x and its positional encodings, following NeRF. Reference: https://arxiv.org/pdf/2210.04628.pdf
(x: torch.Tensor, min_deg: int = 0, max_deg: int = 15)
| 51 | |
| 52 | |
| 53 | def posenc_nerf(x: torch.Tensor, min_deg: int = 0, max_deg: int = 15) -> torch.Tensor: |
| 54 | """ |
| 55 | Concatenate x and its positional encodings, following NeRF. |
| 56 | |
| 57 | Reference: https://arxiv.org/pdf/2210.04628.pdf |
| 58 | """ |
| 59 | if min_deg == max_deg: |
| 60 | return x |
| 61 | |
| 62 | scales = 2.0 ** torch.arange(min_deg, max_deg, dtype=x.dtype, device=x.device) |
| 63 | *shape, dim = x.shape |
| 64 | xb = (x.reshape(-1, 1, dim) * scales.view(1, -1, 1)).reshape(*shape, -1) |
| 65 | assert xb.shape[-1] == dim * (max_deg - min_deg) |
| 66 | emb = torch.cat([xb, xb + math.pi / 2.0], axis=-1).sin() |
| 67 | return torch.cat([x, emb], dim=-1) |
| 68 | |
| 69 | |
| 70 | def encode_position(position): |
no outgoing calls
no test coverage detected