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

Method DeepLabV3Impl

src/architectures/DeepLab.cpp:3–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "DeepLab.h"
2
3DeepLabV3Impl::DeepLabV3Impl(int _num_classes, std::string encoder_name, std::string pretrained_path, int encoder_depth,
4 int decoder_channels, int in_channels, double upsampling) {
5 num_classes = _num_classes;
6 auto encoder_param = encoder_params();
7 std::vector<int> encoder_channels = encoder_param[encoder_name]["out_channels"];
8 if (!encoder_param.contains(encoder_name))
9 std::cout<< "encoder name must in {resnet18, resnet34, resnet50, resnet101, resnet150, \
10 resnext50_32x4d, resnext101_32x8d, vgg11, vgg11_bn, vgg13, vgg13_bn, \
11 vgg16, vgg16_bn, vgg19, vgg19_bn,}";
12 if (encoder_param[encoder_name]["class_type"] == "resnet")
13 encoder = new ResNetImpl(encoder_param[encoder_name]["layers"], 1000, encoder_name);
14 else if (encoder_param[encoder_name]["class_type"] == "vgg")
15 encoder = new VGGImpl(encoder_param[encoder_name]["cfg"], 1000, encoder_param[encoder_name]["batch_norm"]);
16 else std::cout<< "unknown error in backbone initialization";
17
18 encoder->load_pretrained(pretrained_path);
19 encoder->make_dilated({ 5,4 }, {4,2});
20
21 decoder = DeepLabV3Decoder(encoder_channels[encoder_channels.size()-1], decoder_channels);
22 segmentation_head = SegmentationHead(decoder_channels, num_classes, 1, upsampling);
23
24 register_module("encoder", std::shared_ptr<Backbone>(encoder));
25 register_module("decoder", decoder);
26 register_module("segmentation_head", segmentation_head);
27}
28
29torch::Tensor DeepLabV3Impl::forward(torch::Tensor x) {
30 std::vector<torch::Tensor> features = encoder->features(x);

Callers

nothing calls this directly

Calls 4

encoder_paramsFunction · 0.85
load_pretrainedMethod · 0.45
make_dilatedMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected