code: def download_dataset(storage_client, image_batches, target_dir,
                       local_dataset_copy=None):
    
    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])
docs: 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'])