Search code examples
c++onnxonnxruntime

Print ONNXRUNTIME::Graph without having Model


I'm working on new optimizer that inherits from GraphTransformer in c++

How can I view the changes that I made, just after ApplyImpl ends I tried graph.ToGraphProto() but I cannot save it And I need to make a new Model to be able to save it and view it in Netron or something


Solution

  • Found it Need to make new model and versions need to get SchemaRegistry:

    ModelProto model_proto1;
    model_proto1.set_ir_version(IR_VERSION);
    OperatorSetIdProto* op_set_id = model_proto1.add_opset_import();
    op_set_id->set_domain("");
    op_set_id->set_version(12);
    model_proto1.set_allocated_graph(new GraphProto(graph.ToGraphProto()));
    IOnnxRuntimeOpSchemaRegistryList local_registries{graph.GetSchemaRegistry()};
    
    
    Model model(model_proto1, &local_registries, logger);
    onnxruntime::Model::Save(model, "/tmp/new_g.onnx");