MCPcopy Create free account
hub / github.com/MotrixLab/ADHMR / init_weights

Method init_weights

ADHMR/lib/models/hrnet.py:604–648  ·  view source on GitHub ↗
(self, pretrained='')

Source from the content-addressed store, hash-verified

602 return fmap,pred_shape,pred_2d
603
604 def init_weights(self, pretrained=''):
605 logger.info('=> init weights from normal distribution')
606 for m in self.modules():
607 if isinstance(m, nn.Conv2d):
608 # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
609 nn.init.normal_(m.weight, std=0.001)
610 for name, _ in m.named_parameters():
611 if name in ['bias']:
612 nn.init.constant_(m.bias, 0)
613 elif isinstance(m, nn.BatchNorm2d):
614 nn.init.constant_(m.weight, 1)
615 nn.init.constant_(m.bias, 0)
616 elif isinstance(m, nn.ConvTranspose2d):
617 nn.init.normal_(m.weight, std=0.001)
618 for name, _ in m.named_parameters():
619 if name in ['bias']:
620 nn.init.constant_(m.bias, 0)
621 '''
622 if os.path.isfile(pretrained):
623 pretrained_state_dict = torch.load(pretrained, map_location='cpu')
624 logger.info('=> loading pretrained model {}'.format(pretrained))
625 pretrained_state_dict = load_model(self.state_dict(),pretrained_state_dict)
626 print(self.load_state_dict(pretrained_state_dict, strict=False))
627 elif pretrained:
628 logger.error('=> please download pre-trained models first!')
629 raise ValueError('{} is not exist!'.format(pretrained))
630 '''
631 if os.path.isfile(pretrained):
632 pretrained_state_dict = torch.load(pretrained,map_location='cpu')
633 logging.info('=> loading pretrained HRNet model {}'.format(pretrained))
634
635 try:
636 self.load_state_dict(pretrained_state_dict, strict=True)
637 except:
638 need_init_state_dict = {}
639 for name, m in pretrained_state_dict.items():
640 if 'final_layer' not in name:
641 need_init_state_dict[name] = m
642 pretrained_state_dict = need_init_state_dict
643 self.load_state_dict(pretrained_state_dict, strict=False)
644 logging.info('=> reinit final layer...')
645 logging.info('=> successfully loaded')
646 elif pretrained:
647 logging.info('=> please download pre-trained HRNet models first!')
648 raise ValueError('{} is not exist!'.format(pretrained))
649
650
651def get_pose_net(cfg, is_train, score=False, **kwargs):

Callers 1

get_pose_netFunction · 0.95

Calls 4

infoMethod · 0.80
loadMethod · 0.45
load_state_dictMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected