class_docstr: LVIS PyTorch Object Detection Dataset
class_docstr_tok: ["LVIS","PyTorch","Object","Detection","Dataset"]
code: def _load_metadata(self) -> bool:
      must_load_api = self.lvis_api is None
      must_load_img_ids = self.img_ids is None
      try:
          # Load metadata
          if must_load_api:
              if self.train:
                  ann_json_path = str(self.root / "lvis_v1_train.json")
              else:
                  ann_json_path = str(self.root / "lvis_v1_val.json")
  
              self.lvis_api = LVIS(ann_json_path)
  
          lvis_api = self.lvis_api
          if must_load_img_ids:
              self.img_ids = list(sorted(lvis_api.get_img_ids()))
  
          self.targets = LVISDetectionTargets(lvis_api, self.img_ids)
  
          # Try loading an image
          if len(self.img_ids) > 0:
              img_id = self.img_ids[0]
              img_dict: LVISImgEntry = self.lvis_api.load_imgs(
                  ids=[img_id]
              )[0]
              assert self._load_img(img_dict) is not None
      except BaseException:
          if must_load_api:
              self.lvis_api = None  # type: ignore
          if must_load_img_ids:
              self.img_ids = None  # type: ignore
  
          self.targets = None  # type: ignore
          raise
  
      return True
  
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 3 for calling the LvisDataset obj's underlying member method code with example usage: obj._load_metadata() and returns: True