code: def onnx_to_hls(config):
      """Convert onnx model to hls model from configuration.
  
      Args:
          config (dict): ONNX configuration from yaml file or passed through API.
  
      Raises:
          Exception: Raised if an unsupported operation is found in the ONNX model.
  
      Returns:
          ModelGraph: hls4ml model object
      """
      # This is a list of dictionaries to hold all the layer info we need to generate HLS
      layer_list = []
  
      # Extract model architecture
      print("Interpreting Model ...")
  
      model = (
          onnx.load(config["OnnxModel"])
          if isinstance(config["OnnxModel"], str)
          else config["OnnxModel"]
      )
  
      model = shape_inference.infer_shapes(model)
      graph = model.graph
  
      reader = ONNXDataReader(model)
  
      # Obtain list of input/ouput layers
      all_inputs = [x.name for x in model.graph.input]
      all_initializers = [x.name for x in model.graph.initializer]
      input_layers = [
          x for x in all_inputs if x not in all_initializers
      ]
      output_layers = get_out_layer_name(graph)
  
      print("Output layers: ", output_layers)
  
      for i, inp in enumerate(input_layers):
          input_layer = {}
          input_layer["name"] = replace_char_inconsitency(inp)
          input_layer["class_name"] = "InputLayer"
          inp_shape = next(
              (
                  x.type.tensor_type.shape.dim
                  for x in model.graph.input
                  if x.name == inp
              ),
              None,
          )
          input_layer["input_shape"] = [x.dim_value for x in inp_shape]
  
          if len(input_layer["input_shape"]) > 1:
              input_layer["input_shape"][0] = None  # Firt dim is batch
  
          # Clean the layer name for specific models
          sanitize_layer_name(input_layer)
          input_layers[i] = input_layer["name"]
  
          layer_list.append(input_layer)
  
      # Defined supported layers and check for unsupported layer type
      skip_layers = ["Dropout", "Identity", "Flatten"]
  
      # Map inputs of skipped layers
      inputs_map = {}
  
      supported_layers = get_supported_onnx_layers() + skip_layers
  
      # Get input shape
      current_shape = [input_layer["input_shape"]]
      print("Input shape:", current_shape[0])
  
      # Loop through layers
      layer_counter = 0
  
      # Output shape tracking
      output_shape = None
  
      print("Topology:")
      for node in graph.node:
          if node.op_type not in supported_layers:
              raise Exception(
                  f"ERROR: Unsupported operation type: {node.op_type}"
              )
  
          # If not the first layer then input shape is taken from last layer's output
          if layer_counter != 0:
              current_shape = [output_shape]
  
          if node.op_type in skip_layers:
              if node.op_type == "Flatten":
                  output_shape = [
                      current_shape[0][0],
                      np.prod(current_shape[0][1:]),
                  ]
  
              else:
                  # Currently supported skipped layers have only one input and output
                  # Skipped layers can follow each other (e.g., Dropout -> Flatten)
  
                  # Mapping inputs
                  input_name = inputs_map.get(
                      node.input[0], node.input[0]
                  )
                  output_name = node.output[0]
                  inputs_map[output_name] = input_name
  
                  output_shape = current_shape[0]
              continue
  
          if node.op_type in supported_layers:
              layer_counter = layer_counter + 1
  
          # Process the layer
          layer, output_shape = layer_handlers[node.op_type](
              reader, node, inputs_map, current_shape, graph, config
          )
  
          sanitize_layer_name(layer)
          print(
              "Layer name: {}, layer type: {}, current shape: {}".format(
                  layer["name"], layer["class_name"], current_shape
              )
          )
          layer_list.append(layer)
  
      #################
      # Generate HLS
      #################
  
      print("Creating HLS model")
      hls_model = ModelGraph(
          config, reader, layer_list, input_layers, output_layers
      )
      return hls_model
  
imports: import numpy
  import onnx
  from onnx import helper, numpy_helper, shape_inference
  from hls4ml.model import ModelGraph
label_desc: Use image node_id 12 for calling a global function with example usage: onnx_to_hls(config) and returns: hls_model