MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / posenc_nerf

Function posenc_nerf

diffusers/src/diffusers/pipelines/shap_e/renderer.py:53–67  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

51
52
53def 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
70def encode_position(position):

Callers 2

encode_positionFunction · 0.85
encode_directionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected