xwr.nn
¶
Radar preprocessing toolkit for neural network training.
Warning
This submodule requires torch
and torchvision
to be installed, e.g. via
the nn
extra.
Tip
This submodule supports both np.ndarray
and torch.Tensor
inputs
directly out-of-the box (with no additional overhead, since we already
require torch
to handle resizing).
When converting complex spectrum to real-valued representations, we can apply
a range of different data augmentations. The supported data augmentations
according to the
abstract_dataloader.ext.augment
conventions are:
Augmentation Key | Description |
---|---|
azimuth_flip |
Flip along azimuth axis. |
doppler_flip |
Flip along doppler axis. |
range_scale |
Apply random range scale. |
speed_scale |
Apply random speed scale. |
radar_scale |
Radar magnitude scale factor. |
radar_phase |
Phase shift across the frame. |
Sample Hydra Configuration for abstract_dataloader.ext.augment
_target_: abstract_dataloader.ext.augment.Augmentations
azimuth_flip:
_target_: abstract_dataloader.ext.augment.Bernoulli
p: 0.5
doppler_flip:
_target_: abstract_dataloader.ext.augment.Bernoulli
p: 0.5
radar_scale:
_target_: abstract_dataloader.ext.augment.TruncatedLogNormal
std: 0.2
clip: 2.0
radar_phase:
_target_: abstract_dataloader.ext.augment.Uniform
lower: -3.14159265
upper: 3.14159265
range_scale:
_target_: abstract_dataloader.ext.augment.Uniform
lower: 1.0
upper: 2.0
speed_scale:
_target_: abstract_dataloader.ext.augment.TruncatedLogNormal
std: 0.2
clip: 2.0
xwr.nn.Magnitude
¶
Bases: Representation
Real spectrum magnitude with phase discarded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale factor to apply to the magnitude. |
1e-06
|
transform
|
Literal['log', 'sqrt', 'linear']
|
transformation to apply to the magnitude. |
'sqrt'
|
eps
|
float
|
small value to avoid log(0) in log transform. |
1e-06
|
Source code in src/xwr/nn/representations.py
__call__
¶
__call__(
spectrum: Complex64[TArray, "batch doppler el az rng"],
aug: Mapping[str, Any] = {},
) -> Float32[TArray, "batch doppler el az rng 1"]
Get spectrum amplitude.
Type Parameters
TArray
: array type;np.ndarray
ortorch.Tensor
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
Complex64[TArray, 'batch doppler el az rng']
|
complex spectrum as output by one of the
|
required |
aug
|
Mapping[str, Any]
|
augmentations to apply. |
{}
|
Returns:
Type | Description |
---|---|
Float32[TArray, 'batch doppler el az rng 1']
|
Real 4D spectrum with a leading batch axis and trailing
|
Source code in src/xwr/nn/representations.py
xwr.nn.PhaseAngle
¶
Bases: Representation
Complex spectrum with magnitude and phase angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale factor to apply to the magnitude. |
1e-06
|
transform
|
Literal['log', 'sqrt', 'linear']
|
transformation to apply to the magnitude. |
'sqrt'
|
eps
|
float
|
small value to avoid log(0) in log transform. |
1e-06
|
Source code in src/xwr/nn/representations.py
__call__
¶
__call__(
spectrum: Complex64[TArray, "batch doppler el az rng"],
aug: Mapping[str, Any] = {},
) -> Float32[TArray, "batch doppler el az rng 2"]
Get complex spectrum representation.
Type Parameters
TArray
: array type;np.ndarray
ortorch.Tensor
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
Complex64[TArray, 'batch doppler el az rng']
|
complex spectrum as output by one of the
|
required |
aug
|
Mapping[str, Any]
|
augmentations to apply. |
{}
|
Returns:
Type | Description |
---|---|
Float32[TArray, 'batch doppler el az rng 2']
|
Complex 4D spectrum with a leading batch axis and trailing
|
Source code in src/xwr/nn/representations.py
xwr.nn.PhaseVec
¶
Bases: Representation
Complex spectrum with magnitude and re/im phase vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale factor to apply to the magnitude. |
1e-06
|
transform
|
Literal['log', 'sqrt', 'linear']
|
transformation to apply to the magnitude. |
'sqrt'
|
eps
|
float
|
small value to avoid log(0) in log transform. |
1e-06
|
Source code in src/xwr/nn/representations.py
__call__
¶
__call__(
spectrum: Complex64[TArray, "batch doppler el az rng"],
aug: Mapping[str, Any] = {},
) -> Float32[TArray, "batch doppler el az rng 3"]
Get amplitude spectrum.
Type Parameters
TArray
: array type;np.ndarray
ortorch.Tensor
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
Complex64[TArray, 'batch doppler el az rng']
|
complex spectrum as output by one of the
|
required |
aug
|
Mapping[str, Any]
|
augmentations to apply. |
{}
|
Returns:
Type | Description |
---|---|
Float32[TArray, 'batch doppler el az rng 3']
|
Real 4D spectrum with a leading batch axis and trailing
|
Source code in src/xwr/nn/representations.py
xwr.nn.Representation
¶
Bases: ABC
Generic representation which maps complex spectrum to real channels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale
|
float
|
scale factor to apply to the magnitude. |
1e-06
|
transform
|
Literal['log', 'sqrt', 'linear']
|
transformation to apply to the magnitude. |
'sqrt'
|
eps
|
float
|
small value to avoid log(0) in log transform. |
1e-06
|
Source code in src/xwr/nn/representations.py
__call__
abstractmethod
¶
__call__(
spectrum: Complex64[TArray, "batch doppler el az rng"],
aug: Mapping[str, Any] = {},
) -> Float32[TArray, "batch doppler el az rng c"]
Get spectrum representation.
Type Parameters
TArray
: array type;np.ndarray
ortorch.Tensor
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
Complex64[TArray, 'batch doppler el az rng']
|
complex spectrum as output by one of the
|
required |
aug
|
Mapping[str, Any]
|
dictionary of augmentations to apply. |
{}
|
Returns:
Type | Description |
---|---|
Float32[TArray, 'batch doppler el az rng c']
|
Real 4D spectrum with a leading batch axis and trailing channel axis. |
Source code in src/xwr/nn/representations.py
xwr.nn.resize
¶
resize(
spectrum: Float32[TArray, "T D *A R"],
range_scale: float = 1.0,
speed_scale: float = 1.0,
) -> Float32[TArray, "T D *A R"]
Resize range-Doppler spectrum.
Note
We use torchvision.transforms.Resize
, which requires a
round-trip through a (cpu) Tensor
for numpy arrays. From some limited
testing, this appears to be the most performant image resizing which
supports antialiasing, with skimage.transform.resize
being
particularly slow.
Type Parameters
TArray
: array type;np.ndarray
ortorch.Tensor
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
Float32[TArray, 'T D *A R']
|
input spectrum as a real channel; should be output by one of
the |
required |
range_scale
|
float
|
scale factor for the range dimension; crops if greater than 1.0, and zero-pads if less than 1.0. |
1.0
|
speed_scale
|
float
|
scale factor for the Doppler dimension; wraps if greater than 1.0, and zero-pads if less than 1.0. |
1.0
|