2

入力レイヤー、出力レイヤー、およびその形状などのデータを onnx モデルから抽出しようとしています。これを行うためのpythonインターフェースがあることは知っています。このコードに似たようなことをしたいのですが、C ++で。リンクからコードも貼り付けました。私はPythonで試してみましたが、うまくいきました。同じことを行う C++ API があるかどうかを知りたいです。

import onnx

model = onnx.load(r"model.onnx")

# The model is represented as a protobuf structure and it can be accessed
# using the standard python-for-protobuf methods

# iterate through inputs of the graph
for input in model.graph.input:
    print (input.name, end=": ")
    # get type of input tensor
    tensor_type = input.type.tensor_type
    # check if it has a shape:
    if (tensor_type.HasField("shape")):
        # iterate through dimensions of the shape:
        for d in tensor_type.shape.dim:
            # the dimension may have a definite (integer) value or a symbolic identifier or neither:
            if (d.HasField("dim_value")):
                print (d.dim_value, end=", ")  # known dimension
            elif (d.HasField("dim_param")):
                print (d.dim_param, end=", ")  # unknown dimension with symbolic name
            else:
                print ("?", end=", ")  # unknown dimension with no name
    else:
        print ("unknown rank", end="")
    print()

また、私はC ++が初めてなので、同じことを手伝ってください。

4

1 に答える 1