code: def etree_to_dict(t):
      d = {t.tag: {} if t.attrib else None}
      children = list(t)
      if children:
          dd = defaultdict(list)
          for dc in map(etree_to_dict, children):
              for k, v in dc.items():
                  dd[k].append(v)
          d = {
              t.tag: {
                  k: v[0] if len(v) == 1 else v for k, v in dd.items()
              }
          }
      if t.attrib:
          d[t.tag].update(("@" + k, v) for k, v in t.attrib.items())
      if t.text:
          text = t.text.strip()
          if children or t.attrib:
              if text:
                  d[t.tag]["#text"] = text
          else:
              d[t.tag] = text
      return d
  
file_path: neon/examples/ssd/datasets/convert_xml_to_json.py
imports: import json
  import glob
  import collections
  import os
  from os.path import join
  import xml.etree.ElementTree
  from collections import defaultdict
  import argparse
label_desc: Use image node_id 1 for calling a global function with example usage: etree_to_dict(t) and returns: d