| 34 | |
| 35 | |
| 36 | class Bottleneck(nn.Module): |
| 37 | expansion = 4 |
| 38 | |
| 39 | def __init__(self, in_planes, planes, stride=1, wide=1): |
| 40 | super(Bottleneck, self).__init__() |
| 41 | mid_planes = planes * wide |
| 42 | self.conv1 = nn.Conv2d(in_planes, mid_planes, kernel_size=1, bias=False) |
| 43 | self.bn1 = nn.BatchNorm2d(mid_planes) |
| 44 | self.conv2 = nn.Conv2d(mid_planes, mid_planes, kernel_size=3, stride=stride, padding=1, bias=False) |
| 45 | self.bn2 = nn.BatchNorm2d(mid_planes) |
| 46 | self.conv3 = nn.Conv2d(mid_planes, self.expansion*planes, kernel_size=1, bias=False) |
| 47 | self.bn3 = nn.BatchNorm2d(self.expansion*planes) |
| 48 | |
| 49 | self.shortcut = nn.Sequential() |
| 50 | if stride != 1 or in_planes != self.expansion*planes: |
| 51 | self.shortcut = nn.Sequential( |
| 52 | nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False), |
| 53 | nn.BatchNorm2d(self.expansion*planes) |
| 54 | ) |
| 55 | |
| 56 | def forward(self, x): |
| 57 | out = F.relu(self.bn1(self.conv1(x))) |
| 58 | out = F.relu(self.bn2(self.conv2(out))) |
| 59 | out = self.bn3(self.conv3(out)) |
| 60 | out += self.shortcut(x) |
| 61 | out = F.relu(out) |
| 62 | return out |
| 63 | |
| 64 | |
| 65 | class ResNet(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected