Initialize the weights in backbone. Args: pretrained (str, optional): Path to pre-trained weights. Defaults to None.
(self, pretrained=None)
| 450 | param.requires_grad = False |
| 451 | |
| 452 | def init_weights(self, pretrained=None): |
| 453 | """Initialize the weights in backbone. |
| 454 | |
| 455 | Args: |
| 456 | pretrained (str, optional): Path to pre-trained weights. |
| 457 | Defaults to None. |
| 458 | """ |
| 459 | |
| 460 | def _init_weights(m): |
| 461 | if isinstance(m, nn.Linear): |
| 462 | trunc_normal_(m.weight, std=.02) |
| 463 | if isinstance(m, nn.Linear) and m.bias is not None: |
| 464 | nn.init.constant_(m.bias, 0) |
| 465 | elif isinstance(m, nn.LayerNorm): |
| 466 | nn.init.constant_(m.bias, 0) |
| 467 | nn.init.constant_(m.weight, 1.0) |
| 468 | |
| 469 | if isinstance(pretrained, str): |
| 470 | self.apply(_init_weights) |
| 471 | logger = get_root_logger() |
| 472 | load_checkpoint(self, pretrained, strict=False, logger=logger) |
| 473 | elif pretrained is None: |
| 474 | self.apply(_init_weights) |
| 475 | else: |
| 476 | raise TypeError('pretrained must be a str or None') |
| 477 | |
| 478 | def load_weights(self, pretrained_dict=None, pretrained_layers=[], verbose=True): |
| 479 | model_dict = self.state_dict() |
nothing calls this directly
no outgoing calls
no test coverage detected