class_docstr: IIIT-5K character-level localization dataset from
  `"BMVC 2012 Scene Text Recognition using Higher Order Language Priors"
  <https://cdn.iiit.ac.in/cdn/cvit.iiit.ac.in/images/Projects/SceneTextUnderstanding/home/mishraBMVC12.pdf>`_.
  
  .. image:: https://doctr-static.mindee.com/models?id=v0.5.0/iiit5k-grid.png&src=0
      :align: center
  
  >>> # NOTE: this dataset is for character-level localization
  >>> from doctr.datasets import IIIT5K
  >>> train_set = IIIT5K(train=True, download=True)
  >>> img, target = train_set[0]
  
  Args:
  ----
      train: whether the subset should be the training one
      use_polygons: whether polygons should be considered as rotated bounding box (instead of straight ones)
      recognition_task: whether the dataset should be used for recognition task
      **kwargs: keyword arguments from `VisionDataset`.
class_docstr_tok: ["IIIT-5K","character-level","localization","dataset","from","`","``","BMVC","2012","Scene","Text","Recognition","using","Higher","Order","Language","Priors","''","<","https",":","\/\/cdn.iiit.ac.in\/cdn\/cvit.iiit.ac.in\/images\/Projects\/SceneTextUnderstanding\/home\/mishraBMVC12.pdf",">","`","_",".","..","image",":",":","https",":","\/\/doctr-static.mindee.com\/models","?","id=v0.5.0\/iiit5k-grid.png","&","src=0",":","align",":","center",">",">",">","#","NOTE",":","this","dataset","is","for","character-level","localization",">",">",">","from","doctr.datasets","import","IIIT5K",">",">",">","train_set","=","IIIT5K","(","train=True",",","download=True",")",">",">",">","img",",","target","=","train_set","[","0","]","Args",":","--","--","train",":","whether","the","subset","should","be","the","training","one","use_polygons",":","whether","polygons","should","be","considered","as","rotated","bounding","box","(","instead","of","straight","ones",")","recognition_task",":","whether","the","dataset","should","be","used","for","recognition","task","*","*","kwargs",":","keyword","arguments","from","`","VisionDataset","`","."]
code: def __init__(
      self,
      train: bool = True,
      use_polygons: bool = False,
      recognition_task: bool = False,
      **kwargs: Any,
  ) -> None:
      super().__init__(
          self.URL,
          None,
          file_hash=self.SHA256,
          extract_archive=True,
          pre_transforms=convert_target_to_relative
          if not recognition_task
          else None,
          **kwargs,
      )
      self.train = train
  
      # Load mat data
      tmp_root = (
          os.path.join(self.root, "IIIT5K")
          if self.SHA256
          else self.root
      )
      mat_file = "trainCharBound" if self.train else "testCharBound"
      mat_data = sio.loadmat(os.path.join(tmp_root, f"{mat_file}.mat"))[
          mat_file
      ][0]
  
      self.data: List[
          Tuple[Union[str, np.ndarray], Union[str, Dict[str, Any]]]
      ] = []
      np_dtype = np.float32
  
      for img_path, label, box_targets in tqdm(
          iterable=mat_data,
          desc="Unpacking IIIT5K",
          total=len(mat_data),
      ):
          _raw_path = img_path[0]
          _raw_label = label[0]
  
          # File existence check
          if not os.path.exists(os.path.join(tmp_root, _raw_path)):
              raise FileNotFoundError(
                  f"unable to locate {os.path.join(tmp_root, _raw_path)}"
              )
  
          if recognition_task:
              self.data.append((_raw_path, _raw_label))
          else:
              if use_polygons:
                  # (x, y) coordinates of top left, top right, bottom right, bottom left corners
                  box_targets = [
                      [
                          [box[0], box[1]],
                          [box[0] + box[2], box[1]],
                          [box[0] + box[2], box[1] + box[3]],
                          [box[0], box[1] + box[3]],
                      ]
                      for box in box_targets
                  ]
              else:
                  # xmin, ymin, xmax, ymax
                  box_targets = [
                      [box[0], box[1], box[0] + box[2], box[1] + box[3]]
                      for box in box_targets
                  ]
  
              # label are casted to list where each char corresponds to the character's bounding box
              self.data.append(
                  (
                      _raw_path,
                      dict(
                          boxes=np.asarray(box_targets, dtype=np_dtype),
                          labels=list(_raw_label),
                      ),
                  )
              )
  
      self.root = tmp_root
  
file_path: doctr/doctr/datasets/iiit5k.py
imports: import os
  from typing import Any, Dict, List, Tuple, Union
  import numpy
  import scipy.io
  from tqdm import tqdm
  from .datasets import VisionDataset
  from .utils import convert_target_to_relative
label_desc: Use image node_id 1 to create a new IIIT5K object from inherited base classes: VisionDataset with example: obj = IIIT5K(train, use_polygons, recognition_task)