class_docstr: ONNX data reader to be used for extracting relevant information during conversion.
class_docstr_tok: ["ONNX","data","reader","to","be","used","for","extracting","relevant","information","during","conversion","."]
docstr: Extract weights data from ONNX model.
  
  Args:
      layer_name (str): Layer's name in the ONNX model.
      var_name (str): Variable to be extracted.
  
  Returns:
      ndarray: Extracted weights data.
docstr_tok: ["Extract","weights","data","from","ONNX","model",".","Args",":","layer_name","(","str",")",":","Layer","'s","name","in","the","ONNX","model",".","var_name","(","str",")",":","Variable","to","be","extracted",".","Returns",":","ndarray",":","Extracted","weights","data","."]
code: def get_weights_data(self, layer_name, var_name):
      """Extract weights data from ONNX model.
  
      Args:
          layer_name (str): Layer's name in the ONNX model.
          var_name (str): Variable to be extracted.
  
      Returns:
          ndarray: Extracted weights data.
      """
      # Get the node associated with the layer name
      node = next(
          node
          for node in self.model.graph.node
          if node.name == layer_name
      )
  
      inputs = self.input_map[layer_name]
      inp_idx = self.index_map[var_name]
  
      if inp_idx >= len(inputs["inputs"]):
          # Check if the layer is an AddBias layer
          if (node.op_type == "Add") and (var_name == "bias"):
              inp_idx = 1
          else:
              # Input not found, likely a bias tensor is not available
              return None
  
      tensor = next(
          (
              x
              for x in self.model.graph.initializer
              if x.name == inputs["inputs"][inp_idx]
          ),
          None,
      )
  
      if tensor is not None:
          data = numpy_helper.to_array(tensor)
  
          if inputs["transpose"]:
              if inputs["perm"] is not None and len(data.shape) == len(
                  inputs["perm"]
              ):
                  data = data.transpose(inputs["perm"])
              else:
                  data = data.transpose()
  
          # Check for transB in Gemm
          if node.op_type == "Gemm":
              if not get_onnx_attribute(node, "transB"):
                  data = data.transpose()
  
      return data
  
imports: import numpy
  import onnx
  from onnx import helper, numpy_helper, shape_inference
  from hls4ml.model import ModelGraph
label_desc: Use image node_id 2 for calling the ONNXDataReader obj's underlying member method code with example usage: obj.get_weights_data(layer_name, var_name) and returns: data, None