code: def __init__(
      self,
      data_path,
      data_debug_path,
      per_sample_image,
      tokenizer,
      vis_processor,
      **kwargs,
  ):
      vis_root = f"{data_path}/coco/train2017"
      assert os.path.isdir(
          vis_root
      ), f"OtterMimicitCgdDataset image directory {vis_root} not found, you need to download 2017 Train images from https://cocodataset.org/#download"
      ### Below commented code are the images from the MIMIC-IT. We use the original coco images above which are the same and with higher resolution.
      # vis_root = f"{data_path}/MIMIC-IT/CGD_images"
      # if not os.path.isdir(vis_root):
      #     print_rank_0(f"OtterMimicitCgdDataset image directory {vis_root} not found, starting an one-time preprocessing:")
      #     vis_root_file = f"{data_path}/MIMIC-IT/CGD.json"
      #     assert os.path.isfile(vis_root_file), f"OtterMimicitCgdDataset image data {vis_root_file} not found, you need to download it from https://huggingface.co/datasets/pufanyi/MIMICIT"
      #     if is_rank_0():
      #         os.makedirs(vis_root, exist_ok=True)
      #         image_data = json.load(open(vis_root_file, "r"))
      #         image_keys = list(image_data.keys())
      #         for k in tqdm(image_keys):
      #             image = base64.b64decode(image_data[k])
      #             with open(f"{vis_root}/{k}.jpg", 'wb') as f:
      #                 f.write(image)
      # torch.distributed.barrier()
  
      ann_paths_raw = ["MIMIC-IT/CGD_instructions.json"]
      ann_paths = ["MIMIC-IT/CGD_instructions_merged.json"]
      for idx in range(len(ann_paths)):
          ann_paths_raw[idx] = f"{data_path}/{ann_paths_raw[idx]}"
          ann_paths[idx] = f"{data_path}/{ann_paths[idx]}"
          assert os.path.isfile(
              ann_paths_raw[idx]
          ), f"OtterMimicitCgdDataset raw annotation file {ann_paths_raw[idx]} not found, you need to download it from https://huggingface.co/datasets/pufanyi/MIMICIT"
          if not os.path.isfile(ann_paths[idx]):
              print_rank_0(
                  f"OtterMimicitCgdDataset annotation file {ann_paths[idx]} not found, starting an one-time preprocessing:"
              )
              if is_rank_0():
                  raw_annotation = json.load(
                      open(ann_paths_raw[idx], "r")
                  )["data"]
                  raw_annotation_keys = list(raw_annotation.keys())
                  random.shuffle(raw_annotation_keys)
                  annotations = []
                  for k in tqdm(raw_annotation_keys):
                      if k in raw_annotation:
                          ann = {}
                          ann["image_ids"] = raw_annotation[k][
                              "image_ids"
                          ]
                          ann["instruction"] = [
                              raw_annotation[k]["instruction"]
                          ]
                          ann["answer"] = [raw_annotation[k]["answer"]]
                          rel_ins_ids = raw_annotation[k]["rel_ins_ids"]
                          for k_rel in rel_ins_ids:
                              if k_rel in raw_annotation:
                                  ann["instruction"].append(
                                      raw_annotation[k_rel][
                                          "instruction"
                                      ]
                                  )
                                  ann["answer"].append(
                                      raw_annotation[k_rel]["answer"]
                                  )
                                  del raw_annotation[k_rel]
                          annotations.append(ann)
                          del raw_annotation[k]
                  with open(ann_paths[idx], "w") as f:
                      json.dump(annotations, f)
          torch.distributed.barrier()
      super().__init__(
          data_path,
          data_debug_path,
          per_sample_image,
          tokenizer,
          vis_processor,
          vis_root,
          ann_paths,
          **kwargs,
      )
  
file_path: deepspeedexamples/applications/DeepSpeed-VisualChat/utils/data/otter_mimicit_cgd_dataset.py
imports: import os
  import torch
  import json
  import random
  from tqdm import tqdm
  from PIL import Image
  from .vqa_dataset import VQADataset
  from utils.utils import print_rank_0, is_rank_0, get_rank
  from .utils import save_debug_image, save_debug_text
label_desc: Use image node_id 1 to create a new OtterMimicitCgdDataset object from inherited base classes: VQADataset with example: obj = OtterMimicitCgdDataset(data_path, data_debug_path, per_sample_image, tokenizer, vis_processor)