MCPcopy Create free account
hub / github.com/ZHKKKe/MODNet / SEBlock

Class SEBlock

torchscript/modnet_torchscript.py:66–85  ·  view source on GitHub ↗

SE Block Proposed in https://arxiv.org/pdf/1709.01507.pdf

Source from the content-addressed store, hash-verified

64
65
66class SEBlock(nn.Module):
67 """ SE Block Proposed in https://arxiv.org/pdf/1709.01507.pdf
68 """
69
70 def __init__(self, in_channels, out_channels, reduction=1):
71 super(SEBlock, self).__init__()
72 self.pool = nn.AdaptiveAvgPool2d(1)
73 self.fc = nn.Sequential(
74 nn.Linear(in_channels, int(in_channels // reduction), bias=False),
75 nn.ReLU(inplace=True),
76 nn.Linear(int(in_channels // reduction), out_channels, bias=False),
77 nn.Sigmoid()
78 )
79
80 def forward(self, x):
81 b, c, _, _ = x.size()
82 w = self.pool(x).view(b, c)
83 w = self.fc(w).view(b, c, 1, 1)
84
85 return x * w.expand_as(x)
86
87
88#------------------------------------------------------------------------------

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected