code: def main():
      input_filename, output_dir, n_threads = parse_args()
  
      if not os.path.isdir(output_dir):
          print("Output directory {} does not exist".format(output_dir))
          sys.exit()
  
      with open(input_filename) as input_file:
          reader = csv.reader(input_file)
          header_row = next(reader)
          rows = list(reader)
      try:
          row_idx_image_id = header_row.index("ImageId")
          row_idx_url = header_row.index("URL")
          row_idx_x1 = header_row.index("x1")
          row_idx_y1 = header_row.index("y1")
          row_idx_x2 = header_row.index("x2")
          row_idx_y2 = header_row.index("y2")
      except ValueError as e:
          print(
              "One of the columns was not found in the source file: ",
              e.message,
          )
  
      rows = [
          (
              row[row_idx_image_id],
              row[row_idx_url],
              float(row[row_idx_x1]),
              float(row[row_idx_y1]),
              float(row[row_idx_x2]),
              float(row[row_idx_y2]),
          )
          for row in rows
      ]
  
      if n_threads > 1:
          pool = ThreadPool(n_threads)
          partial_get_images = partial(get_image, output_dir=output_dir)
          for i, _ in enumerate(
              pool.imap_unordered(partial_get_images, rows), 1
          ):
              sys.stderr.write("\rDownloaded {0} images".format(i + 1))
          pool.close()
          pool.join()
      else:
          failed_to_download = set()
          for idx in range(len(rows)):
              row = rows[idx]
              if not download_image(
                  image_id=row[0],
                  url=row[1],
                  x1=float(row[2]),
                  y1=float(row[3]),
                  x2=float(row[4]),
                  y2=float(row[5]),
                  output_dir=output_dir,
              ):
                  failed_to_download.add(row[row_idx_image_id])
              sys.stdout.write(
                  "\rDownloaded {0} images".format(idx + 1)
              )
              sys.stdout.flush()
  
          print()
          if failed_to_download:
              print(
                  "\nUnable to download images with the following IDs:"
              )
              for image_id in failed_to_download:
                  print(image_id)
  
file_path: cleverhans/cleverhans_v3.1.0/examples/nips17_adversarial_competition/dataset/download_images.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import csv
  import os
  import sys
  from functools import partial
  from io import BytesIO
  import multiprocessing
  from multiprocessing.dummy import Pool
  from PIL import Image
label_desc: Use image node_id 4 for calling a global function with example usage: main() without return types