File size: 267 Bytes
32408ed
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
"""Layers producing a 2D attention map from a feature map"""

from torch import nn


class L2Attention(nn.Module):
    """Compute the attention as L2-norm of local descriptors"""

    def forward(self, x):
        return (x.pow(2.0).sum(1) + 1e-10).sqrt().squeeze(0)