MCPcopy
hub / github.com/open-mmlab/mmtracking / outs2results

Function outs2results

mmtrack/core/track/transforms.py:51–118  ·  view source on GitHub ↗

Convert tracking/detection results to a list of numpy arrays. Args: bboxes (torch.Tensor | np.ndarray): shape (n, 5) labels (torch.Tensor | np.ndarray): shape (n, ) masks (torch.Tensor | np.ndarray): shape (n, h, w) ids (torch.Tensor | np.ndarray): shape (n, )

(bboxes=None,
                 labels=None,
                 masks=None,
                 ids=None,
                 num_classes=None,
                 **kwargs)

Source from the content-addressed store, hash-verified

49
50
51def outs2results(bboxes=None,
52 labels=None,
53 masks=None,
54 ids=None,
55 num_classes=None,
56 **kwargs):
57 """Convert tracking/detection results to a list of numpy arrays.
58
59 Args:
60 bboxes (torch.Tensor | np.ndarray): shape (n, 5)
61 labels (torch.Tensor | np.ndarray): shape (n, )
62 masks (torch.Tensor | np.ndarray): shape (n, h, w)
63 ids (torch.Tensor | np.ndarray): shape (n, )
64 num_classes (int): class number, not including background class
65
66 Returns:
67 dict[str : list(ndarray) | list[list[np.ndarray]]]: tracking/detection
68 results of each class. It may contain keys as belows:
69
70 - bbox_results (list[np.ndarray]): Each list denotes bboxes of one
71 category.
72 - mask_results (list[list[np.ndarray]]): Each outer list denotes masks
73 of one category. Each inner list denotes one mask belonging to
74 the category. Each mask has shape (h, w).
75 """
76 assert labels is not None
77 assert num_classes is not None
78
79 results = dict()
80
81 if ids is not None:
82 valid_inds = ids > -1
83 ids = ids[valid_inds]
84 labels = labels[valid_inds]
85
86 if bboxes is not None:
87 if ids is not None:
88 bboxes = bboxes[valid_inds]
89 if bboxes.shape[0] == 0:
90 bbox_results = [
91 np.zeros((0, 6), dtype=np.float32)
92 for i in range(num_classes)
93 ]
94 else:
95 if isinstance(bboxes, torch.Tensor):
96 bboxes = bboxes.cpu().numpy()
97 labels = labels.cpu().numpy()
98 ids = ids.cpu().numpy()
99 bbox_results = [
100 np.concatenate(
101 (ids[labels == i, None], bboxes[labels == i, :]),
102 axis=1) for i in range(num_classes)
103 ]
104 else:
105 bbox_results = bbox2result(bboxes, labels, num_classes)
106 results['bbox_results'] = bbox_results
107
108 if masks is not None:

Callers 9

test_outs2resultsFunction · 0.90
_create_coco_gt_resultsFunction · 0.90
acc_single_videoFunction · 0.90
simple_testMethod · 0.90
simple_testMethod · 0.90
simple_testMethod · 0.90
simple_testMethod · 0.90
simple_testMethod · 0.90
simple_testMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_outs2resultsFunction · 0.72