Hi.
I'm trying to convert my python model to C++.
But while doing so, when i call one class from another class, how do i register the class module.
class A(nn.Module):
def init(self, num_features):
super(A, self).init()
self.bn = BatchNorm2d(num_features)
struct BNCC_Gate : torch::nn::Module {
BNCC_Gate()
{
bn(CustomBatchNorm(3, NULL, NULL));
this->register_module("bn", bn);
conv_gate = torch::nn::Sequential();
......
}
};
But this is giving me error as: undefined bn.
How should i create a object of the class A and regsiter it to get the complete network structure in class B?
@goldsborough
@soumith @asmeurer @asuhan @xuhdev
Any help would be great.
Thank you
Hi. I'm trying to convert my python model to C++. But while doing so, when i call one class from another class, how do i register the class module.
class A(nn.Module): def init(self, num_features): super(A, self).init() self.bn = BatchNorm2d(num_features)
class B(nn::Module): def init(self, num_features) super(BNCN_Gate, self).init() self.bn = CustomBatchNorm(in_channels, renorm, arg_ex) conv_gate = nn::sequential() ......`
How should write such using Pytorch C++ API. Right now i'm able to do this:
`struct A : torch::nn::Module { A(int64_t num_features) : bn(torch::nn::BatchNorm(num_features)) { } torch::Tensor forward(torch::Tensor x) { x = bn->forward(x); return x; } torch::nn::BatchNorm bn; };
struct BNCC_Gate : torch::nn::Module { BNCC_Gate() { bn(CustomBatchNorm(3, NULL, NULL)); this->register_module("bn", bn); conv_gate = torch::nn::Sequential(); ...... } };
But this is giving me error as: undefined bn. How should i create a object of the class A and regsiter it to get the complete network structure in class B?
@goldsborough @soumith @asmeurer @asuhan @xuhdev Any help would be great. Thank you