MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / ChannelAttention

Class ChannelAttention

PATH/core/models/necks/attention.py:51–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51class ChannelAttention(nn.Module):
52 def __init__(self,channel,reduction=16):
53 super().__init__()
54 self.maxpool=nn.AdaptiveMaxPool2d(1)
55 self.avgpool=nn.AdaptiveAvgPool2d(1)
56 self.se=nn.Sequential(
57 nn.Conv2d(channel,channel//reduction,1,bias=False),
58 nn.ReLU(),
59 nn.Conv2d(channel//reduction,channel,1,bias=False)
60 )
61 self.sigmoid=nn.Sigmoid()
62
63 def forward(self, x) :
64 max_result=self.maxpool(x)
65 avg_result=self.avgpool(x)
66 max_out=self.se(max_result)
67 avg_out=self.se(avg_result)
68 output=self.sigmoid(max_out+avg_out)
69 return output
70
71class SpatialAttention(nn.Module):
72 def __init__(self,kernel_size=7):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected