MCPcopy
hub / github.com/ZFTurbo/Weighted-Boxes-Fusion / non_maximum_weighted

Function non_maximum_weighted

ensemble_boxes/ensemble_boxes_nmw.py:92–148  ·  view source on GitHub ↗

:param boxes_list: list of boxes predictions from each model, each box is 4 numbers. It has 3 dimensions (models_number, model_preds, 4) Order of boxes: x1, y1, x2, y2. We expect float normalized coordinates [0; 1] :param scores_list: list of scores for each model :param label

(boxes_list, scores_list, labels_list, weights=None, iou_thr=0.55, skip_box_thr=0.0)

Source from the content-addressed store, hash-verified

90
91
92def non_maximum_weighted(boxes_list, scores_list, labels_list, weights=None, iou_thr=0.55, skip_box_thr=0.0):
93 '''
94 :param boxes_list: list of boxes predictions from each model, each box is 4 numbers.
95 It has 3 dimensions (models_number, model_preds, 4)
96 Order of boxes: x1, y1, x2, y2. We expect float normalized coordinates [0; 1]
97 :param scores_list: list of scores for each model
98 :param labels_list: list of labels for each model
99 :param weights: list of weights for each model. Default: None, which means weight == 1 for each model
100 :param intersection_thr: IoU value for boxes to be a match
101 :param skip_box_thr: exclude boxes with score lower than this variable
102
103 :return: boxes: boxes coordinates (Order of boxes: x1, y1, x2, y2).
104 :return: scores: confidence scores
105 :return: labels: boxes labels
106 '''
107
108 if weights is None:
109 weights = np.ones(len(boxes_list))
110 if len(weights) != len(boxes_list):
111 print('Warning: incorrect number of weights {}. Must be: {}. Set weights equal to 1.'.format(len(weights), len(boxes_list)))
112 weights = np.ones(len(boxes_list))
113 weights = np.array(weights)
114 for i in range(len(weights)):
115 scores_list[i] = (np.array(scores_list[i]) * weights[i]) / weights.sum()
116
117 filtered_boxes = prefilter_boxes(boxes_list, scores_list, labels_list, weights, skip_box_thr)
118 if len(filtered_boxes) == 0:
119 return np.zeros((0, 4)), np.zeros((0,)), np.zeros((0,))
120
121 overall_boxes = []
122 for label in filtered_boxes:
123 boxes = filtered_boxes[label]
124 new_boxes = []
125 main_boxes = []
126
127 # Clusterize boxes
128 for j in range(0, len(boxes)):
129 index, best_iou = find_matching_box(main_boxes, boxes[j], iou_thr)
130 if index != -1:
131 new_boxes[index].append(boxes[j].copy())
132 else:
133 new_boxes.append([boxes[j].copy()])
134 main_boxes.append(boxes[j].copy())
135
136 weighted_boxes = []
137 for j in range(0, len(new_boxes)):
138 box = get_weighted_box(new_boxes[j])
139 weighted_boxes.append(box.copy())
140
141 overall_boxes.append(np.array(weighted_boxes))
142
143 overall_boxes = np.concatenate(overall_boxes, axis=0)
144 overall_boxes = overall_boxes[overall_boxes[:, 1].argsort()[::-1]]
145 boxes = overall_boxes[:, 2:]
146 scores = overall_boxes[:, 1]
147 labels = overall_boxes[:, 0]
148 return boxes, scores, labels

Callers 1

process_single_idFunction · 0.85

Calls 3

prefilter_boxesFunction · 0.70
find_matching_boxFunction · 0.70
get_weighted_boxFunction · 0.70

Tested by

no test coverage detected