| 54 | |
| 55 | |
| 56 | class Bottleneck(nn.Module): |
| 57 | expansion = 4 |
| 58 | |
| 59 | def __init__(self, inplanes, planes, stride=1, downsample=None): |
| 60 | super(Bottleneck, self).__init__() |
| 61 | self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) |
| 62 | self.bn1 = BatchNorm2d(planes) |
| 63 | self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, |
| 64 | padding=1, bias=False) |
| 65 | self.bn2 = BatchNorm2d(planes) |
| 66 | self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False) |
| 67 | self.bn3 = BatchNorm2d(planes * 4) |
| 68 | self.relu = nn.ReLU(inplace=True) |
| 69 | self.downsample = downsample |
| 70 | self.stride = stride |
| 71 | |
| 72 | def forward(self, x): |
| 73 | residual = x |
| 74 | |
| 75 | out = self.conv1(x) |
| 76 | out = self.bn1(out) |
| 77 | out = self.relu(out) |
| 78 | |
| 79 | out = self.conv2(out) |
| 80 | out = self.bn2(out) |
| 81 | out = self.relu(out) |
| 82 | |
| 83 | out = self.conv3(out) |
| 84 | out = self.bn3(out) |
| 85 | |
| 86 | if self.downsample is not None: |
| 87 | residual = self.downsample(x) |
| 88 | |
| 89 | out += residual |
| 90 | out = self.relu(out) |
| 91 | |
| 92 | return out |
| 93 | |
| 94 | |
| 95 | class ResNet(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected