| 203 | nn.init.constant_(m.bn2.weight, 0) # type: ignore[arg-type] |
| 204 | |
| 205 | def _make_layer(self, block: Type[Union[BasicBlock, Bottleneck]], planes: int, blocks: int, |
| 206 | stride: int = 1, dilate: bool = False) -> nn.Sequential: |
| 207 | norm_layer = self._norm_layer |
| 208 | downsample = None |
| 209 | previous_dilation = self.dilation |
| 210 | if dilate: |
| 211 | self.dilation *= stride |
| 212 | stride = 1 |
| 213 | if stride != 1 or self.inplanes != planes * block.expansion: |
| 214 | downsample = nn.Sequential( |
| 215 | conv1x1(self.inplanes, planes * block.expansion, stride), |
| 216 | norm_layer(planes * block.expansion), |
| 217 | ) |
| 218 | |
| 219 | layers = [] |
| 220 | layers.append(block(self.inplanes, planes, stride, downsample, self.groups, |
| 221 | self.base_width, previous_dilation, norm_layer)) |
| 222 | self.inplanes = planes * block.expansion |
| 223 | for _ in range(1, blocks): |
| 224 | layers.append(block(self.inplanes, planes, groups=self.groups, |
| 225 | base_width=self.base_width, dilation=self.dilation, |
| 226 | norm_layer=norm_layer)) |
| 227 | |
| 228 | return nn.Sequential(*layers) |
| 229 | |
| 230 | def _forward_impl(self, x: Tensor) -> Tensor: |
| 231 | # See note [TorchScript super()] |