py123d_detection.torch.models.petr.positional_encoding

Classes

SinePositionalEncoding3D(*args, **kwargs)

Position encoding with sine and cosine functions.

class py123d_detection.torch.models.petr.positional_encoding.SinePositionalEncoding3D(*args: Any, **kwargs: Any)[source]

Bases: Module

Position encoding with sine and cosine functions.

Adapted from mmcv’s SinePositionalEncoding, extended to three axes. See End-to-End Object Detection with Transformers for the original.

Parameters:
  • num_feats – Feature dimension per position and per axis. The returned dimension is twice this, because each axis contributes a sine and a cosine.

  • temperature – Scaling of the position embedding.

  • normalize – Normalise the embedding by the extent of the unmasked region.

  • scale – Factor applied to the normalised embedding; used only when normalize is set.

  • eps – Added to the denominator for numerical stability.

  • offset – Added to the embedding before normalising.

forward(mask)[source]
Parameters:

mask – [bs, h, w], non-zero where a position is to be ignored.

Returns:

The position embedding, [bs, num_feats * 2, h, w].