docstr: Takes in an image or list of images and returns the top
  scoring predictions for each detected label in each image.
  Equivalent to running :meth:`detecto.core.Model.predict` and
  then :func:`detecto.utils.filter_top_predictions` together.
  
  :param images: An image or list of images to predict on. If the
      images have not already been transformed into torch.Tensor
      objects, the default transformations contained in
      :func:`detecto.utils.default_transforms` will be applied.
  :type images: list or numpy.ndarray or torch.Tensor
  :return: If given a single image, returns a tuple of size
      three. The first element is a list of string labels of size K,
      the number of uniquely detected objects. The second element is
      a torch.Tensor of size (K, 4), giving the ``xmin``, ``ymin``,
      ``xmax``, and ``ymax`` coordinates of the top-scoring boxes
      around each unique object. The third element is a torch.Tensor
      of size K containing the scores of each uniquely predicted object
      (ranges from 0.0 to 1.0). If given a list of images, returns a
      list of the tuples described above, each tuple corresponding to
      a single image.
  :rtype: tuple or list of tuple
  
  
  **Example**::
  
      >>> from detecto.core import Model
      >>> from detecto.utils import read_image
  
      >>> model = Model.load('model_weights.pth', ['label1', 'label2'])
      >>> image = read_image('image.jpg')
      >>> top_preds = model.predict_top(image)
      >>> 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]))
docstr_tok: ["Takes","in","an","image","or","list","of","images","and","returns","the","top","scoring","predictions","for","each","detected","label","in","each","image",".","Equivalent","to","running",":","meth",":","`","detecto.core.Model.predict","`","and","then",":","func",":","`","detecto.utils.filter_top_predictions","`","together",".",":","param","images",":","An","image","or","list","of","images","to","predict","on",".","If","the","images","have","not","already","been","transformed","into","torch.Tensor","objects",",","the","default","transformations","contained","in",":","func",":","`","detecto.utils.default_transforms","`","will","be","applied",".",":","type","images",":","list","or","numpy.ndarray","or","torch.Tensor",":","return",":","If","given","a","single","image",",","returns","a","tuple","of","size","three",".","The","first","element","is","a","list","of","string","labels","of","size","K",",","the","number","of","uniquely","detected","objects",".","The","second","element","is","a","torch.Tensor","of","size","(","K",",","4",")",",","giving","the","``","xmin","``",",","``","ymin","``",",","``","xmax","``",",","and","``","ymax","``","coordinates","of","the","top-scoring","boxes","around","each","unique","object",".","The","third","element","is","a","torch.Tensor","of","size","K","containing","the","scores","of","each","uniquely","predicted","object","(","ranges","from","0.0","to","1.0",")",".","If","given","a","list","of","images",",","returns","a","list","of","the","tuples","described","above",",","each","tuple","corresponding","to","a","single","image",".",":","rtype",":","tuple","or","list","of","tuple","*","*","Example","*","*",":",":",">",">",">","from","detecto.core","import","Model",">",">",">","from","detecto.utils","import","read_image",">",">",">","model","=","Model.load","(","'model_weights.pth","'",",","[","'label1","'",",","'label2","'","]",")",">",">",">","image","=","read_image","(","'image.jpg","'",")",">",">",">","top_preds","=","model.predict_top","(","image",")",">",">",">","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","]",")",")"]
code: def predict_top(self, images):
      """Takes in an image or list of images and returns the top
      scoring predictions for each detected label in each image.
      Equivalent to running :meth:`detecto.core.Model.predict` and
      then :func:`detecto.utils.filter_top_predictions` together.
  
      :param images: An image or list of images to predict on. If the
          images have not already been transformed into torch.Tensor
          objects, the default transformations contained in
          :func:`detecto.utils.default_transforms` will be applied.
      :type images: list or numpy.ndarray or torch.Tensor
      :return: If given a single image, returns a tuple of size
          three. The first element is a list of string labels of size K,
          the number of uniquely detected objects. The second element is
          a torch.Tensor of size (K, 4), giving the ``xmin``, ``ymin``,
          ``xmax``, and ``ymax`` coordinates of the top-scoring boxes
          around each unique object. The third element is a torch.Tensor
          of size K containing the scores of each uniquely predicted object
          (ranges from 0.0 to 1.0). If given a list of images, returns a
          list of the tuples described above, each tuple corresponding to
          a single image.
      :rtype: tuple or list of tuple
  
  
      **Example**::
  
          >>> from detecto.core import Model
          >>> from detecto.utils import read_image
  
          >>> model = Model.load('model_weights.pth', ['label1', 'label2'])
          >>> image = read_image('image.jpg')
          >>> top_preds = model.predict_top(image)
          >>> 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]))
      """
  
      predictions = self.predict(images)
  
      # If tuple but not list, then images is a single image
      if not isinstance(predictions, list):
          return filter_top_predictions(*predictions)
  
      results = []
      for pred in predictions:
          results.append(filter_top_predictions(*pred))
  
      return results
  
imports: import os
  import pandas
  import random
  import torch
  import torchvision
  from detecto.config import config
  from detecto.utils import default_transforms, filter_top_predictions, xml_to_csv, _is_iterable, read_image
  from torchvision import transforms
  from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
  from tqdm import tqdm
label_desc: Use image node_id 4 for calling the Model obj's underlying member method code with example usage: obj.predict_top(images) and returns: results, filter_top_predictions