Python mmdet.core.multi_apply() Examples
The following are 30
code examples of mmdet.core.multi_apply().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mmdet.core
, or try the search function
.
Example #1
Source File: anchor_free_head.py From mmdetection with Apache License 2.0 | 6 votes |
def forward(self, feats): """Forward features from the upstream network. Args: feats (tuple[Tensor]): Features from the upstream network, each is a 4D-tensor. Returns: tuple: Usually contain classification scores and bbox predictions. cls_scores (list[Tensor]): Box scores for each scale level, each is a 4D-tensor, the channel number is num_points * num_classes. bbox_preds (list[Tensor]): Box energies / deltas for each scale level, each is a 4D-tensor, the channel number is num_points * 4. """ return multi_apply(self.forward_single, feats)[:2]
Example #2
Source File: fovea_head.py From kaggle-kuzushiji-recognition with MIT License | 6 votes |
def fovea_target(self, gt_bbox_list, gt_label_list, featmap_sizes, points): label_list, bbox_target_list = multi_apply( self.fovea_target_single, gt_bbox_list, gt_label_list, featmap_size_list=featmap_sizes, point_list=points) flatten_labels = [ torch.cat([ labels_level_img.flatten() for labels_level_img in labels_level ]) for labels_level in zip(*label_list) ] flatten_bbox_targets = [ torch.cat([ bbox_targets_level_img.reshape(-1, 4) for bbox_targets_level_img in bbox_targets_level ]) for bbox_targets_level in zip(*bbox_target_list) ] flatten_labels = torch.cat(flatten_labels) flatten_bbox_targets = torch.cat(flatten_bbox_targets) return flatten_labels, flatten_bbox_targets
Example #3
Source File: fovea_head.py From Cascade-RPN with Apache License 2.0 | 6 votes |
def fovea_target(self, gt_bbox_list, gt_label_list, featmap_sizes, points): label_list, bbox_target_list = multi_apply( self.fovea_target_single, gt_bbox_list, gt_label_list, featmap_size_list=featmap_sizes, point_list=points) flatten_labels = [ torch.cat([ labels_level_img.flatten() for labels_level_img in labels_level ]) for labels_level in zip(*label_list) ] flatten_bbox_targets = [ torch.cat([ bbox_targets_level_img.reshape(-1, 4) for bbox_targets_level_img in bbox_targets_level ]) for bbox_targets_level in zip(*bbox_target_list) ] flatten_labels = torch.cat(flatten_labels) flatten_bbox_targets = torch.cat(flatten_bbox_targets) return flatten_labels, flatten_bbox_targets
Example #4
Source File: fovea_head.py From IoU-Uniform-R-CNN with Apache License 2.0 | 6 votes |
def fovea_target(self, gt_bbox_list, gt_label_list, featmap_sizes, points): label_list, bbox_target_list = multi_apply( self.fovea_target_single, gt_bbox_list, gt_label_list, featmap_size_list=featmap_sizes, point_list=points) flatten_labels = [ torch.cat([ labels_level_img.flatten() for labels_level_img in labels_level ]) for labels_level in zip(*label_list) ] flatten_bbox_targets = [ torch.cat([ bbox_targets_level_img.reshape(-1, 4) for bbox_targets_level_img in bbox_targets_level ]) for bbox_targets_level in zip(*bbox_target_list) ] flatten_labels = torch.cat(flatten_labels) flatten_bbox_targets = torch.cat(flatten_bbox_targets) return flatten_labels, flatten_bbox_targets
Example #5
Source File: fovea_head.py From ttfnet with Apache License 2.0 | 6 votes |
def fovea_target(self, gt_bbox_list, gt_label_list, featmap_sizes, points): label_list, bbox_target_list = multi_apply( self.fovea_target_single, gt_bbox_list, gt_label_list, featmap_size_list=featmap_sizes, point_list=points) flatten_labels = [ torch.cat([ labels_level_img.flatten() for labels_level_img in labels_level ]) for labels_level in zip(*label_list) ] flatten_bbox_targets = [ torch.cat([ bbox_targets_level_img.reshape(-1, 4) for bbox_targets_level_img in bbox_targets_level ]) for bbox_targets_level in zip(*bbox_target_list) ] flatten_labels = torch.cat(flatten_labels) flatten_bbox_targets = torch.cat(flatten_bbox_targets) return flatten_labels, flatten_bbox_targets
Example #6
Source File: fovea_head.py From mmdetection with Apache License 2.0 | 6 votes |
def get_targets(self, gt_bbox_list, gt_label_list, featmap_sizes, points): label_list, bbox_target_list = multi_apply( self._get_target_single, gt_bbox_list, gt_label_list, featmap_size_list=featmap_sizes, point_list=points) flatten_labels = [ torch.cat([ labels_level_img.flatten() for labels_level_img in labels_level ]) for labels_level in zip(*label_list) ] flatten_bbox_targets = [ torch.cat([ bbox_targets_level_img.reshape(-1, 4) for bbox_targets_level_img in bbox_targets_level ]) for bbox_targets_level in zip(*bbox_target_list) ] flatten_labels = torch.cat(flatten_labels) flatten_bbox_targets = torch.cat(flatten_bbox_targets) return flatten_labels, flatten_bbox_targets
Example #7
Source File: fcos_head.py From mmdetection with Apache License 2.0 | 6 votes |
def forward(self, feats): """Forward features from the upstream network. Args: feats (tuple[Tensor]): Features from the upstream network, each is a 4D-tensor. Returns: tuple: cls_scores (list[Tensor]): Box scores for each scale level, each is a 4D-tensor, the channel number is num_points * num_classes. bbox_preds (list[Tensor]): Box energies / deltas for each scale level, each is a 4D-tensor, the channel number is num_points * 4. centernesses (list[Tensor]): Centerss for each scale level, each is a 4D-tensor, the channel number is num_points * 1. """ return multi_apply(self.forward_single, feats, self.scales, self.strides)
Example #8
Source File: weight_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def center_target(self, gt_bboxes_list, gt_labels_list, img_metas, all_level_points): assert len(self.featmap_sizes) == len(self.regress_ranges) # get heatmaps and targets of each image # heatmaps in heatmaps_list: [num_points, 80] # wh_targets: [num_points, 2] => [batch_size, num_points, 2] heatmaps_list, wh_targets_list, offset_targets_list = multi_apply( self.center_target_single, gt_bboxes_list, gt_labels_list, img_metas ) # split to per img, per level num_points = [center.size(0) for center in all_level_points] # 每一层多少个点 all_level_points [[12414, 2], []] heatmaps_list = [heatmaps.split(num_points, 0) for heatmaps in heatmaps_list] wh_targets_list = [wh_targets.split(num_points, 0) for wh_targets in wh_targets_list] offset_targets_list = [offset_targets.split(num_points, 0) for offset_targets in offset_targets_list] # concat per level image, 同一层的concat # [(batch_size,featmap_size[1]), ...) concat_lvl_heatmaps = [] concat_lvl_wh_targets = [] concat_lvl_offset_targets = [] num_levels = len(self.featmap_sizes) for i in range(num_levels): concat_lvl_heatmaps.append( torch.cat([heatmaps[i] for heatmaps in heatmaps_list])) # (num_levels, batch_size * w * h, 80) concat_lvl_wh_targets.append( torch.cat( [wh_targets[i] for wh_targets in wh_targets_list])) concat_lvl_offset_targets.append( torch.cat( [offset_targets[i] for offset_targets in offset_targets_list])) return concat_lvl_heatmaps, concat_lvl_wh_targets, concat_lvl_offset_targets
Example #9
Source File: fcos_head.py From Libra_R-CNN with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets
Example #10
Source File: matrix_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def center_target(self, gt_bboxes_list, gt_labels_list, img_metas, all_level_points): #assert len(self.featmap_sizes) == len(self.regress_ranges) assert len(self.featmap_sizes) == len(self.strides) # get heatmaps and targets of each image # heatmaps in heatmaps_list: [num_points, 80] # wh_targets: [num_points, 2] => [batch_size, num_points, 2] heatmaps_list, wh_targets_list, offset_targets_list = multi_apply( self.center_target_single, gt_bboxes_list, gt_labels_list, img_metas ) # split to per img, per level num_points = [center.size(0) for center in all_level_points] # 每一层多少个点 all_level_points [[12414, 2], []] heatmaps_list = [heatmaps.split(num_points, 0) for heatmaps in heatmaps_list] wh_targets_list = [wh_targets.split(num_points, 0) for wh_targets in wh_targets_list] offset_targets_list = [offset_targets.split(num_points, 0) for offset_targets in offset_targets_list] # concat per level image, 同一层的concat # [(batch_size,featmap_size[1]), ...) concat_lvl_heatmaps = [] concat_lvl_wh_targets = [] concat_lvl_offset_targets = [] num_levels = len(self.featmap_sizes) for i in range(num_levels): concat_lvl_heatmaps.append( torch.cat([heatmaps[i] for heatmaps in heatmaps_list])) # (num_levels, batch_size * w * h, 80) concat_lvl_wh_targets.append( torch.cat( [wh_targets[i] for wh_targets in wh_targets_list])) concat_lvl_offset_targets.append( torch.cat( [offset_targets[i] for offset_targets in offset_targets_list])) return concat_lvl_heatmaps, concat_lvl_wh_targets, concat_lvl_offset_targets
Example #11
Source File: center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def center_target(self, gt_bboxes_list, gt_labels_list, img_metas, all_level_points): assert len(self.featmap_sizes) == len(self.regress_ranges) # get heatmaps and targets of each image # heatmaps in heatmaps_list: [num_points, 80] # wh_targets: [num_points, 2] => [batch_size, num_points, 2] heatmaps_list, wh_targets_list, offset_targets_list = multi_apply( self.center_target_single, gt_bboxes_list, gt_labels_list, img_metas ) # split to per img, per level num_points = [center.size(0) for center in all_level_points] # 每一层多少个点 all_level_points [[12414, 2], []] heatmaps_list = [heatmaps.split(num_points, 0) for heatmaps in heatmaps_list] wh_targets_list = [wh_targets.split(num_points, 0) for wh_targets in wh_targets_list] offset_targets_list = [offset_targets.split(num_points, 0) for offset_targets in offset_targets_list] # concat per level image, 同一层的concat # [(batch_size,featmap_size[1]), ...) concat_lvl_heatmaps = [] concat_lvl_wh_targets = [] concat_lvl_offset_targets = [] num_levels = len(self.featmap_sizes) for i in range(num_levels): concat_lvl_heatmaps.append( torch.cat([heatmaps[i] for heatmaps in heatmaps_list])) # (num_levels, batch_size * w * h, 80) concat_lvl_wh_targets.append( torch.cat( [wh_targets[i] for wh_targets in wh_targets_list])) concat_lvl_offset_targets.append( torch.cat( [offset_targets[i] for offset_targets in offset_targets_list])) return concat_lvl_heatmaps, concat_lvl_wh_targets, concat_lvl_offset_targets
Example #12
Source File: center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #13
Source File: weight_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #14
Source File: fcos_plus_head.py From CenterNet with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets
Example #15
Source File: ttf_head.py From ttfnet with Apache License 2.0 | 5 votes |
def target_generator(self, gt_boxes, gt_labels, img_metas): """ Args: gt_boxes: list(tensor). tensor <=> image, (gt_num, 4). gt_labels: list(tensor). tensor <=> image, (gt_num,). img_metas: list(dict). Returns: heatmap: tensor, (batch, 80, h, w). box_target: tensor, (batch, 4, h, w) or (batch, 80 * 4, h, w). reg_weight: tensor, same as box_target. """ with torch.no_grad(): feat_shape = (img_metas[0]['pad_shape'][0] // self.down_ratio, img_metas[0]['pad_shape'][1] // self.down_ratio) heatmap, box_target, reg_weight = multi_apply( self.target_single_image, gt_boxes, gt_labels, feat_shape=feat_shape ) heatmap, box_target = [torch.stack(t, dim=0).detach() for t in [heatmap, box_target]] reg_weight = torch.stack(reg_weight, dim=0).detach() return heatmap, box_target, reg_weight
Example #16
Source File: fovea_head.py From ttfnet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats)
Example #17
Source File: fcos_head.py From ttfnet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #18
Source File: sr_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #19
Source File: fcos_head.py From AugFPN with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #20
Source File: sr_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def center_target(self, gt_bboxes_list, gt_labels_list, img_metas, all_level_points): assert len(self.featmap_sizes) == len(self.regress_ranges) # get heatmaps and targets of each image # heatmaps in heatmaps_list: [num_points, 80] # wh_targets: [num_points, 2] => [batch_size, num_points, 2] heatmaps_list, wh_targets_list, offset_targets_list = multi_apply( self.center_target_single, gt_bboxes_list, gt_labels_list, img_metas ) # split to per img, per level num_points = [center.size(0) for center in all_level_points] # 每一层多少个点 all_level_points [[12414, 2], []] heatmaps_list = [heatmaps.split(num_points, 0) for heatmaps in heatmaps_list] wh_targets_list = [wh_targets.split(num_points, 0) for wh_targets in wh_targets_list] offset_targets_list = [offset_targets.split(num_points, 0) for offset_targets in offset_targets_list] # concat per level image, 同一层的concat # [(batch_size,featmap_size[1]), ...) concat_lvl_heatmaps = [] concat_lvl_wh_targets = [] concat_lvl_offset_targets = [] num_levels = len(self.featmap_sizes) for i in range(num_levels): concat_lvl_heatmaps.append( torch.cat([heatmaps[i] for heatmaps in heatmaps_list])) # (num_levels, batch_size * w * h, 80) concat_lvl_wh_targets.append( torch.cat( [wh_targets[i] for wh_targets in wh_targets_list])) concat_lvl_offset_targets.append( torch.cat( [offset_targets[i] for offset_targets in offset_targets_list])) return concat_lvl_heatmaps, concat_lvl_wh_targets, concat_lvl_offset_targets
Example #21
Source File: matrix_center_head.py From CenterNet with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #22
Source File: fcos_head.py From Feature-Selective-Anchor-Free-Module-for-Single-Shot-Object-Detection with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets
Example #23
Source File: fcos_head.py From Feature-Selective-Anchor-Free-Module-for-Single-Shot-Object-Detection with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #24
Source File: fcos_head.py From Cascade-RPN with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets
Example #25
Source File: fcos_head.py From Cascade-RPN with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #26
Source File: fovea_head.py From Cascade-RPN with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats)
Example #27
Source File: fcos_head.py From FoveaBox with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets
Example #28
Source File: fcos_head.py From FoveaBox with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats, self.scales)
Example #29
Source File: fovea_head.py From FoveaBox with Apache License 2.0 | 5 votes |
def forward(self, feats): return multi_apply(self.forward_single, feats)
Example #30
Source File: fcos_head.py From AugFPN with Apache License 2.0 | 5 votes |
def fcos_target(self, points, gt_bboxes_list, gt_labels_list): assert len(points) == len(self.regress_ranges) num_levels = len(points) # expand regress ranges to align with points expanded_regress_ranges = [ points[i].new_tensor(self.regress_ranges[i])[None].expand_as( points[i]) for i in range(num_levels) ] # concat all levels points and regress ranges concat_regress_ranges = torch.cat(expanded_regress_ranges, dim=0) concat_points = torch.cat(points, dim=0) # get labels and bbox_targets of each image labels_list, bbox_targets_list = multi_apply( self.fcos_target_single, gt_bboxes_list, gt_labels_list, points=concat_points, regress_ranges=concat_regress_ranges) # split to per img, per level num_points = [center.size(0) for center in points] labels_list = [labels.split(num_points, 0) for labels in labels_list] bbox_targets_list = [ bbox_targets.split(num_points, 0) for bbox_targets in bbox_targets_list ] # concat per level image concat_lvl_labels = [] concat_lvl_bbox_targets = [] for i in range(num_levels): concat_lvl_labels.append( torch.cat([labels[i] for labels in labels_list])) concat_lvl_bbox_targets.append( torch.cat( [bbox_targets[i] for bbox_targets in bbox_targets_list])) return concat_lvl_labels, concat_lvl_bbox_targets