MCPcopy Create free account
hub / github.com/OpenMeshLab/MeshXL / nms_3d_faster_samecls

Function nms_3d_faster_samecls

utils/nms.py:120–162  ·  view source on GitHub ↗
(boxes, overlap_threshold, old_type=False)

Source from the content-addressed store, hash-verified

118
119
120def nms_3d_faster_samecls(boxes, overlap_threshold, old_type=False):
121 x1 = boxes[:, 0]
122 y1 = boxes[:, 1]
123 z1 = boxes[:, 2]
124 x2 = boxes[:, 3]
125 y2 = boxes[:, 4]
126 z2 = boxes[:, 5]
127 score = boxes[:, 6]
128 cls = boxes[:, 7]
129 area = (x2 - x1) * (y2 - y1) * (z2 - z1)
130
131 I = np.argsort(score)
132 pick = []
133 while I.size != 0:
134 last = I.size
135 i = I[-1]
136 pick.append(i)
137
138 xx1 = np.maximum(x1[i], x1[I[: last - 1]])
139 yy1 = np.maximum(y1[i], y1[I[: last - 1]])
140 zz1 = np.maximum(z1[i], z1[I[: last - 1]])
141 xx2 = np.minimum(x2[i], x2[I[: last - 1]])
142 yy2 = np.minimum(y2[i], y2[I[: last - 1]])
143 zz2 = np.minimum(z2[i], z2[I[: last - 1]])
144 cls1 = cls[i]
145 cls2 = cls[I[: last - 1]]
146
147 l = np.maximum(0, xx2 - xx1)
148 w = np.maximum(0, yy2 - yy1)
149 h = np.maximum(0, zz2 - zz1)
150
151 if old_type:
152 o = (l * w * h) / area[I[: last - 1]]
153 else:
154 inter = l * w * h
155 o = inter / (area[i] + area[I[: last - 1]] - inter)
156 o = o * (cls1 == cls2)
157
158 I = np.delete(
159 I, np.concatenate(([last - 1], np.where(o > overlap_threshold)[0]))
160 )
161
162 return pick

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected