python:
resnet101 = torchvision.models.resnet101(pretrained=self._pretrained)
children = list(resnet101.children())
features = children[:-3]
hidden = children[-3]
features = nn.Sequential(*features)
c++:
vision::models::ResNet101 model = vision::models::ResNet101();
torch::OrderedDict<std::string, std::shared_ptr<torch::nn::Module>> children = model->named_children();
std::shared_ptr<torch::nn::Module> hidden_layer;
nn::Sequential features;
for (auto& child : children)
{
std::cout << child.key() << std::endl;
if (child.key().find("layer4") != std::string::npos)
{
hidden_layer = child.value();
}
}
both error: ‘forward’ is not a member of ‘std::remove_reference<torch::nn::Module>::type {aka torch::nn::Module}’
/*features->push_back( std::make_shared<torch::nn::Module>(children[0].value()) );
features->push_back( children[0].value() );*/
How to get features as python in libtorch c++ ?