ding.torch_utils.network.soft_argmax¶
ding.torch_utils.network.soft_argmax
¶
SoftArgmax
¶
Bases: Module
Overview
A neural network module that computes the SoftArgmax operation (essentially a 2-dimensional spatial softmax), which is often used for location regression tasks. It converts a feature map (such as a heatmap) into precise coordinate locations.
Interfaces:
__init__, forward
.. note:: For more information on SoftArgmax, you can refer to https://en.wikipedia.org/wiki/Softmax_function and the paper https://arxiv.org/pdf/1504.00702.pdf.
__init__()
¶
Overview
Initialize the SoftArgmax module.
forward(x)
¶
Overview
Perform the forward pass of the SoftArgmax operation.
Arguments:
- x (:obj:torch.Tensor): The input tensor, typically a heatmap representing predicted locations.
Returns:
- location (:obj:torch.Tensor): The predicted coordinates as a result of the SoftArgmax operation.
Shapes:
- x: :math:(B, C, H, W), where B is the batch size, C is the number of channels, and H and W represent height and width respectively.
- location: :math:(B, 2), where B is the batch size and 2 represents the coordinates (height, width).
Full Source Code
../ding/torch_utils/network/soft_argmax.py