| 21 | } |
| 22 | |
| 23 | VGGImpl::VGGImpl(std::vector<int> _cfg, int num_classes, bool batch_norm_) { |
| 24 | cfg = _cfg; |
| 25 | batch_norm = batch_norm_; |
| 26 | features_ = make_features(cfg, batch_norm); |
| 27 | avgpool = torch::nn::AdaptiveAvgPool2d(torch::nn::AdaptiveAvgPool2dOptions(7)); |
| 28 | classifier->push_back(torch::nn::Linear(torch::nn::LinearOptions(512 * 7 * 7, 4096))); |
| 29 | classifier->push_back(torch::nn::ReLU(torch::nn::ReLUOptions(true))); |
| 30 | classifier->push_back(torch::nn::Dropout()); |
| 31 | classifier->push_back(torch::nn::Linear(torch::nn::LinearOptions(4096, 4096))); |
| 32 | classifier->push_back(torch::nn::ReLU(torch::nn::ReLUOptions(true))); |
| 33 | classifier->push_back(torch::nn::Dropout()); |
| 34 | classifier->push_back(torch::nn::Linear(torch::nn::LinearOptions(4096, num_classes))); |
| 35 | |
| 36 | features_ = register_module("features", features_); |
| 37 | classifier = register_module("classifier", classifier); |
| 38 | } |
| 39 | |
| 40 | torch::Tensor VGGImpl::forward(torch::Tensor x) { |
| 41 | x = features_->forward(x); |
nothing calls this directly
no test coverage detected