Hi all,
Suppose I have a module like:
In [1]: import torch
In [2]: class M(torch.nn.Module):
...: thing: str
...: def __init__(self):
...: super().__init__()
...: self.thing = 'hi'
...: self.other = lambda x: x* 2
...:
In [3]: m = M()
In [4]: ms = torch.jit.script(m)
In [5]: ms.save("test.pth")
If I load test.pth
in C++ using libtorch
, once I have a torch::jit::script::Module
(as in the tutorial), how can I access the thing
string by name as some kind of typical C++ string object or pointer?
Would the process be the same for an attribute annotated thing2: float
in Python?
Thanks!