Reference for ultralytics/nn/modules/utils.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/utils.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.nn.modules.utils._get_clones
ultralytics.nn.modules.utils.bias_init_with_prob
Initialize conv/fc bias value according to a given probability value.
ultralytics.nn.modules.utils.linear_init
Initialize the weights and biases of a linear module.
Source code in ultralytics/nn/modules/utils.py
ultralytics.nn.modules.utils.inverse_sigmoid
Calculate the inverse sigmoid function for a tensor.
ultralytics.nn.modules.utils.multi_scale_deformable_attn_pytorch
multi_scale_deformable_attn_pytorch(
value: Tensor,
value_spatial_shapes: Tensor,
sampling_locations: Tensor,
attention_weights: Tensor,
) -> torch.Tensor
Implement multi-scale deformable attention in PyTorch.
This function performs deformable attention across multiple feature map scales, allowing the model to attend to different spatial locations with learned offsets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Tensor
|
The value tensor with shape (bs, num_keys, num_heads, embed_dims). |
required |
value_spatial_shapes
|
Tensor
|
Spatial shapes of the value tensor with shape (num_levels, 2). |
required |
sampling_locations
|
Tensor
|
The sampling locations with shape (bs, num_queries, num_heads, num_levels, num_points, 2). |
required |
attention_weights
|
Tensor
|
The attention weights with shape (bs, num_queries, num_heads, num_levels, num_points). |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The output tensor with shape (bs, num_queries, embed_dims). |
References
https://github.com/IDEA-Research/detrex/blob/main/detrex/layers/multi_scale_deform_attn.py