docstr: Accepts a :class:`detecto.core.Dataset` object and creates
  an iterable over the data, which can then be fed into a
  :class:`detecto.core.Model` for training and validation.
  Extends PyTorch's `DataLoader
  <https://pytorch.org/docs/stable/data.html>`_ class with a custom
  ``collate_fn`` function.
  
  :param dataset: The dataset for iteration over.
  :type dataset: detecto.core.Dataset
  :param kwargs: (Optional) Additional arguments to customize the
      DataLoader, such as ``batch_size`` or ``shuffle``. See `docs
      <https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader>`_
      for more details.
  :type kwargs: Any
  
  **Example**::
  
      >>> from detecto.core import Dataset, DataLoader
  
      >>> dataset = Dataset('labels.csv', 'images/')
      >>> loader = DataLoader(dataset, batch_size=2, shuffle=True)
      >>> for images, targets in loader:
      >>>     print(images[0].shape)
      >>>     print(targets[0])
      torch.Size([3, 1080, 1720])
      {'boxes': tensor([[884, 387, 937, 784]]), 'labels': ['person']}
      torch.Size([3, 1080, 1720])
      {'boxes': tensor([[   1,  410, 1657, 1079]]), 'labels': ['car']}
      ...
docstr_tok: ["Accepts","a",":","class",":","`","detecto.core.Dataset","`","object","and","creates","an","iterable","over","the","data",",","which","can","then","be","fed","into","a",":","class",":","`","detecto.core.Model","`","for","training","and","validation",".","Extends","PyTorch","'s","`","DataLoader","<","https",":","\/\/pytorch.org\/docs\/stable\/data.html",">","`","_","class","with","a","custom","``","collate_fn","``","function",".",":","param","dataset",":","The","dataset","for","iteration","over",".",":","type","dataset",":","detecto.core.Dataset",":","param","kwargs",":","(","Optional",")","Additional","arguments","to","customize","the","DataLoader",",","such","as","``","batch_size","``","or","``","shuffle","``",".","See","`","docs","<","https",":","\/\/pytorch.org\/docs\/stable\/data.html","#","torch.utils.data.DataLoader",">","`","_","for","more","details",".",":","type","kwargs",":","Any","*","*","Example","*","*",":",":",">",">",">","from","detecto.core","import","Dataset",",","DataLoader",">",">",">","dataset","=","Dataset","(","'labels.csv","'",",","'images\/","'",")",">",">",">","loader","=","DataLoader","(","dataset",",","batch_size=2",",","shuffle=True",")",">",">",">","for","images",",","targets","in","loader",":",">",">",">","print","(","images","[","0","]",".shape",")",">",">",">","print","(","targets","[","0","]",")","torch.Size","(","[","3",",","1080",",","1720","]",")","{","'boxes","'",":","tensor","(","[","[","884",",","387",",","937",",","784","]","]",")",",","'labels","'",":","[","'person","'","]","}","torch.Size","(","[","3",",","1080",",","1720","]",")","{","'boxes","'",":","tensor","(","[","[","1",",","410",",","1657",",","1079","]","]",")",",","'labels","'",":","[","'car","'","]","}","..."]
code: def __init__(self, dataset, **kwargs):
      """Accepts a :class:`detecto.core.Dataset` object and creates
      an iterable over the data, which can then be fed into a
      :class:`detecto.core.Model` for training and validation.
      Extends PyTorch's `DataLoader
      <https://pytorch.org/docs/stable/data.html>`_ class with a custom
      ``collate_fn`` function.
  
      :param dataset: The dataset for iteration over.
      :type dataset: detecto.core.Dataset
      :param kwargs: (Optional) Additional arguments to customize the
          DataLoader, such as ``batch_size`` or ``shuffle``. See `docs
          <https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader>`_
          for more details.
      :type kwargs: Any
  
      **Example**::
  
          >>> from detecto.core import Dataset, DataLoader
  
          >>> dataset = Dataset('labels.csv', 'images/')
          >>> loader = DataLoader(dataset, batch_size=2, shuffle=True)
          >>> for images, targets in loader:
          >>>     print(images[0].shape)
          >>>     print(targets[0])
          torch.Size([3, 1080, 1720])
          {'boxes': tensor([[884, 387, 937, 784]]), 'labels': ['person']}
          torch.Size([3, 1080, 1720])
          {'boxes': tensor([[   1,  410, 1657, 1079]]), 'labels': ['car']}
          ...
      """
  
      super().__init__(
          dataset, collate_fn=DataLoader.collate_data, **kwargs
      )
  
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 DataLoader object from inherited base classes: torch.utils.data with example: obj = DataLoader(dataset)