| 3 | import torch.nn.functional as F |
| 4 | |
| 5 | class SEBasicBlock(nn.Module): |
| 6 | expansion = 1 |
| 7 | |
| 8 | def __init__(self, inplanes, planes, stride=1, downsample=None, reduction=8): |
| 9 | super(SEBasicBlock, self).__init__() |
| 10 | self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=stride, padding=1, bias=False) |
| 11 | self.bn1 = nn.BatchNorm2d(planes) |
| 12 | self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False) |
| 13 | self.bn2 = nn.BatchNorm2d(planes) |
| 14 | self.relu = nn.ReLU(inplace=True) |
| 15 | self.se = SELayer(planes, reduction) |
| 16 | self.downsample = downsample |
| 17 | self.stride = stride |
| 18 | |
| 19 | def forward(self, x): |
| 20 | residual = x |
| 21 | |
| 22 | out = self.conv1(x) |
| 23 | out = self.relu(out) |
| 24 | out = self.bn1(out) |
| 25 | |
| 26 | out = self.conv2(out) |
| 27 | out = self.bn2(out) |
| 28 | out = self.se(out) |
| 29 | |
| 30 | if self.downsample is not None: |
| 31 | residual = self.downsample(x) |
| 32 | |
| 33 | out += residual |
| 34 | out = self.relu(out) |
| 35 | return out |
| 36 | |
| 37 | class SELayer(nn.Module): |
| 38 | def __init__(self, channel, reduction=8): |
nothing calls this directly
no outgoing calls
no test coverage detected