| 60 | } |
| 61 | |
| 62 | ResNetImpl::ResNetImpl(std::vector<int> layers, int num_classes, std::string model_type, int _groups, int _width_per_group) |
| 63 | { |
| 64 | if (model_type != "resnet18" && model_type != "resnet34") |
| 65 | { |
| 66 | expansion = 4; |
| 67 | is_basic = false; |
| 68 | } |
| 69 | groups = _groups; |
| 70 | base_width = _width_per_group; |
| 71 | conv1 = torch::nn::Conv2d(conv_options(3, 64, 7, 2, 3, 1, false)); |
| 72 | bn1 = torch::nn::BatchNorm2d(torch::nn::BatchNorm2dOptions(64)); |
| 73 | layer1 = torch::nn::Sequential(_make_layer(64, layers[0])); |
| 74 | layer2 = torch::nn::Sequential(_make_layer(128, layers[1], 2)); |
| 75 | layer3 = torch::nn::Sequential(_make_layer(256, layers[2], 2)); |
| 76 | layer4 = torch::nn::Sequential(_make_layer(512, layers[3], 2)); |
| 77 | |
| 78 | fc = torch::nn::Linear(512 * expansion, num_classes); |
| 79 | register_module("conv1", conv1); |
| 80 | register_module("bn1", bn1); |
| 81 | register_module("layer1", layer1); |
| 82 | register_module("layer2", layer2); |
| 83 | register_module("layer3", layer3); |
| 84 | register_module("layer4", layer4); |
| 85 | register_module("fc", fc); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | torch::Tensor ResNetImpl::forward(torch::Tensor x) { |
nothing calls this directly
no test coverage detected