I want to know module type in c++ environment

In a c++ (libtorch) environment, I obtain submodule of Torchvison’s models using children() and print type() and then it is printed in binary form. I want to know the type like “nn.Conv2d” of submodule.
What should I do?

Not sure there’s any way to get just the name “Conv2d”, but the pretty_print() function outputs the name (alongside other module properties).

As a workaround, you could use that with, for example, a std::stringstream and do some post-processing on the string to pull out the part you want.

If that doesn’t work for you, I suggest opening a feature request issue on the PyTorch GitHub page.

Use the name() method on Module perhaps? It relies on RTTI to resolve the type name. This is the same function that pretty_print() uses to get the module name.

https://pytorch.org/cppdocs/api/classtorch_1_1nn_1_1_module.html#_CPPv4NK5torch2nn6Module4nameEv