Pytorch 如何从jit::script::module访问模块属性,如卷积步长 我目前正在编写一个C++程序,需要对美国有线电视新闻网模型的结构进行分析。我使用的是C++ Trac类库,它在Trk.Org上显示的方式,加载到模型中,如: #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; }

Pytorch 如何从jit::script::module访问模块属性,如卷积步长 我目前正在编写一个C++程序,需要对美国有线电视新闻网模型的结构进行分析。我使用的是C++ Trac类库,它在Trk.Org上显示的方式,加载到模型中,如: #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; },pytorch,jit,libtorch,torchscript,Pytorch,Jit,Libtorch,Torchscript,该函数递归地遍历各个模块,并打印与torch脚本的内置函数相对应的最低级别模块的名称 我现在的问题是,如何访问那些内置函数的详细信息,例如卷积的步长? 我无法用我的一生来访问这些模块的基本属性。我也会打印中间级别的模块名称。另外,添加一个整数值输入缩进(默认值0),您可以在模块深入时缩进模块。类似于(我在本地测试了它,它似乎有效)。 void print_modules(const torch::jit::script::Module& imodule) { for (cons

该函数递归地遍历各个模块,并打印与torch脚本的内置函数相对应的最低级别模块的名称

我现在的问题是,如何访问那些内置函数的详细信息,例如卷积的步长?


我无法用我的一生来访问这些模块的基本属性。

我也会打印中间级别的模块名称。另外,添加一个整数值输入
缩进
(默认值0),您可以在模块深入时缩进模块。类似于(我在本地测试了它,它似乎有效)。
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";

        }
    }
}