class_docstr: LVIS PyTorch Object Detection Dataset
class_docstr_tok: ["LVIS","PyTorch","Object","Detection","Dataset"]
docstr: Loads an instance given its index.
  
  :param index: The index of the instance to retrieve.
  
  :return: a (sample, target) tuple where the target is a
      torchvision-style annotation for object detection
      https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html
docstr_tok: ["Loads","an","instance","given","its","index",".",":","param","index",":","The","index","of","the","instance","to","retrieve",".",":","return",":","a","(","sample",",","target",")","tuple","where","the","target","is","a","torchvision-style","annotation","for","object","detection","https",":","\/\/pytorch.org\/tutorials\/intermediate\/torchvision_tutorial.html"]
code: def __getitem__(self, index):
      """
      Loads an instance given its index.
  
      :param index: The index of the instance to retrieve.
  
      :return: a (sample, target) tuple where the target is a
          torchvision-style annotation for object detection
          https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html
      """
      img_id = self.img_ids[index]
      img_dict: LVISImgEntry = self.lvis_api.load_imgs(ids=[img_id])[0]
      annotation_dicts: LVISImgTargets = self.targets[index]
  
      # Transform from LVIS dictionary to torchvision-style target
      num_objs = annotation_dicts["bbox"].shape[0]
  
      boxes = []
      labels = []
      for i in range(num_objs):
          xmin = annotation_dicts["bbox"][i][0]
          ymin = annotation_dicts["bbox"][i][1]
          xmax = xmin + annotation_dicts["bbox"][i][2]
          ymax = ymin + annotation_dicts["bbox"][i][3]
          boxes.append([xmin, ymin, xmax, ymax])
          labels.append(annotation_dicts["category_id"][i])
  
      if len(boxes) > 0:
          boxes = torch.as_tensor(boxes, dtype=torch.float32)
      else:
          boxes = torch.empty((0, 4), dtype=torch.float32)
      labels = torch.as_tensor(labels, dtype=torch.int64)
  
      image_id = torch.tensor([img_id])
      areas = []
      for i in range(num_objs):
          areas.append(annotation_dicts["area"][i])
      areas = torch.as_tensor(areas, dtype=torch.float32)
      iscrowd = torch.zeros((num_objs,), dtype=torch.int64)
  
      target = dict()
      target["boxes"] = boxes
      target["labels"] = labels
      target["image_id"] = image_id
      target["area"] = areas
      target["iscrowd"] = iscrowd
  
      img = self._load_img(img_dict)
  
      if self.transform is not None:
          img, target = self.transform(img, target)
  
      return img, target
  
imports: from pathlib import Path
  from typing import Optional, Union, List, Sequence
  import torch
  from PIL import Image
  from torchvision.datasets.folder import default_loader
  from torchvision.transforms import ToTensor
  from typing_extensions import TypedDict
  from avalanche.benchmarks.datasets import DownloadableDataset, default_dataset_location
  from avalanche.benchmarks.datasets.lvis_dataset.lvis_data import lvis_archives
label_desc: Use image node_id 5 for calling the LvisDataset obj's underlying member method code with example usage: obj.__getitem__(index) and returns: img,  target