code: def _download_and_prepare(
      dataset_dir,
      scratch_dir,
      download_fcn,
      get_classes_fcn,
      get_num_samples_fcn,
      sample_parser,
  ):
      #
      # Download the TFDS dataset, if necessary
      #
      # Prevents ResourceExhaustedError that can arise...
      # https://github.com/tensorflow/datasets/issues/1441#issuecomment-581660890
      #
      with fou.ResourceLimit(
          "RLIMIT_NOFILE", soft=4096, warn_on_failure=True
      ):
          dataset, info = download_fcn(scratch_dir)
  
      classes = get_classes_fcn(info)
      num_samples = get_num_samples_fcn(info)
      sample_parser.classes = classes
      label_cls = sample_parser.label_cls
  
      if not isinstance(label_cls, (list, tuple)):
          label_cls = [label_cls]
  
      if fol.Classification in label_cls:
          dataset_type = fot.FiftyOneImageClassificationDataset()
          dataset_exporter = (
              foud.FiftyOneImageClassificationDatasetExporter(
                  dataset_dir, classes=classes
              )
          )
      elif fol.Detections in label_cls:
          dataset_type = fot.FiftyOneImageDetectionDataset()
          dataset_exporter = foud.FiftyOneImageDetectionDatasetExporter(
              dataset_dir, classes=classes
          )
      else:
          raise ValueError(
              "Unsupported sample parser %s" % type(sample_parser)
          )
  
      try:
          samples = dataset.as_numpy_iterator()
      except AttributeError:
          # Must be tensorflow < 2.1
          samples = tfds.as_numpy(dataset)
  
      # Write the formatted dataset to `dataset_dir`
      foud.write_dataset(
          samples,
          sample_parser,
          dataset_exporter,
          num_samples=num_samples,
      )
  
      return dataset_type, num_samples, classes
  
imports: import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.types
  import fiftyone.utils.imagenet
  import fiftyone.utils.data
  import fiftyone.zoo.datasets
label_desc: Use image node_id 1 for calling a global function with example usage: _download_and_prepare(dataset_dir, scratch_dir, download_fcn, get_classes_fcn, get_num_samples_fcn, sample_parser) and returns: dataset_type,  num_samples,  classes