本文整理匯總了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