(model: onnx.ModelProto, const_nodes: List[onnx.NodeProto],
                          res: Tensors)
return model
:param model: the original onnx model
    :param const_nodes: const nodes detected by `get_constant_nodes`
    :param res: The dict containing all tensors, got by `forward_all`
    :return: the simplified onnx model. Redundant ops are all removed.
:param model: the original onnx model
    :param const_nodes: const nodes detected by `get_constant_nodes`
    :param res: The dict containing all tensors, got by `forward_all`
    :return: the simplified onnx model. Redundant ops are all removed.
: param model : the original onnx model : param const_nodes : const nodes detected by get_constant_nodes : param res : The dict containing all tensors got by forward_all : return : the simplified onnx model . Redundant ops are all removed .
def eliminate_const_nodes(model: onnx.ModelProto, const_nodes: List[onnx.NodeProto],
                          res: Tensors) -> onnx.ModelProto:
    """
    :param model: the original onnx model
    :param const_nodes: const nodes detected by `get_constant_nodes`
    :param res: The dict containing all tensors, got by `forward_all`
    :return: the simplified onnx model. Redundant ops are all removed.
    """
    for i, node in enumerate(model.graph.node):
        if node in const_nodes:
            for output in node.output:
                new_node = copy.deepcopy(node)
                new_node.name = "node_" + output
                new_node.op_type = 'Constant'
                new_attr = onnx.helper.make_attribute(
                    'value',
                    onnx.numpy_helper.from_array(res[output], name=output)
                )
                del new_node.input[:]
                del new_node.attribute[:]
                del new_node.output[:]
                new_node.output.extend([output])
                new_node.attribute.extend([new_attr])
                insert_elem(model.graph.node, i + 1, new_node)
            del model.graph.node[i]

    return model
def eliminate_const_nodes ( model : onnx . ModelProto , const_nodes : List [ onnx . NodeProto ] , res : Tensors ) -> onnx . ModelProto : for i , node in enumerate ( model . graph . node ) : if node in const_nodes : for output in node . output : new_node = copy . deepcopy ( node ) new_node . name = "node_" + output new_node . op_type = 'Constant' new_attr = onnx . helper . make_attribute ( 'value' , onnx . numpy_helper . from_array ( res [ output ] , name = output ) ) del new_node . input [ : ] del new_node . attribute [ : ] del new_node . output [ : ] new_node . output . extend ( [ output ] ) new_node . attribute . extend ( [ new_attr ] ) insert_elem ( model . graph . node , i + 1 , new_node ) del model . graph . node [ i ] return model