grt.models
¶
GRT building blocks.
Use TransformerEncoder
as the GRT encoder
The GRT encoder is just a vanilla transformer encoder! If you're using hydra, use the following:
encoder:
_target_: torch.nn.TransformerEncoder
encoder_layer:
_target_: torch.nn.TransformerEncoderLayer
d_model: 512
nhead: 8
dim_feedforward: 2048
dropout: 0.1
activation: gelu
layer_norm_eps: 1e-5
batch_first: true
norm_first: true
bias: true
num_layers: 4
enable_nested_tensor: false
d_model
and num_layers
:
- Set
dim_feedforward
to4.0 * d_model
- Set
n_head
tod_model // 64
grt.models.SpectrumTokenizer
¶
Bases: Module
GRT 4D Radar Spectrum tokenizer.
Two types of positional embeddings are supported:
nd
(recommended): n-dimensional embeddings, splitting the input features intod
equal chunks encoding each axis separately.flat
: flattened positional embeddings, similar to the original ViT.
Info
We use a relative coordinate system for positional embeddings instead
of absolute position indices, where each axis is scaled to [-1, 1]
by
default and scaled by pos_scale
and global_scale
factors; see
modules.Sinusoid
for details.
Warning
Any axes specified in squeeze
must have a patch size which is equal
to the input size along that axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d_model
|
int
|
model feature dimension. |
768
|
patch
|
Sequence[int]
|
input (doppler, azimuth, elevation, range) patch size. |
(1, 2, 2, 8, 4)
|
squeeze
|
Sequence[int]
|
eliminate these axes by moving them to the channel axis prior to patching; specified by index. |
[]
|
n_channels
|
int
|
number of input channels; see |
2
|
scale
|
Sequence[float] | float | None
|
position embedding scale. |
None
|
w_min
|
Sequence[float] | float | None
|
minimum frequency for sinusoidal position embeddings. |
0.2
|
positions
|
Literal['flat', 'nd']
|
type of positional embedding. |
'nd'
|
Source code in grt/grt/models.py
forward
¶
forward(spectrum: SpectrumData) -> Float[Tensor, 'n s c']
Apply radar transformer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
SpectrumData
|
input batch spectrum data. |
required |
Returns:
Type | Description |
---|---|
Float[Tensor, 'n s c']
|
Tokenized output. |