pytorch3d.renderer.implicit.sample_pdf

sample_pdf

pytorch3d.renderer.implicit.sample_pdf.sample_pdf(bins: Tensor, weights: Tensor, n_samples: int, det: bool = False, eps: float = 1e-05) Tensor[source]

Samples probability density functions defined by bin edges bins and the non-negative per-bin probabilities weights.

Parameters:
  • bins – Tensor of shape (…, n_bins+1) denoting the edges of the sampling bins.

  • weights – Tensor of shape (…, n_bins) containing non-negative numbers representing the probability of sampling the corresponding bin.

  • n_samples – The number of samples to draw from each set of bins.

  • det – If False, the sampling is random. True yields deterministic uniformly-spaced sampling from the inverse cumulative density function.

  • eps – A constant preventing division by zero in case empty bins are present.

Returns:

samples

Tensor of shape (…, n_samples) containing n_samples samples

drawn from each probability distribution.

Refs:

[1] https://github.com/bmild/nerf/blob/55d8b00244d7b5178f4d003526ab6667683c9da9/run_nerf_helpers.py#L183 # noqa E501

pytorch3d.renderer.implicit.sample_pdf.sample_pdf_python(bins: Tensor, weights: Tensor, N_samples: int, det: bool = False, eps: float = 1e-05) Tensor[source]

This is a pure python implementation of the sample_pdf function. It may be faster than sample_pdf when the number of bins is very large, because it behaves as O(batchsize * [n_bins + log(n_bins) * n_samples] ) whereas sample_pdf behaves as O(batchsize * n_bins * n_samples). For 64 bins sample_pdf is much faster.

Samples probability density functions defined by bin edges bins and the non-negative per-bin probabilities weights.

Note: This is a direct conversion of the TensorFlow function from the original release [1] to PyTorch. It requires PyTorch 1.6 or greater due to the use of torch.searchsorted.

Parameters:
  • bins – Tensor of shape (…, n_bins+1) denoting the edges of the sampling bins.

  • weights – Tensor of shape (…, n_bins) containing non-negative numbers representing the probability of sampling the corresponding bin.

  • N_samples – The number of samples to draw from each set of bins.

  • det – If False, the sampling is random. True yields deterministic uniformly-spaced sampling from the inverse cumulative density function.

  • eps – A constant preventing division by zero in case empty bins are present.

Returns:

samples

Tensor of shape (…, N_samples) containing N_samples samples

drawn from each probability distribution.

Refs:

[1] https://github.com/bmild/nerf/blob/55d8b00244d7b5178f4d003526ab6667683c9da9/run_nerf_helpers.py#L183 # noqa E501