MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / init_weights

Method init_weights

semantic_sam/backbone/focal_dw.py:549–573  ·  view source on GitHub ↗

Initialize the weights in backbone. Args: pretrained (str, optional): Path to pre-trained weights. Defaults to None.

(self, pretrained=None)

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected