Initialize the weights in backbone. Args: pretrained (str, optional): Path to pre-trained weights. Defaults to None.
(self, pretrained=None)
| 547 | param.requires_grad = False |
| 548 | |
| 549 | def init_weights(self, pretrained=None): |
| 550 | """Initialize the weights in backbone. |
| 551 | |
| 552 | Args: |
| 553 | pretrained (str, optional): Path to pre-trained weights. |
| 554 | Defaults to None. |
| 555 | """ |
| 556 | |
| 557 | def _init_weights(m): |
| 558 | if isinstance(m, nn.Linear): |
| 559 | trunc_normal_(m.weight, std=.02) |
| 560 | if isinstance(m, nn.Linear) and m.bias is not None: |
| 561 | nn.init.constant_(m.bias, 0) |
| 562 | elif isinstance(m, nn.LayerNorm): |
| 563 | nn.init.constant_(m.bias, 0) |
| 564 | nn.init.constant_(m.weight, 1.0) |
| 565 | |
| 566 | if isinstance(pretrained, str): |
| 567 | self.apply(_init_weights) |
| 568 | logger = get_root_logger() |
| 569 | load_checkpoint(self, pretrained, strict=False, logger=logger) |
| 570 | elif pretrained is None: |
| 571 | self.apply(_init_weights) |
| 572 | else: |
| 573 | raise TypeError('pretrained must be a str or None') |
| 574 | |
| 575 | def load_weights(self, pretrained_dict=None, pretrained_layers=[], verbose=True): |
| 576 | model_dict = self.state_dict() |
nothing calls this directly
no outgoing calls
no test coverage detected