MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / NMS

Method NMS

samples/python/detectron2/create_onnx.py:245–298  ·  view source on GitHub ↗
(self, boxes, scores, anchors, background_class, score_activation, max_proposals, iou_threshold, nms_score_threshold, user_threshold, nms_name=None)

Source from the content-addressed store, hash-verified

243 node.inputs[1].values[0] = self.batch_size
244
245 def NMS(self, boxes, scores, anchors, background_class, score_activation, max_proposals, iou_threshold, nms_score_threshold, user_threshold, nms_name=None):
246 # Helper function to create the NMS Plugin node with the selected inputs.
247 # EfficientNMS_TRT TensorRT Plugin is suitable for our use case.
248 # :param boxes: The box predictions from the Box Net.
249 # :param scores: The class predictions from the Class Net.
250 # :param anchors: The default anchor coordinates.
251 # :param background_class: The label ID for the background class.
252 # :param max_proposals: Number of proposals made by NMS.
253 # :param score_activation: If set to True - apply sigmoid activation to the confidence scores during NMS operation,
254 # if false - no activation.
255 # :param iou_threshold: NMS intersection over union threshold, given by self.det2_cfg.
256 # :param nms_score_threshold: NMS score threshold, given by self.det2_cfg.
257 # :param user_threshold: User's given threshold to overwrite default NMS score threshold.
258 # :param nms_name: Name of NMS node in a graph, renames NMS elements accordingly in order to eliminate cycles.
259
260 if nms_name is None:
261 nms_name = ""
262 else:
263 nms_name = "_" + nms_name
264
265 # Set score threshold.
266 score_threshold = nms_score_threshold if user_threshold is None else user_threshold
267
268 # NMS Outputs.
269 nms_output_num_detections = gs.Variable(name="num_detections"+nms_name, dtype=np.int32, shape=[self.batch_size, 1])
270 nms_output_boxes = gs.Variable(name="detection_boxes"+nms_name, dtype=np.float32,
271 shape=[self.batch_size, max_proposals, 4])
272 nms_output_scores = gs.Variable(name="detection_scores"+nms_name, dtype=np.float32,
273 shape=[self.batch_size, max_proposals])
274 nms_output_classes = gs.Variable(name="detection_classes"+nms_name, dtype=np.int32,
275 shape=[self.batch_size, max_proposals])
276
277 nms_outputs = [nms_output_num_detections, nms_output_boxes, nms_output_scores, nms_output_classes]
278
279 # Plugin.
280 self.graph.plugin(
281 op="EfficientNMS_TRT",
282 name="nms"+nms_name,
283 inputs=[boxes, scores, anchors],
284 outputs=nms_outputs,
285 attrs={
286 'plugin_version': "1",
287 'background_class': background_class,
288 'max_output_boxes': max_proposals,
289 'score_threshold': max(0.01, score_threshold),
290 'iou_threshold': iou_threshold,
291 'score_activation': score_activation,
292 'class_agnostic': False,
293 'box_coding': 1,
294 }
295 )
296 log.info("Created nms{} with EfficientNMS_TRT plugin".format(nms_name))
297
298 return nms_outputs
299
300 def ROIAlign(self, rois, p2, p3, p4, p5, pooled_size, sampling_ratio, roi_align_type, num_rois, ra_name):
301 # Helper function to create the ROIAlign Plugin node with the selected inputs.

Callers 2

proposal_generatorMethod · 0.95
roi_headsMethod · 0.95

Calls 2

maxFunction · 0.85
infoMethod · 0.45

Tested by

no test coverage detected