docstr: Initializes a machine learning model for object detection.
  Models are built on top of PyTorch's `pre-trained models
  <https://pytorch.org/docs/stable/torchvision/models.html>`_,
  specifically the Faster R-CNN architectures, but allow for
  fine-tuning to predict on custom classes/labels.
  
  :param classes: (Optional) A list of classes/labels for the model
      to predict. If none given, uses the default classes specified
      `here <https://pytorch.org/docs/stable/torchvision/models.html
      #object-detection-instance-segmentation-and-person-keypoint-detection>`_.
      Defaults to None.
  :type classes: list or None
  :param device: (Optional) The device on which to run the model,
      such as the CPU or GPU. See `here
      <https://pytorch.org/docs/stable/tensor_attributes.html#torch-device>`_
      for details on specifying the device. Defaults to the GPU if
      available and the CPU if not.
  :type device: torch.device or None
  :param pretrained: (Optional) Whether to load pretrained weights or not.
      Defaults to True. 
  :type pretrained: bool
  :param model_name: (Optional) The name of the Faster R-CNN model to use.
      Valid choices are ``"fasterrcnn_resnet50_fpn"`` (``Model.DEFAULT``),
      ``"fasterrcnn_mobilenet_v3_large_fpn"`` (``Model.MOBILENET``), and
      ``"fasterrcnn_mobilenet_v3_large_320_fpn"`` (``Model.MOBILENET_320``).
      Defaults to ``"fasterrcnn_resnet50_fpn"``.
  :type model_name: str
  
  **Example**::
  
      >>> from detecto.core import Model
  
      >>> model = Model(['dog', 'cat', 'bunny'])
docstr_tok: ["Initializes","a","machine","learning","model","for","object","detection",".","Models","are","built","on","top","of","PyTorch","'s","`","pre-trained","models","<","https",":","\/\/pytorch.org\/docs\/stable\/torchvision\/models.html",">","`","_",",","specifically","the","Faster","R-CNN","architectures",",","but","allow","for","fine-tuning","to","predict","on","custom","classes\/labels",".",":","param","classes",":","(","Optional",")","A","list","of","classes\/labels","for","the","model","to","predict",".","If","none","given",",","uses","the","default","classes","specified","`","here","<","https",":","\/\/pytorch.org\/docs\/stable\/torchvision\/models.html","#","object-detection-instance-segmentation-and-person-keypoint-detection",">","`","_",".","Defaults","to","None",".",":","type","classes",":","list","or","None",":","param","device",":","(","Optional",")","The","device","on","which","to","run","the","model",",","such","as","the","CPU","or","GPU",".","See","`","here","<","https",":","\/\/pytorch.org\/docs\/stable\/tensor_attributes.html","#","torch-device",">","`","_","for","details","on","specifying","the","device",".","Defaults","to","the","GPU","if","available","and","the","CPU","if","not",".",":","type","device",":","torch.device","or","None",":","param","pretrained",":","(","Optional",")","Whether","to","load","pretrained","weights","or","not",".","Defaults","to","True",".",":","type","pretrained",":","bool",":","param","model_name",":","(","Optional",")","The","name","of","the","Faster","R-CNN","model","to","use",".","Valid","choices","are","``","``","fasterrcnn_resnet50_fpn","''","``","(","``","Model.DEFAULT","``",")",",","``","``","fasterrcnn_mobilenet_v3_large_fpn","''","``","(","``","Model.MOBILENET","``",")",",","and","``","``","fasterrcnn_mobilenet_v3_large_320_fpn","''","``","(","``","Model.MOBILENET_320","``",")",".","Defaults","to","``","``","fasterrcnn_resnet50_fpn","''","``",".",":","type","model_name",":","str","*","*","Example","*","*",":",":",">",">",">","from","detecto.core","import","Model",">",">",">","model","=","Model","(","[","'dog","'",",","'cat","'",",","'bunny","'","]",")"]
code: def __init__(
      self,
      classes=None,
      device=None,
      pretrained=True,
      model_name=DEFAULT,
  ):
      """Initializes a machine learning model for object detection.
      Models are built on top of PyTorch's `pre-trained models
      <https://pytorch.org/docs/stable/torchvision/models.html>`_,
      specifically the Faster R-CNN architectures, but allow for
      fine-tuning to predict on custom classes/labels.
  
      :param classes: (Optional) A list of classes/labels for the model
          to predict. If none given, uses the default classes specified
          `here <https://pytorch.org/docs/stable/torchvision/models.html
          #object-detection-instance-segmentation-and-person-keypoint-detection>`_.
          Defaults to None.
      :type classes: list or None
      :param device: (Optional) The device on which to run the model,
          such as the CPU or GPU. See `here
          <https://pytorch.org/docs/stable/tensor_attributes.html#torch-device>`_
          for details on specifying the device. Defaults to the GPU if
          available and the CPU if not.
      :type device: torch.device or None
      :param pretrained: (Optional) Whether to load pretrained weights or not.
          Defaults to True.
      :type pretrained: bool
      :param model_name: (Optional) The name of the Faster R-CNN model to use.
          Valid choices are ``"fasterrcnn_resnet50_fpn"`` (``Model.DEFAULT``),
          ``"fasterrcnn_mobilenet_v3_large_fpn"`` (``Model.MOBILENET``), and
          ``"fasterrcnn_mobilenet_v3_large_320_fpn"`` (``Model.MOBILENET_320``).
          Defaults to ``"fasterrcnn_resnet50_fpn"``.
      :type model_name: str
  
      **Example**::
  
          >>> from detecto.core import Model
  
          >>> model = Model(['dog', 'cat', 'bunny'])
      """
  
      self._device = device if device else config["default_device"]
  
      # Load a model pre-trained on COCO
      if model_name == self.DEFAULT:
          self._model = (
              torchvision.models.detection.fasterrcnn_resnet50_fpn(
                  pretrained=pretrained
              )
          )
      elif model_name == self.MOBILENET:
          self._model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_fpn(
              pretrained=pretrained
          )
      elif model_name == self.MOBILENET_320:
          self._model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_320_fpn(
              pretrained=pretrained
          )
      else:
          raise ValueError(
              f"Invalid value {model_name} for model_name. "
              + f"Please choose between {self.DEFAULT}, {self.MOBILENET}, and {self.MOBILENET_320}."
          )
  
      if classes:
          # Get the number of input features for the classifier
          in_features = (
              self._model.roi_heads.box_predictor.cls_score.in_features
          )
          # Replace the pre-trained head with a new one (note: +1 because of the __background__ class)
          self._model.roi_heads.box_predictor = FastRCNNPredictor(
              in_features, len(classes) + 1
          )
          self._disable_normalize = False
      else:
          classes = config["default_classes"]
          self._disable_normalize = True
  
      self._model.to(self._device)
  
      # Mappings to convert from string labels to ints and vice versa
      self._classes = ["__background__"] + classes
      self._int_mapping = {
          label: index for index, label in enumerate(self._classes)
      }
  
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 1 to create a new Model object  with example: obj = Model(classes, device, pretrained, model_name)