MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / make_features

Function make_features

lesson5-TrainingVGG/vgg.cpp:3–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "vgg.h"
2
3torch::nn::Sequential make_features(std::vector<int> &cfg, bool batch_norm){
4 torch::nn::Sequential features;
5 int in_channels = 3;
6 for(auto v : cfg){
7 if(v==-1){
8 features->push_back(torch::nn::MaxPool2d(maxpool_options(2,2)));
9 }
10 else{
11 auto conv2d = torch::nn::Conv2d(conv_options(in_channels,v,3,1,1));
12 features->push_back(conv2d);
13 if(batch_norm){
14 features->push_back(torch::nn::BatchNorm2d(torch::nn::BatchNorm2dOptions(v)));
15 }
16 features->push_back(torch::nn::ReLU(torch::nn::ReLUOptions(true)));
17 in_channels = v;
18 }
19 }
20 return features;
21}
22
23VGGImpl::VGGImpl(std::vector<int> &cfg, int num_classes, bool batch_norm){
24 features_ = make_features(cfg,batch_norm);

Callers 1

VGGImplMethod · 0.85

Calls 3

push_backMethod · 0.80
maxpool_optionsFunction · 0.70
conv_optionsFunction · 0.70

Tested by

no test coverage detected