How to get weights and biases

Hello,

I have pretrained model in c++ that I trained in python. I now need to extract the weights to do my own arithmetic with it. I see that several methods exist for python. I tried using one called named_parameters() but it did not work. Does anyone have any other methods that i can try to use. Idealy I would want it to be return as a tensor.

What kind of issue did you see?

Module::parameters() is defined here and will return a std::vector<Tensor> while Module::named_parameters() is defined here and will return a std::map<std::string, at::Tensor>.

Sorry I just saw this and been deleting code all day so I do not remember. My goal right now is to just get the weights and store them so I could use my own multiplication method. majority of the issue say ‘no member’ or that the function is not a member.

torch::jit::script::Module module;
std::vector<torch::Tensor> params = module.parameters();
for (auto& p : params) {
    std::cout << p.sizes() << std::endl;
}

This gave me this error

" error: conversion from ‘torch::jit::parameter_list’ {aka ‘torch::jit::slot_list_impltorch::jit::detail::ParameterPolicy’} to non-scalar type ‘std::vectorat::Tensor’ requested"

Got it! :slight_smile: I should be able to continue now Thank you !!!