Encodings#

Encoding functions

class nerfstudio.field_components.encodings.Encoding(in_dim: int)#

Bases: FieldComponent

Encode an input tensor. Intended to be subclassed

Parameters:

in_dim – Input dimension of tensor

abstract forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

class nerfstudio.field_components.encodings.HashEncoding(num_levels: int = 16, min_res: int = 16, max_res: int = 1024, log2_hashmap_size: int = 19, features_per_level: int = 2, hash_init_scale: float = 0.001, implementation: Literal['tcnn', 'torch'] = 'tcnn', interpolation: Optional[Literal['Nearest', 'Linear', 'Smoothstep']] = None)#

Bases: Encoding

Hash encoding

Parameters:
  • num_levels – Number of feature grids.

  • min_res – Resolution of smallest feature grid.

  • max_res – Resolution of largest feature grid.

  • log2_hashmap_size – Size of hash map is 2^log2_hashmap_size.

  • features_per_level – Number of features per level.

  • hash_init_scale – Value to initialize hash grid.

  • implementation – Implementation of hash encoding. Fallback to torch if tcnn not available.

  • interpolation – Interpolation override for tcnn hashgrid. Not supported for torch unless linear.

forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

get_out_dim() int#

Calculates output dimension of encoding.

hash_fn(in_tensor: Tensor) Tensor#

Returns hash tensor using method described in Instant-NGP

Parameters:

in_tensor – Tensor to be hashed

pytorch_fwd(in_tensor: Tensor) Tensor#

Forward pass using pytorch. Significantly slower than TCNN implementation.

class nerfstudio.field_components.encodings.Identity(in_dim: int)#

Bases: Encoding

Identity encoding (Does not modify input)

forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

get_out_dim() int#

Calculates output dimension of encoding.

class nerfstudio.field_components.encodings.NeRFEncoding(in_dim: int, num_frequencies: int, min_freq_exp: float, max_freq_exp: float, include_input: bool = False)#

Bases: Encoding

Multi-scale sinusoidal encodings. Support integrated positional encodings if covariances are provided. Each axis is encoded with frequencies ranging from 2^min_freq_exp to 2^max_freq_exp.

Parameters:
  • in_dim – Input dimension of tensor

  • num_frequencies – Number of encoded frequencies per axis

  • min_freq_exp – Minimum frequency exponent

  • max_freq_exp – Maximum frequency exponent

  • include_input – Append the input coordinate to the encoding

forward(in_tensor: Tensor, covs: Optional[Tensor] = None) Tensor#
Calculates NeRF encoding. If covariances are provided the encodings will be integrated as proposed

in mip-NeRF.

Parameters:
  • in_tensor – For best performance, the input tensor should be between 0 and 1.

  • covs – Covariances of input points.

Returns:

Output values will be between -1 and 1

get_out_dim() int#

Calculates output dimension of encoding.

class nerfstudio.field_components.encodings.RFFEncoding(in_dim: int, num_frequencies: int, scale: float, include_input: bool = False)#

Bases: Encoding

Random Fourier Feature encoding. Supports integrated encodings.

Parameters:
  • in_dim – Input dimension of tensor

  • num_frequencies – Number of encoding frequencies

  • scale – Std of Gaussian to sample frequencies. Must be greater than zero

  • include_input – Append the input coordinate to the encoding

forward(in_tensor: Tensor, covs: Optional[Tensor] = None) Tensor#
Calculates RFF encoding. If covariances are provided the encodings will be integrated as proposed

in mip-NeRF.

Parameters:
  • in_tensor – For best performance, the input tensor should be between 0 and 1.

  • covs – Covariances of input points.

Returns:

Output values will be between -1 and 1

get_out_dim() int#

Calculates output dimension of encoding.

class nerfstudio.field_components.encodings.SHEncoding(levels: int = 4)#

Bases: Encoding

Spherical harmonic encoding

Parameters:

levels – Number of spherical harmonic levels to encode.

forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

get_out_dim() int#

Calculates output dimension of encoding.

class nerfstudio.field_components.encodings.ScalingAndOffset(in_dim: int, scaling: float = 1.0, offset: float = 0.0)#

Bases: Encoding

Simple scaling and offset to input

Parameters:
  • in_dim – Input dimension of tensor

  • scaling – Scaling applied to tensor.

  • offset – Offset applied to tensor.

forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

get_out_dim() int#

Calculates output dimension of encoding.

class nerfstudio.field_components.encodings.TensorCPEncoding(resolution: int = 256, num_components: int = 24, init_scale: float = 0.1)#

Bases: Encoding

Learned CANDECOMP/PARFAC (CP) decomposition encoding used in TensoRF

Parameters:
  • resolution – Resolution of grid.

  • num_components – Number of components per dimension.

  • init_scale – Initialization scale.

forward(in_tensor: Tensor) Tensor#

Call forward and returns and processed tensor

Parameters:

in_tensor – the input tensor to process

get_out_dim() int#

Calculates output dimension of encoding.

upsample_grid(resolution: int) None#

Upsamples underyling feature grid

Parameters:

resolution – Target resolution.

class nerfstudio.field_components.encodings.TensorVMEncoding(resolution: int = 128, num_components: int = 24, init_scale: float = 0.1)#

Bases: Encoding

Learned vector-matrix encoding proposed by TensoRF

Parameters:
  • resolution – Resolution of grid.

  • num_components – Number of components per dimension.

  • init_scale – Initialization scale.

forward(in_tensor: Tensor) Tensor#

Compute encoding for each position in in_positions

Parameters:

in_tensor – position inside bounds in range [-1,1],

Returns: Encoded position

get_out_dim() int#

Calculates output dimension of encoding.

upsample_grid(resolution: int) None#

Upsamples underlying feature grid

Parameters:

resolution – Target resolution.