MCPcopy Create free account
hub / github.com/geekcomputers/Python / SpatialAttention

Class SpatialAttention

ML/src/python/neuralforge/nn/modules.py:167–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165 return x * se.view(b, c, 1, 1)
166
167class SpatialAttention(nn.Module):
168 def __init__(self, kernel_size=7):
169 super().__init__()
170 self.conv = nn.Conv2d(2, 1, kernel_size, padding=kernel_size // 2)
171
172 def forward(self, x):
173 avg_out = torch.mean(x, dim=1, keepdim=True)
174 max_out, _ = torch.max(x, dim=1, keepdim=True)
175 attention = torch.cat([avg_out, max_out], dim=1)
176 attention = torch.sigmoid(self.conv(attention))
177 return x * attention
178
179class CBAM(nn.Module):
180 def __init__(self, channels, reduction=16, kernel_size=7):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected