code: def ingest_spacenet(
      data_dir,
      cities,
      width,
      height,
      overwrite=False,
      train_fraction=0.9,
      percent_blank=0.5,
      annot_save=None,
  ):
      warnings.showwarning = _warning  # monkeypatch to not emit code
      hw = "{}x{}".format(height, width)
      ext = ".png"
      data = {}
  
      train_manifest = os.path.join(data_dir, "train_{}.csv".format(hw))
      val_manifest = os.path.join(data_dir, "val_{}.csv".format(hw))
  
      if (
          os.path.exists(train_manifest)
          and os.path.exists(val_manifest)
          and not overwrite
      ):
          print("Manifest files already found, skipping ingest.")
          print("Use --overwrite flag to force re-ingest.")
          return
  
      for city in cities:
          if city == "AOI_1_Rio":  # Rio has different dataset structure
              img_folder = os.path.join(
                  data_dir, city, "processedData", "3band"
              )
              annot_folder = os.path.join(
                  data_dir,
                  city,
                  "processedData",
                  "vectorData",
                  "geoJson",
              )
  
              target_img_folder = os.path.join(
                  data_dir, city, "processedData", "3band-{}".format(hw)
              )
              target_annot_folder = os.path.join(
                  data_dir, city, "processedData", "json-{}".format(hw)
              )
              test_img_folder = os.path.join(
                  data_dir,
                  city,
                  "processedData",
                  "3band-{}-gt".format(hw),
              )
  
              # helper function for converting image files to their corresponding annotation file
              # e.g. 3band_013022223133_Public_img3593.tif -> 013022223133_Public_img3593_Geo.geojson
              def img_to_annot(x):
                  x.replace("3band_", "").replace(
                      ".tif", "_Geo.geojson"
                  )
  
          else:
              prefix = "RGB-PanSharpen"
              img_folder = os.path.join(data_dir, city, prefix)
              annot_folder = os.path.join(
                  data_dir, city, "geojson", "buildings"
              )
  
              # create data folders to save converted images and annotations
              target_img_folder = os.path.join(
                  data_dir, city, "{}-{}".format(prefix, hw)
              )
              target_annot_folder = os.path.join(
                  data_dir, city, "json-{}".format(hw)
              )
              test_img_folder = os.path.join(
                  data_dir, city, "{}-{}-gt".format(prefix, hw)
              )
  
              # helper function for converting image files to their corresponding annotation file
              # e.g. RGB-PanSharpen_AOI_2_Vegas_img9.tif -> buildings_AOI_2_Vegas_img9.geojson
              def img_to_annot(x):
                  x.replace(prefix, "buildings").replace(
                      ".tif", ".geojson"
                  )
  
          print("Processing {}".format(city))
  
          make_dir(target_img_folder)
          make_dir(target_annot_folder)
          make_dir(test_img_folder)
  
          images = glob.glob(os.path.join(img_folder, "*.tif"))
          assert len(images) > 0, "No Images found in {}".format(
              img_folder
          )
  
          data[city] = {
              "manifest": [],
              "annotation": [],
              "img_folder": img_folder,
              "annot_folder": annot_folder,
          }
  
          for image in tqdm(images):
              img_file = os.path.basename(image)
              annot_file = img_to_annot(img_file)
              annot = os.path.join(annot_folder, annot_file)
              assert os.path.exists(annot)
  
              # target image has extension=ext, and target_annot has extension JSON
              target_image = os.path.join(
                  target_img_folder, os.path.splitext(img_file)[0] + ext
              )
              target_annot = os.path.join(
                  target_annot_folder,
                  os.path.splitext(annot_file)[0] + ".json",
              )
  
              if (
                  not os.path.exists(target_image)
                  or not os.path.exists(target_annot)
                  or overwrite
              ):
                  annotation = convert_image_annot(
                      image_path=image,
                      annot_path=annot,
                      target_image=target_image,
                      target_annot=target_annot,
                      width=512,
                      height=512,
                      box_shrink=0.8,
                      debug_dir=test_img_folder,
                  )
              else:
                  warnings.warn(
                      "File for {} already exists, skipping processing.Use --overwrite to force.".format(
                          city
                      ),
                      Warning,
                  )
                  annotation = json.load(open(target_annot))
  
              # filter on percent_blank, as well as presence of any objects
              if is_eligible_example(annotation, percent_blank):
                  data[city]["annotation"].append(annotation)
                  data[city]["manifest"].append(
                      (target_image, target_annot)
                  )
  
      # write manifest files
  
      # build manifest list from each city's manifest
      manifest = []
      for city in cities:
          manifest.extend(data[city]["manifest"])
  
      ntrain = int(np.round(len(manifest) * train_fraction))
  
      np.random.seed(0)
      np.random.shuffle(manifest)
  
      util.create_manifest(train_manifest, manifest[:ntrain], data_dir)
      util.create_manifest(val_manifest, manifest[ntrain:], data_dir)
  
      # write SSD CONFIG
      ssd_config = get_ssd_config((height, width))
      ssd_config_path = os.path.join(
          data_dir, "spacenet_ssd_{}.cfg".format(hw)
      )
      util.write_ssd_config(ssd_config, ssd_config_path, True)
  
      # write SSD VAL CONFIG
      ssd_config_val = get_ssd_config((height, width), True)
      ssd_config_path_val = os.path.join(
          data_dir, "spacenet_ssd_{}_val.cfg".format(hw)
      )
      util.write_ssd_config(ssd_config_val, ssd_config_path_val, True)
  
      config_path = os.path.join(data_dir, "spacenet_{}.cfg".format(hw))
  
      config = {
          "manifest": "[train:{}, val:{}]".format(
              train_manifest, val_manifest
          ),
          "manifest_root": data_dir,
          "epochs": 230,
          "height": height,
          "width": width,
          "ssd_config": "[train:{}, val:{}]".format(
              ssd_config_path, ssd_config_path_val
          ),
      }
  
      util.write_config(config, config_path)
  
      # write annotation pickle
      if annot_save is not None:
          pickle.dump(data, open(annot_save, "w"))
  
imports: import pickle
  import glob
  import os
  import json
  import spacenet_utils
  from PIL import Image, ImageDraw
  from collections import OrderedDict
  import ingest_utils
  import numpy
  from tqdm import tqdm
  import warnings
  from configargparse import ArgumentParser
  from neon.util.persist import get_data_cache_or_nothing
label_desc: Use image node_id 10 for calling a global function with example usage: ingest_spacenet(data_dir, cities, width, height, overwrite, train_fraction, percent_blank, annot_save) without return types