code: def _get_label_data(
      dataset_dir,
      image_ids,
      label_type,
      classes=None,
      oi_classes=None,
      download_only=False,
      ids_only=False,
      track_all_ids=True,
      only_matching=False,
      url=None,
      download=True,
  ):
      csv_path = os.path.join(
          dataset_dir, "labels", label_type + ".csv"
      )
      did_download = _download_file_if_necessary(
          csv_path, url, quiet=0, download=download
      )
  
      if download_only:
          return set(), set(), {}, did_download
  
      df = _parse_csv(csv_path, dataframe=True)
  
      if label_type == "points":
          df["ImageID"] = df["ImageId"]
          df = df.drop(columns=["ImageId"])
  
      df.set_index("ImageID", drop=False, inplace=True)
      df = df.loc[df.index.intersection(image_ids)]
  
      if classes is not None:
          # Restrict by classes
          if label_type == "relationships":
              cols = ["LabelName1", "LabelName2"]
          elif label_type == "points":
              cols = [
                  "X",
                  "Y",
                  "Label",
                  "EstimatedYesNo",
                  "Source",
                  "YesVotes",
                  "NoVotes",
                  "UnsureVotes",
                  "TextLabel",
              ]
          else:
              cols = ["LabelName"]
  
          oi_classes = set(oi_classes)
  
          if track_all_ids:
              observed = defaultdict(set)
              for image_id, labels in zip(
                  df["ImageID"].values, df[cols].values
              ):
                  observed[image_id].update(labels)
  
              all_ids = set()
              any_ids = set()
              for image_id, observed_classes in observed.items():
                  if oi_classes.issubset(observed_classes):
                      all_ids.add(image_id)
  
                  if oi_classes & observed_classes:
                      any_ids.add(image_id)
          else:
              any_df = df[df[cols].isin(oi_classes).any(axis=1)]
              all_ids = set()
              any_ids = set(any_df["ImageID"].unique())
      else:
          # No class restriction
          all_ids = set()
          any_ids = set(df["ImageID"].unique())
  
      if ids_only:
          return all_ids, any_ids, {}, did_download
  
      if classes is not None:
          if only_matching:
              # Only keep the specified labels
              relevant_df = df[
                  df[cols].isin(oi_classes).any(axis=1)
              ].copy()
          else:
              # Keep all labels for the relevant image IDs
              relevant_df = df.loc[df.index.intersection(any_ids)]
      else:
          relevant_df = df
  
      relevant_df.sort_index(inplace=True)
  
      data = {
          "all_ids": set(df["ImageID"].unique()),
          "relevant_ids": any_ids,
          "df": relevant_df,
      }
  
      return all_ids, any_ids, data, did_download
  
imports: from collections import defaultdict
  import csv
  from glob import glob
  import logging
  import os
  import random
  import warnings
  import pandas
  import eta.core.image
  import eta.core.serial
  import eta.core.utils
  import eta.core.web
  import fiftyone
  import fiftyone.core.fields
  import fiftyone.core.labels
  import fiftyone.utils.aws
  import fiftyone.utils.data
  import fiftyone.utils.image
label_desc: Use image node_id 21 for calling a global function with example usage: _get_label_data(dataset_dir, image_ids, label_type, classes, oi_classes, download_only, ids_only, track_all_ids, only_matching, url, download) and returns: all_ids,  any_ids,  data,  did_download, set,  set,  dict,  did_download, all_ids,  any_ids,  dict,  did_download