code: def ingest_pascal(
      data_dir,
      out_dir,
      img_reshape=(300, 300),
      overwrite=False,
      skip_untar=False,
  ):
      assert img_reshape is not None, "Target image reshape required."
      hw = "{}x{}".format(img_reshape[0], img_reshape[1])
  
      datasets = ["VOC2007", "VOC2012"]
      tar_files = {
          "VOC2007": [
              "VOCtrainval_06-Nov-2007.tar",
              "VOCtest_06-Nov-2007.tar",
          ],
          "VOC2012": ["VOCtrainval_11-May-2012.tar"],
      }
  
      index_name = {"trainval": "trainval.txt", "test": "test.txt"}
      manifest = {"trainval": [], "test": []}
  
      root_dir = os.path.join(out_dir, "VOCdevkit")
  
      train_manifest = os.path.join(root_dir, "train_{}.csv".format(hw))
      val_manifest = os.path.join(root_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 year in datasets:
          tags = {"trainval": [], "test": []}
  
          # define paths
          if skip_untar is False:
              tarfiles = [
                  os.path.join(data_dir, tar) for tar in tar_files[year]
              ]
              extract_tarfiles(tarfiles, out_dir)
  
          # read the index files and build a list of tags to process
          # in PASCALVOC, each tag (e.g. '000032') refers to an image (000032.jpg)
          # and an annotation XML file (000032.xml)
          for sets in index_name.keys():
              index_file = os.path.join(
                  root_dir, year, "ImageSets", "Main", index_name[sets]
              )
              if os.path.exists(index_file):
                  tag_list = get_tag_list(index_file)
                  tags[sets].extend(tag_list)
                  print(
                      "Found {} images in {}".format(
                          len(tag_list), index_file
                      )
                  )
  
          img_folder = os.path.join(root_dir, year, "JPEGImages")
          annot_folder = os.path.join(root_dir, year, "Annotations")
  
          # create data folders to save converted images and annotations
          target_img_folder = os.path.join(
              root_dir, year, "JPEGImages-converted"
          )
          target_annot_folder = os.path.join(
              root_dir, year, "Annotations-json"
          )
  
          print("Processing {}".format(year))
  
          util.make_dir(target_img_folder)
          util.make_dir(target_annot_folder)
  
          all_tags = (
              tags["trainval"] + tags["test"]
          )  # process all the tags in our index files.
  
          for tag in tqdm(all_tags):
              image = os.path.join(img_folder, tag + ".jpg")
              annot = os.path.join(annot_folder, tag + ".xml")
              assert os.path.exists(image)
              assert os.path.exists(annot)
  
              target_image = os.path.join(
                  target_img_folder, tag + ".jpg"
              )
              target_annot = os.path.join(
                  target_annot_folder, tag + ".json"
              )
  
              # convert the annotations to json, including difficult objects
              convert_xml_to_json(
                  annot, target_annot, difficult=True, img_reshape=None
              )
              util.resize_image(image, target_image, img_reshape=None)
  
              if tag in tags["trainval"]:
                  manifest["trainval"].append(
                      (target_image, target_annot)
                  )
              elif tag in tags["test"]:
                  manifest["test"].append((target_image, target_annot))
  
      np.random.seed(0)
      np.random.shuffle(manifest["trainval"])
  
      util.create_manifest(
          train_manifest, manifest["trainval"], root_dir
      )
      util.create_manifest(val_manifest, manifest["test"], root_dir)
  
      # write SSD CONFIG
      ssd_config = get_ssd_config(img_reshape)
      ssd_config_path = os.path.join(
          root_dir, "pascalvoc_ssd_{}.cfg".format(hw)
      )
      util.write_ssd_config(ssd_config, ssd_config_path, True)
  
      # write SSD VAL CONFIG
      ssd_config_val = get_ssd_config(img_reshape, True)
      ssd_config_path_val = os.path.join(
          root_dir, "pascalvoc_ssd_{}_val.cfg".format(hw)
      )
      util.write_ssd_config(ssd_config_val, ssd_config_path_val, True)
  
      config_path = os.path.join(
          root_dir, "pascalvoc_{}.cfg".format(hw)
      )
  
      config = {
          "manifest": "[train:{}, val:{}]".format(
              train_manifest, val_manifest
          ),
          "manifest_root": root_dir,
          "epochs": 230,
          "height": img_reshape[0],
          "width": img_reshape[1],
          "ssd_config": "[train:{}, val:{}]".format(
              ssd_config_path, ssd_config_path_val
          ),
      }
  
      util.write_config(config, config_path)
  
file_path: neon/examples/ssd/datasets/ingest_pascalvoc.py
imports: from argparse import ArgumentParser
  from convert_xml_to_json import convert_xml_to_json
  import numpy
  import os
  import tarfile
  import ingest_utils
  from collections import OrderedDict
  from tqdm import tqdm
  from neon.util.persist import get_data_cache_or_nothing
label_desc: Use image node_id 4 for calling a global function with example usage: ingest_pascal(data_dir, out_dir, img_reshape, overwrite, skip_untar) without return types