code: def get_model_component_info(model_filename):
      """
      This function reads existing model (*.raw or *.mdl) and returns array
      of XconfigExistingLayer one per {input,output}-node or component-node
      with same 'name' used in the raw model and 'dim' equal to 'output-dim'
      for component-node and 'dim' for {input,output}-node.
  
      e.g. layer in *.mdl -> corresponding 'XconfigExistingLayer' layer
           'input-node name=ivector dim=100' ->
           'existing name=ivector dim=100'
           'component-node name=tdnn1.affine ... input-dim=1000 '
           'output-dim=500' ->
           'existing name=tdnn1.affine dim=500'
      """
  
      all_layers = []
      try:
          f = open(model_filename, "r")
      except Exception as e:
          sys.exit(
              "{0}: error reading model file '{1}'".format(
                  sys.argv[0], model_filename, repr(e)
              )
          )
  
      # use nnet3-info to get component names in the model.
      out = common_lib.get_command_stdout(
          """nnet3-info {0} | grep '\-node' """
          """ """.format(model_filename)
      )
  
      # out contains all {output, input, component}-nodes used in model_filename
      # It can parse lines in out like:
      # i.e. input-node name=input dim=40
      #   component-node name=tdnn1.affine component=tdnn1.affine input=lda
      #   input-dim=300 output-dim=512
      layer_names = []
      key_to_value = dict()
      for line in out.split("\n"):
          parts = line.split(" ")
          dim = -1
          for field in parts:
              key_value = field.split("=")
              if len(key_value) == 2:
                  key = key_value[0]
                  value = key_value[1]
                  if key == "name":  # name=**
                      layer_name = value
                  elif key == "dim":  # for input-node
                      dim = int(value)
                  elif key == "output-dim":  # for component-node
                      dim = int(value)
  
          if layer_name is not None and layer_name not in layer_names:
              layer_names.append(layer_name)
              key_to_value["name"] = layer_name
              assert dim != -1
              key_to_value["dim"] = dim
              all_layers.append(
                  xlayers.XconfigExistingLayer(
                      "existing", key_to_value, all_layers
                  )
              )
      if len(all_layers) == 0:
          raise RuntimeError(
              "{0}: model filename '{1}' is empty.".format(
                  sys.argv[0], model_filename
              )
          )
      f.close()
      return all_layers
  
file_path: espnet/egs2/dns_icassp22/enh1/steps/libs/nnet3/xconfig/parser.py
imports: from __future__ import print_function
  import logging
  import sys
  import libs.nnet3.xconfig.layers
  import libs.nnet3.xconfig.utils
  import libs.common
label_desc: Use image node_id 2 for calling a global function with example usage: get_model_component_info(model_filename) and returns: all_layers