code: def __getitem__(self, idx):
      word_list, label_list, img = (
          self.data_dict["words"][idx],
          self.data_dict["targets"][idx],
          self.data_dict["imgs"][idx],
      )
      tokens, labels = [], []
      for i, word in enumerate(word_list):
          token = self.tokenizer.tokenize(word)
          tokens.extend(token)
          label = label_list[i]
          for m in range(len(token)):
              if m == 0:
                  labels.append(self.label_mapping[label])
              else:
                  labels.append(self.label_mapping["X"])
      if len(tokens) >= self.max_seq - 1:
          tokens = tokens[0 : (self.max_seq - 2)]
          labels = labels[0 : (self.max_seq - 2)]
  
      encode_dict = self.tokenizer.encode_plus(
          tokens,
          max_length=self.max_seq,
          truncation=True,
          padding="max_length",
      )
      input_ids, token_type_ids, attention_mask = (
          encode_dict["input_ids"],
          encode_dict["token_type_ids"],
          encode_dict["attention_mask"],
      )
      labels = (
          [self.label_mapping["[CLS]"]]
          + labels
          + [self.label_mapping["[SEP]"]]
          + [self.ignore_idx] * (self.max_seq - len(labels) - 2)
      )
  
      if self.img_path is not None:
          self.img_path = os.path.join(self.cwd, self.img_path)
          # image process
          try:
              img_path = os.path.join(self.img_path, img)
              image = Image.open(img_path).convert("RGB")
              image = self.clip_processor(
                  images=image, return_tensors="pt"
              )["pixel_values"].squeeze()
          except:
              img_path = os.path.join(self.img_path, "inf.png")
              image = Image.open(img_path).convert("RGB")
              image = self.clip_processor(
                  images=image, return_tensors="pt"
              )["pixel_values"].squeeze()
  
          if self.aux_img_path is not None:
              aux_imgs = []
              aux_img_paths = []
              if img in self.data_dict["aux_imgs"]:
                  aux_img_paths = self.data_dict["aux_imgs"][img]
                  aux_img_paths = [
                      os.path.join(self.aux_img_path, path)
                      for path in aux_img_paths
                  ]
              for i in range(min(3, len(aux_img_paths))):
                  aux_img = Image.open(
                      os.path.join(self.cwd, aux_img_paths[i])
                  ).convert("RGB")
                  aux_img = self.aux_processor(
                      images=aux_img, return_tensors="pt"
                  )["pixel_values"].squeeze()
                  aux_imgs.append(aux_img)
  
              for i in range(3 - len(aux_imgs)):
                  aux_imgs.append(
                      torch.zeros((3, self.aux_size, self.aux_size))
                  )
  
              aux_imgs = torch.stack(aux_imgs, dim=0)
              assert len(aux_imgs) == 3
  
              if self.rcnn_img_path is not None:
                  rcnn_imgs = []
                  rcnn_img_paths = []
                  img = img.split(".")[0]
                  if img in self.data_dict["rcnn_imgs"]:
                      rcnn_img_paths = self.data_dict["rcnn_imgs"][img]
                      rcnn_img_paths = [
                          os.path.join(self.rcnn_img_path, path)
                          for path in rcnn_img_paths
                      ]
                  for i in range(min(3, len(rcnn_img_paths))):
                      rcnn_img = Image.open(
                          os.path.join(self.cwd, rcnn_img_paths[i])
                      ).convert("RGB")
                      rcnn_img = self.rcnn_processor(
                          images=rcnn_img, return_tensors="pt"
                      )["pixel_values"].squeeze()
                      rcnn_imgs.append(rcnn_img)
  
                  for i in range(3 - len(rcnn_imgs)):
                      rcnn_imgs.append(
                          torch.zeros(
                              (3, self.rcnn_size, self.rcnn_size)
                          )
                      )
  
                  rcnn_imgs = torch.stack(rcnn_imgs, dim=0)
                  assert len(rcnn_imgs) == 3
                  return (
                      torch.tensor(input_ids),
                      torch.tensor(token_type_ids),
                      torch.tensor(attention_mask),
                      torch.tensor(labels),
                      image,
                      aux_imgs,
                      rcnn_imgs,
                  )
  
              return (
                  torch.tensor(input_ids),
                  torch.tensor(token_type_ids),
                  torch.tensor(attention_mask),
                  torch.tensor(labels),
                  image,
                  aux_imgs,
              )
  
      assert (
          len(input_ids)
          == len(token_type_ids)
          == len(attention_mask)
          == len(labels)
      )
      return (
          torch.tensor(input_ids),
          torch.tensor(token_type_ids),
          torch.tensor(attention_mask),
          torch.tensor(labels),
      )
  
file_path: DeepKE/src/deepke/name_entity_re/multimodal/modules/dataset.py
imports: import torch
  import os
  from PIL import Image
  from torch.utils.data import Dataset
  from transformers import BertTokenizer, CLIPProcessor
  import logging
label_desc: Use image node_id 3 for calling the MMPNERDataset obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: torch,  torch,  torch,  torch, torch,  torch,  torch,  torch,  image,  aux_imgs, torch,  torch,  torch,  torch,  image,  aux_imgs,  rcnn_imgs