本文整理汇总了Python中utils.resnet_weights_helper.load_pretrained_imagenet_weights方法的典型用法代码示例。如果您正苦于以下问题:Python resnet_weights_helper.load_pretrained_imagenet_weights方法的具体用法?Python resnet_weights_helper.load_pretrained_imagenet_weights怎么用?Python resnet_weights_helper.load_pretrained_imagenet_weights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.resnet_weights_helper
的用法示例。
在下文中一共展示了resnet_weights_helper.load_pretrained_imagenet_weights方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_modules
# 需要导入模块: from utils import resnet_weights_helper [as 别名]
# 或者: from utils.resnet_weights_helper import load_pretrained_imagenet_weights [as 别名]
def _init_modules(self):
if cfg.MODEL.LOAD_IMAGENET_PRETRAINED_WEIGHTS:
resnet_utils.load_pretrained_imagenet_weights(self)
# Check if shared weights are equaled
if cfg.MODEL.MASK_ON and getattr(self.Mask_Head, 'SHARE_RES5', False):
assert compare_state_dict(self.Mask_Head.res5.state_dict(), self.Box_Head.res5.state_dict())
if cfg.MODEL.KEYPOINTS_ON and getattr(self.Keypoint_Head, 'SHARE_RES5', False):
assert compare_state_dict(self.Keypoint_Head.res5.state_dict(), self.Box_Head.res5.state_dict())
if cfg.TRAIN.FREEZE_CONV_BODY:
for p in self.Conv_Body.parameters():
p.requires_grad = False
if cfg.TRAIN.FREEZE_RPN_BODY:
for p in self.RPN.parameters():
p.requires_grad = False
if cfg.TRAIN.FREEZE_FASTER_RCNN:
for p in self.Box_Head.parameters():
p.requires_grad = False
for p in self.Box_Outs.parameters():
p.requires_grad = False
示例2: _init_modules
# 需要导入模块: from utils import resnet_weights_helper [as 别名]
# 或者: from utils.resnet_weights_helper import load_pretrained_imagenet_weights [as 别名]
def _init_modules(self):
if cfg.MODEL.LOAD_IMAGENET_PRETRAINED_WEIGHTS:
resnet_utils.load_pretrained_imagenet_weights(self)
# Check if shared weights are equaled
if cfg.MODEL.MASK_ON and getattr(self.Mask_Head, 'SHARE_RES5', False):
assert compare_state_dict(self.Mask_Head.res5.state_dict(), self.Box_Head.res5.state_dict())
if cfg.MODEL.KEYPOINTS_ON and getattr(self.Keypoint_Head, 'SHARE_RES5', False):
assert compare_state_dict(self.Keypoint_Head.res5.state_dict(), self.Box_Head.res5.state_dict())
if cfg.TRAIN.FREEZE_CONV_BODY:
for p in self.Conv_Body.parameters():
p.requires_grad = False
示例3: _init_modules
# 需要导入模块: from utils import resnet_weights_helper [as 别名]
# 或者: from utils.resnet_weights_helper import load_pretrained_imagenet_weights [as 别名]
def _init_modules(self):
if cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS != '': # or cfg.MODEL.USE_SE_LOSS:
logger.info("Loading pretrained weights from %s", cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS)
resnet_utils.load_pretrained_imagenet_weights(self)
# Check if shared weights are equaled
if cfg.MODEL.MASK_ON and getattr(self.Mask_Head, 'SHARE_RES5', False):
assert self.Mask_Head.res5.state_dict() == self.Box_Head.res5.state_dict()
if cfg.MODEL.KEYPOINTS_ON and getattr(self.Keypoint_Head, 'SHARE_RES5', False):
assert self.Keypoint_Head.res5.state_dict() == self.Box_Head.res5.state_dict()
# load detectron pretrained weights for resnet
if cfg.RESNETS.COCO_PRETRAINED_WEIGHTS != '':
logger.info("loading detectron pretrained weights from %s", cfg.RESNETS.COCO_PRETRAINED_WEIGHTS)
load_detectron_weight(self, cfg.RESNETS.COCO_PRETRAINED_WEIGHTS, ('cls_score', 'bbox_pred'))
if cfg.VGG16.COCO_PRETRAINED_WEIGHTS != '':
logger.info("loading pretrained weights from %s", cfg.VGG16.COCO_PRETRAINED_WEIGHTS)
checkpoint = torch.load(cfg.VGG16.COCO_PRETRAINED_WEIGHTS, map_location=lambda storage, loc: storage)
# not using the last softmax layers
del checkpoint['model']['Box_Outs.cls_score.weight']
del checkpoint['model']['Box_Outs.cls_score.bias']
del checkpoint['model']['Box_Outs.bbox_pred.weight']
del checkpoint['model']['Box_Outs.bbox_pred.bias']
net_utils.load_ckpt(self, checkpoint['model'])
if cfg.RESNETS.TO_BE_FINETUNED_WEIGHTS != '':
logger.info("loading trained and to be finetuned weights from %s", cfg.RESNETS.TO_BE_FINETUNED_WEIGHTS)
checkpoint = torch.load(cfg.RESNETS.TO_BE_FINETUNED_WEIGHTS, map_location=lambda storage, loc: storage)
net_utils.load_ckpt(self, checkpoint['model'])
if cfg.TRAIN.FREEZE_CONV_BODY:
for p in self.Conv_Body.parameters():
p.requires_grad = False
示例4: _init_modules
# 需要导入模块: from utils import resnet_weights_helper [as 别名]
# 或者: from utils.resnet_weights_helper import load_pretrained_imagenet_weights [as 别名]
def _init_modules(self):
# VGG16 imagenet pretrained model is initialized in VGG16.py
if cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS != '':
logger.info("Loading pretrained weights from %s", cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS)
resnet_utils.load_pretrained_imagenet_weights(self)
if cfg.RESNETS.VRD_PRETRAINED_WEIGHTS != '':
self.load_detector_weights(cfg.RESNETS.VRD_PRETRAINED_WEIGHTS)
if cfg.VGG16.VRD_PRETRAINED_WEIGHTS != '':
self.load_detector_weights(cfg.VGG16.VRD_PRETRAINED_WEIGHTS)
if cfg.RESNETS.VG_PRETRAINED_WEIGHTS != '':
self.load_detector_weights(cfg.RESNETS.VG_PRETRAINED_WEIGHTS)
if cfg.VGG16.VG_PRETRAINED_WEIGHTS != '':
self.load_detector_weights(cfg.VGG16.VG_PRETRAINED_WEIGHTS)
if cfg.TRAIN.FREEZE_CONV_BODY:
for p in self.Conv_Body.parameters():
p.requires_grad = False
if cfg.RESNETS.VRD_PRD_PRETRAINED_WEIGHTS != '' or cfg.VGG16.VRD_PRD_PRETRAINED_WEIGHTS != '' or \
cfg.RESNETS.VG_PRD_PRETRAINED_WEIGHTS != '' or cfg.VGG16.VG_PRD_PRETRAINED_WEIGHTS != '':
if cfg.RESNETS.VRD_PRD_PRETRAINED_WEIGHTS != '':
logger.info("loading prd pretrained weights from %s", cfg.RESNETS.VRD_PRD_PRETRAINED_WEIGHTS)
checkpoint = torch.load(cfg.RESNETS.VRD_PRD_PRETRAINED_WEIGHTS, map_location=lambda storage, loc: storage)
if cfg.VGG16.VRD_PRD_PRETRAINED_WEIGHTS != '':
logger.info("loading prd pretrained weights from %s", cfg.VGG16.VRD_PRD_PRETRAINED_WEIGHTS)
checkpoint = torch.load(cfg.VGG16.VRD_PRD_PRETRAINED_WEIGHTS, map_location=lambda storage, loc: storage)
if cfg.RESNETS.VG_PRD_PRETRAINED_WEIGHTS != '':
logger.info("loading prd pretrained weights from %s", cfg.RESNETS.VG_PRD_PRETRAINED_WEIGHTS)
checkpoint = torch.load(cfg.RESNETS.VG_PRD_PRETRAINED_WEIGHTS, map_location=lambda storage, loc: storage)
if cfg.VGG16.VG_PRD_PRETRAINED_WEIGHTS != '':
logger.info("loading prd pretrained weights from %s", cfg.VGG16.VG_PRD_PRETRAINED_WEIGHTS)
checkpoint = torch.load(cfg.VGG16.VG_PRD_PRETRAINED_WEIGHTS, map_location=lambda storage, loc: storage)
# not using the last softmax layers
del checkpoint['model']['Box_Outs.cls_score.weight']
del checkpoint['model']['Box_Outs.cls_score.bias']
del checkpoint['model']['Box_Outs.bbox_pred.weight']
del checkpoint['model']['Box_Outs.bbox_pred.bias']
net_utils.load_ckpt(self.Prd_RCNN, checkpoint['model'])
if cfg.TRAIN.FREEZE_PRD_CONV_BODY:
for p in self.Prd_RCNN.Conv_Body.parameters():
p.requires_grad = False
if cfg.TRAIN.FREEZE_PRD_BOX_HEAD:
for p in self.Prd_RCNN.Box_Head.parameters():
p.requires_grad = False