Hi, All, I have an inquiry about conversion from pytorch to libtorch (C++)
The python code is:
self.layers = torch.nn.ModuleList([
LinearWeightNorm(input_dim, 1000),
LinearWeightNorm(1000, 500),
LinearWeightNorm(500, 250),
LinearWeightNorm(250, 250),
LinearWeightNorm(250, 250)]
)
for i in range(len(self.layers)):
m = self.layers[i]
x_f = F.relu(m(x))
In libtorch code, how shall I convert the line of “m=self.layers(s)”
I use:
layers = register_module(“layer”, torch::nn::ModuleList(
LinearWeightNorm(input_dim, 1000),
LinearWeightNorm(1000, 500),
LinearWeightNorm(500, 250),
LinearWeightNorm(250, 250),
LinearWeightNorm(250, 250)
));
for
for(int64_t i=0; i<sizeof(layers);i++){
torch::nn::Module m;
m=layers[i];
torch::Tensor x_f = torch::nn::functional::relu(m(x));
I get an error in m=layers[i] saying that “No viable overloaded ‘=’”
Could anyone suggest how shall I modify the line to make it work please ?
Any comments are welcome. Much appreciated.
Thanks