| 12 | |
| 13 | |
| 14 | class BasicBlock(nn.Module): |
| 15 | expansion = 1 |
| 16 | |
| 17 | def __init__(self, in_planes, planes, stride=1): |
| 18 | super(BasicBlock, self).__init__() |
| 19 | self.conv1 = nn.Conv2d( |
| 20 | in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) |
| 21 | self.bn1 = nn.BatchNorm2d(planes) |
| 22 | self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, |
| 23 | stride=1, padding=1, bias=False) |
| 24 | self.bn2 = nn.BatchNorm2d(planes) |
| 25 | |
| 26 | self.shortcut = nn.Sequential() |
| 27 | if stride != 1 or in_planes != self.expansion*planes: |
| 28 | self.shortcut = nn.Sequential( |
| 29 | nn.Conv2d(in_planes, self.expansion*planes, |
| 30 | kernel_size=1, stride=stride, bias=False), |
| 31 | nn.BatchNorm2d(self.expansion*planes) |
| 32 | ) |
| 33 | self.relu = nn.ReLU(inplace=False) |
| 34 | |
| 35 | def forward(self, x): |
| 36 | out = self.relu(self.bn1(self.conv1(x))) |
| 37 | out = self.bn2(self.conv2(out)) |
| 38 | out = out + self.shortcut(x) |
| 39 | out = self.relu(out) |
| 40 | return out |
| 41 | |
| 42 | |
| 43 | class Bottleneck(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected