class_docstr: ImgTextTarDataset class for datasets that store Image-Text pairs as tar files, each tar file with multiple pairs.
  
  The dataset should be stored in following format where `img_text_tar_dataset` is the location of directory that
  has all tar files.
  
  img_text_tar_dataset
  |--- 00000000_0_1000.tar.gz
  |-------- 00000000_0_image
  |-------- 00000000_0_text
  |-------- 00000000_1_image
  |-------- 00000000_1_text
  |-------- ...
  
  |--- 00000000_1000_2000.tar.gz
  |-------- 00000000_1000_image
  |-------- 00000000_1000_text
  |-------- 00000000_1001_image
  |-------- 00000000_1001_text
  |-------- ...
  
  Args:
      opts: An argparse.Namespace instance.
class_docstr_tok: ["ImgTextTarDataset","class","for","datasets","that","store","Image-Text","pairs","as","tar","files",",","each","tar","file","with","multiple","pairs",".","The","dataset","should","be","stored","in","following","format","where","`","img_text_tar_dataset","`","is","the","location","of","directory","that","has","all","tar","files",".","img_text_tar_dataset","|","--","-","00000000_0_1000.tar.gz","|","--","--","--","--","00000000_0_image","|","--","--","--","--","00000000_0_text","|","--","--","--","--","00000000_1_image","|","--","--","--","--","00000000_1_text","|","--","--","--","--","...","|","--","-","00000000_1000_2000.tar.gz","|","--","--","--","--","00000000_1000_image","|","--","--","--","--","00000000_1000_text","|","--","--","--","--","00000000_1001_image","|","--","--","--","--","00000000_1001_text","|","--","--","--","--","...","Args",":","opts",":","An","argparse.Namespace","instance","."]
docstr: For a given image index, read the image file, corresponding caption, and class label.
  If class label is not present, -1 is returned.
docstr_tok: ["For","a","given","image","index",",","read","the","image","file",",","corresponding","caption",",","and","class","label",".","If","class","label","is","not","present",",","-1","is","returned","."]
code: def get_dataset_pair(
      self, img_index: int
  ) -> Tuple[Image.Image, str, int]:
      """For a given image index, read the image file, corresponding caption, and class label.
      If class label is not present, -1 is returned.
      """
      class_label = -1
      try:
          if img_index in self.dataset_keys:
              # file index is the same as the start index
              file_index = self.dataset_keys.index(img_index)
              # data index is 0 because file index is one of the start indices
              data_index = 0
              img_text_pair_id = self.dataset_keys[file_index]
          else:
              # find the index at which the element will be inserted.
              # Example: If we have an array of start indices as [0, 15, 35, 90] and
              # we want to find the position of image index 92, then the insertion index will be 4.
              insertion_idx = np.searchsorted(
                  self.dataset_keys, img_index
              )
  
              # the image id corresponding to 92 is stored in file whose start index is 90.
              # So, the file index is one less than insertion index
              file_index = insertion_idx - 1
  
              img_text_pair_id = self.dataset_keys[file_index]
  
              # data index is delta between current value (92) and value at file index (90)
              data_index = img_index - img_text_pair_id
  
          # get the key corresponding to file index and retrieve the file name
          # concatenate the file name with cache location path
          tar_file_name_from_metadata = self.dataset[img_text_pair_id]
  
          tar_file_name = os.path.join(
              self.cache_loc, tar_file_name_from_metadata
          )
          # Tar file name is encoded as: <path>/<folder_start_end.tar.gz>
          # each file name in tar file is encoded as: <folder_dataIdx_image> and <folder_dataIdx_text>
  
          # remove the tar extension because we have extracted the data when downloaded
          tar_file_name = tar_file_name.replace(self.__FILE_EXTN, "")
  
          if not os.path.isdir(tar_file_name):
              async_download_file_from_s3(
                  opts=self.opts,
                  tar_file_name=os.path.join(
                      self.s3_bucket_path, tar_file_name_from_metadata
                  ),
                  cache_loc=self.cache_loc,
              )
  
          # Based on this, decode the folder information
          folder_name = tar_file_name.split(os.sep)[-1].split("_")[0]
  
          # adjust the data index with start_id offset
          start_id = tar_file_name.split(os.sep)[-1].split("_")[1]
          data_index = data_index + int(start_id)
  
          img_text_fname = f"{tar_file_name}/{folder_name}_{data_index}"
          with open(f"{img_text_fname}_image", "rb") as img_byte_data:
              input_img = decode_image(img_byte_data.read())
  
          with open(f"{img_text_fname}_text", "rb") as text_byte_data:
              captions_str = decode_text(text_byte_data.read())
      except Exception as e:
          logger.log(
              "error loading {}. Error message: {}".format(
                  img_index, str(e)
              )
          )
  
          input_img = None
          captions_str = None
      return input_img, captions_str, class_label
  
imports: import argparse
  import glob
  import io
  import os
  import pickle
  import tarfile
  from multiprocessing.pool import Pool
  from typing import AnyStr, Dict, Tuple
  import numpy
  import torch
  from PIL import Image, ImageFile
  from data.datasets import DATASET_REGISTRY
  from data.datasets.multi_modal_img_text.base_multi_modal_img_text import BaseMultiModalImgText
  from utils import logger, resources
  from utils.ddp_utils import dist_barrier
  from utils.download_utils import get_local_path
label_desc: Use image node_id 6 for calling the ImgTextTarDataset obj's underlying member method code with example usage: obj.get_dataset_pair(img_index) and returns: input_img,  captions_str,  class_label