code: def download_dataset(
      storage_client, image_batches, target_dir, local_dataset_copy=None
  ):
      """Downloads dataset, organize it by batches and rename images.
  
      Args:
        storage_client: instance of the CompetitionStorageClient
        image_batches: subclass of ImageBatchesBase with data about images
        target_dir: target directory, should exist and be empty
        local_dataset_copy: directory with local dataset copy, if local copy is
          available then images will be takes from there instead of Cloud Storage
  
      Data in the target directory will be organized into subdirectories by batches,
      thus path to each image will be "target_dir/BATCH_ID/IMAGE_ID.png"
      where BATCH_ID - ID of the batch (key of image_batches.data),
      IMAGE_ID - ID of the image (key of image_batches.data[batch_id]['images'])
      """
      for batch_id, batch_value in iteritems(image_batches.data):
          batch_dir = os.path.join(target_dir, batch_id)
          os.mkdir(batch_dir)
          for image_id, image_val in iteritems(batch_value["images"]):
              dst_filename = os.path.join(batch_dir, image_id + ".png")
              # try to use local copy first
              if local_dataset_copy:
                  local_filename = os.path.join(
                      local_dataset_copy,
                      os.path.basename(image_val["image_path"]),
                  )
                  if os.path.exists(local_filename):
                      shutil.copyfile(local_filename, dst_filename)
                      continue
              # download image from cloud
              cloud_path = (
                  "gs://"
                  + storage_client.bucket_name
                  + "/"
                  + image_val["image_path"]
              )
              if not os.path.exists(dst_filename):
                  subprocess.call(
                      ["gsutil", "cp", cloud_path, dst_filename]
                  )
  
file_path: cleverhans/cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/dataset_helper.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import csv
  import hashlib
  import logging
  import os
  import shutil
  import subprocess
  import numpy
  from PIL import Image
  from six import iteritems
label_desc: Use image node_id 2 for calling a global function with example usage: download_dataset(storage_client, image_batches, target_dir, local_dataset_copy) without return types