I am currently writing a C++ program which needs to do some analyses of the structure of a CNN model in torchScript format. I am using the C++ torch library the way it is shown on torch.org, loading in the model like so:
#include <torch/script.h>
#include <torch/torch.h>
#include <iostream>
#include <memory>
int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}
torch::jit::script::Module module;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
module = torch::jit::load(argv[1]);
}
catch (const c10::Error& e) {
std::cerr << "error loading the model\n";
return -1;
}
return 0;
}
As far as I was able to figure out module
consists of a collection of nested torch::jit::script::Module
's the lowest of which represent the built in functions. Im accessing those lowest modules as follows:
void print_modules(const torch::jit::script::Module& imodule) {
for (const auto& module : imodule.named_children()) {
if(module.value.children().size() > 0){
print_modules(module.value);
}
else{
std::cout << module.name << "\n";
}
}
}
This function recursively goes trough the modules and prints the name of the lowest level ones, which correspond to the builtin functions of torch script.
My question now is, how do I access the details for those builtin functions like for example the stride length for convolutions?
I can't figure out for the life of me to get access to those basic attributes of modules.