| 34 | } |
| 35 | |
| 36 | torch::Tensor BlockImpl::forward(torch::Tensor x) { |
| 37 | torch::Tensor residual = x.clone(); |
| 38 | |
| 39 | x = conv1->forward(x); |
| 40 | x = bn1->forward(x); |
| 41 | x = torch::relu(x); |
| 42 | |
| 43 | x = conv2->forward(x); |
| 44 | x = bn2->forward(x); |
| 45 | |
| 46 | if (!is_basic) { |
| 47 | x = torch::relu(x); |
| 48 | x = conv3->forward(x); |
| 49 | x = bn3->forward(x); |
| 50 | } |
| 51 | |
| 52 | if (!downsample->is_empty()) { |
| 53 | residual = downsample->forward(residual); |
| 54 | } |
| 55 | |
| 56 | x += residual; |
| 57 | x = torch::relu(x); |
| 58 | |
| 59 | return x; |
| 60 | } |
| 61 | |
| 62 | ResNetImpl::ResNetImpl(std::vector<int> layers, int num_classes, std::string model_type, int _groups, int _width_per_group) |
| 63 | { |