Builtin parameter extraction using c++ API

I am using a C++ program to analyze a CNN (YoloV5x). My goal is to extract built-in function parameters, like stride length and kernel size from the model file. I am currently using the torch::jit::script::Module data type and torch::jit::load function to load the torchscript model.

My problem is that I see no way of accessing attributes, even though software like “Netron” can obviously extract that. The only remotely related feature is model.named_parameters(), which only gives weights and biases of the model, which is not enough for my analysis. Is there any programmatic way to extract the needed features of the built-in functions using the C++ API?

Example:
When I load the model (model.pt) in python and print it, one of the function ouptuts is the following:

(1): Conv(
      (conv): Conv2d(80, 160, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))
      (act): Hardswish()
)

I would like to get the kernel_size, stride, and padding parameter in C++ API.

P.S.
In the Python program I load model.pt file and in the C++ file I load the model.torchscript.pt file.

1 Like