code: def _download(
      image_ids,
      downloaded_ids,
      oi_classes,
      oi_attrs,
      seg_classes,
      pnt_classes,
      dataset_dir,
      split,
      label_types=None,
      classes=None,
      attrs=None,
      max_samples=None,
      shuffle=False,
      num_workers=None,
      download=True,
      version=None,
  ):
      # Download any necessary labels, and, if specific classes/attributes are
      # requested, determine which image IDs have the specified labels
      (
          _,
          _,
          _,
          _,
          _,
          all_label_ids,
          any_label_ids,
          did_download,
      ) = _get_all_label_data(
          dataset_dir,
          image_ids,
          label_types=label_types,
          classes=classes,
          oi_classes=oi_classes,
          attrs=attrs,
          oi_attrs=oi_attrs,
          seg_classes=seg_classes,
          pnt_classes=pnt_classes,
          download_only=classes is None and attrs is None,
          ids_only=True,
          track_all_ids=max_samples is not None,
          split=split,
          download=download,
          version=version,
      )
  
      downloaded_ids = set(downloaded_ids)
  
      # Make list of `target_ids`
      if classes is not None or attrs is not None:
          if max_samples is not None:
              #
              # Bias sampling to meet user requirements per the priorities below:
              # (1) samples with all labels
              # (2) already downloaded samples with relevant labels
              # (3) non-downloaded samples with relevant labels
              #
  
              not_all_ids = any_label_ids - all_label_ids
              existing_ids = not_all_ids & downloaded_ids
              non_existing_ids = not_all_ids - downloaded_ids
  
              all_label_ids = sorted(all_label_ids)
              existing_ids = sorted(existing_ids)
              non_existing_ids = sorted(non_existing_ids)
  
              if shuffle:
                  random.shuffle(all_label_ids)
                  random.shuffle(existing_ids)
                  random.shuffle(non_existing_ids)
  
              target_ids = (
                  all_label_ids + existing_ids + non_existing_ids
              )
              target_ids = target_ids[:max_samples]
          else:
              # Include all samples that meet any requirement
              target_ids = sorted(any_label_ids)
  
              if shuffle:
                  random.shuffle(target_ids)
      else:
          if max_samples is not None:
              # Bias sampling towards already-downloaded samples
              image_ids = set(image_ids)
              existing_ids = sorted(image_ids & downloaded_ids)
              non_existing_ids = sorted(image_ids - downloaded_ids)
  
              if shuffle:
                  random.shuffle(existing_ids)
                  random.shuffle(non_existing_ids)
  
              target_ids = existing_ids + non_existing_ids
              target_ids = target_ids[:max_samples]
          else:
              # Use all available samples
              target_ids = sorted(image_ids)
  
              if shuffle:
                  random.shuffle(target_ids)
  
      num_target = len(target_ids)
      all_ids = list(downloaded_ids | set(target_ids))
      num_samples = len(all_ids)  # total downloaded
  
      if max_samples is not None and num_target < max_samples:
          logger.warning(
              "Only found %d (<%d) samples matching your requirements",
              num_target,
              max_samples,
          )
  
      if "segmentations" in label_types:
          _did_download = _download_masks_if_necessary(
              all_ids, dataset_dir, split, download=download
          )
          did_download |= _did_download
      num_downloaded = _download_images_if_necessary(
          target_ids,
          split,
          dataset_dir,
          num_workers=num_workers,
          download=download,
      )
  
      if num_downloaded > 0:
          did_download = True
  
      return num_samples, 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 22 for calling a global function with example usage: _download(image_ids, downloaded_ids, oi_classes, oi_attrs, seg_classes, pnt_classes, dataset_dir, split, label_types, classes, attrs, max_samples, shuffle, num_workers, download, version) and returns: num_samples,  did_download