| 1 | #include "ResNet.h" |
| 2 | |
| 3 | BlockImpl::BlockImpl(int64_t inplanes, int64_t planes, int64_t stride_, |
| 4 | torch::nn::Sequential downsample_, int groups, int base_width, bool _is_basic) |
| 5 | { |
| 6 | downsample = downsample_; |
| 7 | stride = stride_; |
| 8 | int width = int(planes * (base_width / 64.)) * groups; |
| 9 | |
| 10 | conv1 = torch::nn::Conv2d(conv_options(inplanes, width, 3, stride_, 1, groups, false)); |
| 11 | bn1 = torch::nn::BatchNorm2d(torch::nn::BatchNorm2dOptions(width)); |
| 12 | conv2 = torch::nn::Conv2d(conv_options(width, width, 3, 1, 1, groups, false)); |
| 13 | bn2 = torch::nn::BatchNorm2d(torch::nn::BatchNorm2dOptions(width)); |
| 14 | is_basic = _is_basic; |
| 15 | if (!is_basic) { |
| 16 | conv1 = torch::nn::Conv2d(conv_options(inplanes, width, 1, 1, 0, 1, false)); |
| 17 | conv2 = torch::nn::Conv2d(conv_options(width, width, 3, stride_, 1, groups, false)); |
| 18 | conv3 = torch::nn::Conv2d(conv_options(width, planes * 4, 1, 1, 0, 1, false)); |
| 19 | bn3 = torch::nn::BatchNorm2d(torch::nn::BatchNorm2dOptions(planes * 4)); |
| 20 | } |
| 21 | |
| 22 | register_module("conv1", conv1); |
| 23 | register_module("bn1", bn1); |
| 24 | register_module("conv2", conv2); |
| 25 | register_module("bn2", bn2); |
| 26 | if (!is_basic) { |
| 27 | register_module("conv3", conv3); |
| 28 | register_module("bn3", bn3); |
| 29 | } |
| 30 | |
| 31 | if (!downsample->is_empty()) { |
| 32 | register_module("downsample", downsample); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | torch::Tensor BlockImpl::forward(torch::Tensor x) { |
| 37 | torch::Tensor residual = x.clone(); |
nothing calls this directly
no test coverage detected