本文整理汇总了Python中mmdet.core.build_sampler方法的典型用法代码示例。如果您正苦于以下问题:Python core.build_sampler方法的具体用法?Python core.build_sampler怎么用?Python core.build_sampler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mmdet.core
的用法示例。
在下文中一共展示了core.build_sampler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_assigner_sampler
# 需要导入模块: from mmdet import core [as 别名]
# 或者: from mmdet.core import build_sampler [as 别名]
def init_assigner_sampler(self):
"""Initialize assigner and sampler."""
self.bbox_assigner = None
self.bbox_sampler = None
if self.train_cfg:
self.bbox_assigner = build_assigner(self.train_cfg.assigner)
self.bbox_sampler = build_sampler(
self.train_cfg.sampler, context=self)
示例2: _dummy_bbox_sampling
# 需要导入模块: from mmdet import core [as 别名]
# 或者: from mmdet.core import build_sampler [as 别名]
def _dummy_bbox_sampling(proposal_list, gt_bboxes, gt_labels):
"""Create sample results that can be passed to BBoxHead.get_targets."""
num_imgs = 1
feat = torch.rand(1, 1, 3, 3)
assign_config = dict(
type='MaxIoUAssigner',
pos_iou_thr=0.5,
neg_iou_thr=0.5,
min_pos_iou=0.5,
ignore_iof_thr=-1)
sampler_config = dict(
type='RandomSampler',
num=512,
pos_fraction=0.25,
neg_pos_ub=-1,
add_gt_as_proposals=True)
bbox_assigner = build_assigner(assign_config)
bbox_sampler = build_sampler(sampler_config)
gt_bboxes_ignore = [None for _ in range(num_imgs)]
sampling_results = []
for i in range(num_imgs):
assign_result = bbox_assigner.assign(proposal_list[i], gt_bboxes[i],
gt_bboxes_ignore[i], gt_labels[i])
sampling_result = bbox_sampler.sample(
assign_result,
proposal_list[i],
gt_bboxes[i],
gt_labels[i],
feats=feat)
sampling_results.append(sampling_result)
return sampling_results
示例3: forward_train
# 需要导入模块: from mmdet import core [as 别名]
# 或者: from mmdet.core import build_sampler [as 别名]
def forward_train(self,
img,
img_metas,
gt_bboxes,
gt_labels,
gt_bboxes_ignore=None):
if self.use_consistent_supervision:
x, y = self.extract_feat(img)
gt_bboxes_auxiliary = [gt.clone() for gt in gt_bboxes]
gt_labels_auxiliary = [label.clone() for label in gt_labels]
else:
x = self.extract_feat(img)
outs = self.bbox_head(x)
loss_inputs = outs + (gt_bboxes, gt_labels, img_metas, self.train_cfg)
losses = self.bbox_head.loss(
*loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore)
if self.use_consistent_supervision:
proposal_cfg = self.train_cfg.auxiliary.proposal
proposal_inputs = outs + (img_metas, proposal_cfg)
proposal_list = self.bbox_head.get_bboxes_auxiliary(*proposal_inputs)
bbox_assigner = build_assigner(self.train_cfg.auxiliary.assigner)
bbox_sampler = build_sampler(
self.train_cfg.auxiliary.sampler, context=self)
num_imgs = img.size(0)
if gt_bboxes_ignore is None:
gt_bboxes_ignore = [None for _ in range(num_imgs)]
sampling_results = []
for i in range(num_imgs):
assign_result = bbox_assigner.assign(
proposal_list[i], gt_bboxes_auxiliary[i], gt_bboxes_ignore[i],
gt_labels_auxiliary[i])
sampling_result = bbox_sampler.sample(
assign_result,
proposal_list[i],
gt_bboxes_auxiliary[i],
gt_labels_auxiliary[i],
feats=[lvl_feat[i][None] for lvl_feat in x])
sampling_results.append(sampling_result)
rois = bbox2roi([res.bboxes for res in sampling_results])
bbox_feats_raw = self.auxiliary_bbox_roi_extractor(y[:self.auxiliary_bbox_roi_extractor.num_inputs], rois)
cls_score_auxiliary, bbox_pred_auxiliary = self.auxiliary_bbox_head(bbox_feats_raw)
bbox_targets = self.auxiliary_bbox_head.get_target(
sampling_results, gt_bboxes, gt_labels, self.train_cfg.auxiliary.rcnn)
loss_bbox_auxiliary = self.auxiliary_bbox_head.loss(cls_score_auxiliary, bbox_pred_auxiliary,
*bbox_targets, alpha=0.25, num_level=3)
losses.update(loss_bbox_auxiliary)
return losses