code: def filter_top_predictions(labels, boxes, scores):
      """Filters out the top scoring predictions of each class from the
      given data. Note: passing the predictions from
      :meth:`detecto.core.Model.predict` to this function produces the same
      results as a direct call to :meth:`detecto.core.Model.predict_top`.
  
      :param labels: A list containing the string labels.
      :type labels: list
      :param boxes: A tensor of size [N, 4] containing the N box coordinates.
      :type boxes: torch.Tensor
      :param scores: A tensor containing the score for each prediction.
      :type scores: torch.Tensor
      :return: Returns a tuple of the given labels, boxes, and scores, except
          with only the top scoring prediction of each unique label kept in;
          all other predictions are filtered out.
      :rtype: tuple
  
      **Example**::
  
          >>> from detecto.core import Model
          >>> from detecto.utils import read_image, filter_top_predictions
  
          >>> model = Model.load('model_weights.pth', ['label1', 'label2'])
          >>> image = read_image('image.jpg')
          >>> labels, boxes, scores = model.predict(image)
          >>> top_preds = filter_top_predictions(labels, boxes, scores)
          >>> top_preds
          (['label2', 'label1'], tensor([[   0.0000,  428.0744, 1617.1860, 1076.3607],
          [ 875.3470,  412.1762,  949.5915,  793.3424]]), tensor([0.9397, 0.8686]))
      """
  
      filtered_labels = []
      filtered_boxes = []
      filtered_scores = []
      # Loop through each unique label
      for label in set(labels):
          # Get first index of label, which is also its highest scoring occurrence
          index = labels.index(label)
  
          filtered_labels.append(label)
          filtered_boxes.append(boxes[index])
          filtered_scores.append(scores[index])
  
      if len(filtered_labels) == 0:
          return (
              filtered_labels,
              torch.empty(0, 4),
              torch.tensor(filtered_scores),
          )
      return (
          filtered_labels,
          torch.stack(filtered_boxes),
          torch.tensor(filtered_scores),
      )
  
file_path: detecto/detecto/utils.py
imports: import cv2
  import os
  import pandas
  import torch
  import xml.etree.ElementTree
  from glob import glob
  from torchvision import transforms
label_desc: Use image node_id 2 for calling a global function with example usage: filter_top_predictions(labels, boxes, scores) and returns: filtered_labels,  torch,  torch, filtered_labels,  torch,  torch