protobuf解析onnx模型结构

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图
onnx::ModelProto  model_data;
    std::string filedir="C:/Users/DH/Desktop/1/detect.onnx";
    int fd=google::protobuf::io::win32::open(filedir.c_str(),O_RDONLY);

    FileInputStream* raw_input = new FileInputStream(fd);
    CodedInputStream* coded_input = new CodedInputStream(raw_input);
    coded_input->SetTotalBytesLimit(INT_MAX);
    google::protobuf::MessageLite * proto;
            proto=& model_data;

    bool success = proto->ParseFromCodedStream(coded_input);

    bool success1 = proto->ParseFromZeroCopyStream(raw_input);
//    delete coded_input;
//    delete raw_input;
    //close(fd);


    onnx::GraphProto graph = model_data.graph();  //访问graph结构

    int num = graph.node_size();                    //node节点个数
    int input_size = graph.input_size();            //网络输入个数,input以及各层常量输入
    for (int i = 0; i < input_size; ++i)
    {
        const std::string name = graph.input(i).name();
        onnx::TypeProto type = graph.input(i).type();
        onnx::TensorShapeProto shape = type.tensor_type().shape();//输入维度
        for (int i = 0; i < shape.dim_size(); i++)
        {
            std::cout << shape.dim(i).dim_value();
            std::cout<< std::endl;
        }
    }

    int output_size = graph.output_size();    //网络output个数
    for (int i = 0; i < num; i++)    //遍历每个node结构
    {
        const onnx::NodeProto node = graph.node(i);
        std::string node_name = node.name();
        std::cout <<"cur node name:"<< node_name << std::endl;
        const ::google::protobuf::RepeatedPtrField< ::onnx::AttributeProto> attr = node.attribute();        //每个node结构的参数信息
        const std::string type = node.op_type();
        int in_size = node.input_size();
        int out_size = node.output_size();
    }

运行结果及报错内容

读取模型graph空的,读出来的inputsize为0,是哪里出错了,使用proto3

我的解答思路和尝试过的方法
我想要达到的结果