MCPcopy Create free account
hub / github.com/AllentDan/LibtorchSegmentation / ResNetImpl

Method ResNetImpl

src/backbones/ResNet.cpp:62–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

conv_optionsFunction · 0.85

Tested by

no test coverage detected