Initialize the weights in backbone. Args: pretrained (str, optional): Path to pre-trained weights. Defaults to None.
(self, pretrained=None)
| 435 | param.requires_grad = False |
| 436 | |
| 437 | def init_weights(self, pretrained=None): |
| 438 | """Initialize the weights in backbone. |
| 439 | |
| 440 | Args: |
| 441 | pretrained (str, optional): Path to pre-trained weights. |
| 442 | Defaults to None. |
| 443 | """ |
| 444 | |
| 445 | def _init_weights(m): |
| 446 | if isinstance(m, nn.Linear): |
| 447 | trunc_normal_(m.weight, std=.02) |
| 448 | if isinstance(m, nn.Linear) and m.bias is not None: |
| 449 | nn.init.constant_(m.bias, 0) |
| 450 | elif isinstance(m, nn.LayerNorm): |
| 451 | nn.init.constant_(m.bias, 0) |
| 452 | nn.init.constant_(m.weight, 1.0) |
| 453 | |
| 454 | if isinstance(pretrained, str): |
| 455 | self.apply(_init_weights) |
| 456 | logger_ = get_root_logger() |
| 457 | load_checkpoint(self, pretrained, strict=('upernet' in pretrained), logger=None) |
| 458 | logger.info('loading swin success !!!') |
| 459 | elif pretrained is None: |
| 460 | self.apply(_init_weights) |
| 461 | else: |
| 462 | raise TypeError('pretrained must be a str or None') |
| 463 | |
| 464 | def forward(self, x, l, l_mask): |
| 465 | """Forward function.""" |
no test coverage detected