Libtorch named_parameters() not work?

As the libtorch guide says, named_parameters() is used to print model parameters, and the return value should be OrderedDict<std::string, Tensor> named_parameters(bool recurse = true) const,but it went into error:

no member named 'key' in 'torch::jit::script::Named<at::Tensor>'

My input is

for (const auto& pair : net.named_parameters()) {
  std::cout << pair.key() << ": " << pair.value() << std::endl;
1 Like

Hi, module of script is not dict.

1 Like