code: def maybe_download_image_dataset(image_ids, target_dir):
      """Download a set of images from api.brain-map.org to `target_dir`.
  
      Args:
        image_ids: list, a list of image ids.
        target_dir: str, a directory to which to download the images.
      """
  
      tf.gfile.MakeDirs(target_dir)
  
      num_images = len(image_ids)
  
      for i, image_id in enumerate(image_ids):
          destination = os.path.join(target_dir, "%s.jpg" % i)
          tmp_destination = "%s.temp" % destination
  
          source_url = (
              "http://api.brain-map.org/api/v2/"
              "section_image_download/%s" % image_id
          )
  
          if tf.gfile.Exists(destination):
              tf.logging.info(
                  "Image with ID already present, "
                  "skipping download (%s of %s)." % (i + 1, num_images)
              )
              continue
  
          tf.logging.info(
              "Downloading image with id %s (%s of %s)"
              % (image_id, i + 1, num_images)
          )
  
          response = requests.get(source_url, stream=True)
  
          response.raise_for_status()
  
          with tf.gfile.Open(tmp_destination, "w") as f:
              for block in response.iter_content(1024):
                  f.write(block)
  
          tf.gfile.Rename(tmp_destination, destination)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from io import BytesIO
  import math
  import os
  import numpy
  import requests
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import image_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import metrics
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 3 for calling a global function with example usage: maybe_download_image_dataset(image_ids, target_dir) without return types