src.jormungandr.embedder
Classes:
-
DetrLearnedPositionEmbedding–This module learns positional embeddings up to a fixed maximum size.
-
DetrSinePositionEmbedding–This is a more standard version of the position embedding, very similar to the one used by the Attention is all you
DetrLearnedPositionEmbedding
DetrLearnedPositionEmbedding(embedding_dim=256)
Bases: Module, Embedder
This module learns positional embeddings up to a fixed maximum size.
Source code in src/jormungandr/embedder.py
96 97 98 99 | |
DetrSinePositionEmbedding
DetrSinePositionEmbedding(num_position_features: int = 128, temperature: int = 10000, normalize: bool = True, scale: float | None = None)
Bases: Module, Embedder
This is a more standard version of the position embedding, very similar to the one used by the Attention is all you need paper, generalized to work on images.
Methods:
-
forward–Args:
Source code in src/jormungandr/embedder.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
forward
forward(shape: Size, device: device | str, dtype: dtype, mask: Tensor | None = None) -> torch.Tensor
Parameters:
-
(shapeSize) –The shape of the feature maps for which to compute the position embedding, expected to be (batch_size, channels, height, width)
-
(devicedevice | str) –The device on which to create the position embedding
-
(dtypedtype) –The dtype of the position embedding
-
(maskTensor | None, default:None) –An optional mask tensor of shape (batch_size, height, width) where True values indicate masked positions. If None, no positions are masked.
Returns: A position embedding tensor of shape (batch_size, sequence_length, hidden_size) where sequence_length is height * width and hidden_size is num_position_features * 2 (for sine and cosine components)
Source code in src/jormungandr/embedder.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |