(
self,
block,
layers=[2, 2, 2, 2],
num_classes=1000,
zero_init_residual=False,
groups=1,
width_per_group=64,
replace_stride_with_dilation=None,
norm=M.BatchNorm2d,
)
| 284 | |
| 285 | class ResNet(M.Module): |
| 286 | def __init__( |
| 287 | self, |
| 288 | block, |
| 289 | layers=[2, 2, 2, 2], |
| 290 | num_classes=1000, |
| 291 | zero_init_residual=False, |
| 292 | groups=1, |
| 293 | width_per_group=64, |
| 294 | replace_stride_with_dilation=None, |
| 295 | norm=M.BatchNorm2d, |
| 296 | ): |
| 297 | super().__init__() |
| 298 | self.in_channels = 64 |
| 299 | self.dilation = 1 |
| 300 | if replace_stride_with_dilation is None: |
| 301 | # each element in the tuple indicates if we should replace |
| 302 | # the 2x2 stride with a dilated convolution instead |
| 303 | replace_stride_with_dilation = [False, False, False] |
| 304 | if len(replace_stride_with_dilation) != 3: |
| 305 | raise ValueError( |
| 306 | "replace_stride_with_dilation should be None " |
| 307 | "or a 3-element tuple, got {}".format(replace_stride_with_dilation) |
| 308 | ) |
| 309 | self.groups = groups |
| 310 | self.base_width = width_per_group |
| 311 | self.conv1 = M.Conv2d( |
| 312 | 3, self.in_channels, kernel_size=7, stride=2, padding=3, bias=False |
| 313 | ) |
| 314 | self.bn1 = norm(self.in_channels) |
| 315 | self.maxpool = M.MaxPool2d(kernel_size=3, stride=2, padding=1) |
| 316 | |
| 317 | self.layer1_0 = BasicBlock( |
| 318 | self.in_channels, |
| 319 | 64, |
| 320 | stride=1, |
| 321 | groups=self.groups, |
| 322 | base_width=self.base_width, |
| 323 | dilation=self.dilation, |
| 324 | norm=M.BatchNorm2d, |
| 325 | ) |
| 326 | self.layer1_1 = BasicBlock( |
| 327 | self.in_channels, |
| 328 | 64, |
| 329 | stride=1, |
| 330 | groups=self.groups, |
| 331 | base_width=self.base_width, |
| 332 | dilation=self.dilation, |
| 333 | norm=M.BatchNorm2d, |
| 334 | ) |
| 335 | self.layer2_0 = BasicBlock(64, 128, stride=2) |
| 336 | self.layer2_1 = BasicBlock(128, 128) |
| 337 | self.layer3_0 = BasicBlock(128, 256, stride=2) |
| 338 | self.layer3_1 = BasicBlock(256, 256) |
| 339 | self.layer4_0 = BasicBlock(256, 512, stride=2) |
| 340 | self.layer4_1 = BasicBlock(512, 512) |
| 341 | |
| 342 | self.layer1 = self._make_layer(block, 64, layers[0], norm=norm) |
| 343 | self.layer2 = self._make_layer( |
nothing calls this directly
no test coverage detected