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