class_docstr: `iNaturalist <https://github.com/visipedia/inat_comp>`_ Dataset.
  
  Args:
      root (string): Root directory of dataset where the image files are stored.
          This class does not require/use annotation files.
      version (string, optional): Which version of the dataset to download/use. One of
          '2017', '2018', '2019', '2021_train', '2021_train_mini', '2021_valid'.
          Default: `2021_train`.
      target_type (string or list, optional): Type of target to use, for 2021 versions, one of:
  
          - ``full``: the full category (species)
          - ``kingdom``: e.g. "Animalia"
          - ``phylum``: e.g. "Arthropoda"
          - ``class``: e.g. "Insecta"
          - ``order``: e.g. "Coleoptera"
          - ``family``: e.g. "Cleridae"
          - ``genus``: e.g. "Trichodes"
  
          for 2017-2019 versions, one of:
  
          - ``full``: the full (numeric) category
          - ``super``: the super category, e.g. "Amphibians"
  
          Can also be a list to output a tuple with all specified target types.
          Defaults to ``full``.
      transform (callable, optional): A function/transform that takes in a PIL image
          and returns a transformed version. E.g, ``transforms.RandomCrop``
      target_transform (callable, optional): A function/transform that takes in the
          target and transforms it.
      download (bool, optional): If true, downloads the dataset from the internet and
          puts it in root directory. If dataset is already downloaded, it is not
          downloaded again.
docstr: Initialize based on 2017-2019 layout
docstr_tok: ["Initialize","based","on","2017-2019","layout"]
code: def _init_pre2021(self) -> None:
      """Initialize based on 2017-2019 layout"""
  
      # map: category type -> name of category -> index
      self.categories_index = {"super": {}}
  
      cat_index = 0
      super_categories = sorted(os.listdir(self.root))
      for sindex, scat in enumerate(super_categories):
          self.categories_index["super"][scat] = sindex
          subcategories = sorted(
              os.listdir(os.path.join(self.root, scat))
          )
          for subcat in subcategories:
              if self.version == "2017":
                  # this version does not use ids as directory names
                  subcat_i = cat_index
                  cat_index += 1
              else:
                  try:
                      subcat_i = int(subcat)
                  except ValueError:
                      raise RuntimeError(
                          f"Unexpected non-numeric dir name: {subcat}"
                      )
              if subcat_i >= len(self.categories_map):
                  old_len = len(self.categories_map)
                  self.categories_map.extend(
                      [{}] * (subcat_i - old_len + 1)
                  )
                  self.all_categories.extend(
                      [""] * (subcat_i - old_len + 1)
                  )
              if self.categories_map[subcat_i]:
                  raise RuntimeError(f"Duplicate category {subcat}")
              self.categories_map[subcat_i] = {"super": sindex}
              self.all_categories[subcat_i] = os.path.join(scat, subcat)
  
      # validate the dictionary
      for cindex, c in enumerate(self.categories_map):
          if not c:
              raise RuntimeError(f"Missing category {cindex}")
  
file_path: vision/torchvision/datasets/inaturalist.py
imports: import os
  import os.path
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  from PIL import Image
  from .utils import download_and_extract_archive, verify_str_arg
  from .vision import VisionDataset
label_desc: Use image node_id 3 for calling the INaturalist obj's underlying member method code with example usage: obj._init_pre2021() without return types