| 38 | |
| 39 | |
| 40 | class BasicBlock(nn.Module): |
| 41 | expansion = 1 |
| 42 | |
| 43 | def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1, |
| 44 | base_width=64, dilation=1, norm_layer=None): |
| 45 | super(BasicBlock, self).__init__() |
| 46 | if norm_layer is None: |
| 47 | norm_layer = nn.BatchNorm2d |
| 48 | if groups != 1 or base_width != 64: |
| 49 | raise ValueError('BasicBlock only supports groups=1 and base_width=64') |
| 50 | if dilation > 1: |
| 51 | raise NotImplementedError("Dilation > 1 not supported in BasicBlock") |
| 52 | # Both self.conv1 and self.downsample layers downsample the input when stride != 1 |
| 53 | self.conv1 = conv3x3(inplanes, planes, stride) |
| 54 | self.bn1 = norm_layer(planes) |
| 55 | self.relu = nn.ReLU(inplace=True) |
| 56 | self.conv2 = conv3x3(planes, planes) |
| 57 | self.bn2 = norm_layer(planes) |
| 58 | self.downsample = downsample |
| 59 | self.stride = stride |
| 60 | |
| 61 | def forward(self, x): |
| 62 | identity = x |
| 63 | |
| 64 | out = self.conv1(x) |
| 65 | out = self.bn1(out) |
| 66 | out = self.relu(out) |
| 67 | |
| 68 | out = self.conv2(out) |
| 69 | out = self.bn2(out) |
| 70 | |
| 71 | if self.downsample is not None: |
| 72 | identity = self.downsample(x) |
| 73 | |
| 74 | out += identity |
| 75 | out = self.relu(out) |
| 76 | |
| 77 | return out |
| 78 | |
| 79 | |
| 80 | class Bottleneck(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected