| 72 | |
| 73 | |
| 74 | class Bottleneck(nn.Module): |
| 75 | # class attribute |
| 76 | expansion = 4 |
| 77 | num_layers = 3 |
| 78 | |
| 79 | def __init__(self, inplanes, planes, stride=1, downsample=None): |
| 80 | super(Bottleneck, self).__init__() |
| 81 | self.conv1 = conv1x1(inplanes, planes) |
| 82 | self.bn1 = nn.BatchNorm2d(planes) |
| 83 | # only conv with possibly not 1 stride |
| 84 | self.conv2 = conv3x3(planes, planes, stride) |
| 85 | self.bn2 = nn.BatchNorm2d(planes) |
| 86 | self.conv3 = conv1x1(planes, planes * self.expansion) |
| 87 | self.bn3 = nn.BatchNorm2d(planes * self.expansion) |
| 88 | self.relu = nn.ReLU(inplace=True) |
| 89 | |
| 90 | # if stride is not 1 then self.downsample cannot be None |
| 91 | self.downsample = downsample |
| 92 | self.stride = stride |
| 93 | |
| 94 | def forward(self, x): |
| 95 | identity = x |
| 96 | |
| 97 | out = self.conv1(x) |
| 98 | out = self.bn1(out) |
| 99 | out = self.relu(out) |
| 100 | |
| 101 | out = self.conv2(out) |
| 102 | out = self.bn2(out) |
| 103 | out = self.relu(out) |
| 104 | |
| 105 | out = self.conv3(out) |
| 106 | out = self.bn3(out) |
| 107 | |
| 108 | if self.downsample is not None: |
| 109 | identity = self.downsample(x) |
| 110 | |
| 111 | out += identity |
| 112 | out = self.relu(out) |
| 113 | |
| 114 | return out |
| 115 | |
| 116 | def block_conv_info(self): |
| 117 | block_kernel_sizes = [1, 3, 1] |
| 118 | block_strides = [1, self.stride, 1] |
| 119 | block_paddings = [0, 1, 0] |
| 120 | |
| 121 | return block_kernel_sizes, block_strides, block_paddings |
| 122 | |
| 123 | |
| 124 | class ResNet_features(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected