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

Method DeepLabV3PlusImpl

src/architectures/DeepLab.cpp:36–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36DeepLabV3PlusImpl::DeepLabV3PlusImpl(int _num_classes, std::string encoder_name, std::string pretrained_path, int encoder_depth,
37 int encoder_output_stride, int decoder_channels, int in_channels, double upsampling) {
38 num_classes = _num_classes;
39 auto encoder_param = encoder_params();
40 std::vector<int> encoder_channels = encoder_param[encoder_name]["out_channels"];
41 if (!encoder_param.contains(encoder_name))
42 std::cout<< "encoder name must in {resnet18, resnet34, resnet50, resnet101, resnet150, \
43 resnext50_32x4d, resnext101_32x8d, vgg11, vgg11_bn, vgg13, vgg13_bn, \
44 vgg16, vgg16_bn, vgg19, vgg19_bn,}";
45 if (encoder_param[encoder_name]["class_type"] == "resnet")
46 encoder = new ResNetImpl(encoder_param[encoder_name]["layers"], 1000, encoder_name);
47 else if (encoder_param[encoder_name]["class_type"] == "vgg")
48 encoder = new VGGImpl(encoder_param[encoder_name]["cfg"], 1000, encoder_param[encoder_name]["batch_norm"]);
49 else std::cout<< "unknown error in backbone initialization";
50
51 encoder->load_pretrained(pretrained_path);
52 if (encoder_output_stride == 8) {
53 encoder->make_dilated({ 5,4 }, { 4,2 });
54 }
55 else if (encoder_output_stride == 16) {
56 encoder->make_dilated({ 5 }, { 2 });
57 }
58 else {
59 std::cout<< "Encoder output stride should be 8 or 16";
60 }
61
62 decoder = DeepLabV3PlusDecoder(encoder_channels, decoder_channels, decoder_atrous_rates, encoder_output_stride);
63 segmentation_head = SegmentationHead(decoder_channels, num_classes, 1, upsampling);
64
65 register_module("encoder", std::shared_ptr<Backbone>(encoder));
66 register_module("decoder", decoder);
67 register_module("segmentation_head", segmentation_head);
68}
69
70torch::Tensor DeepLabV3PlusImpl::forward(torch::Tensor x) {
71 std::vector<torch::Tensor> features = encoder->features(x);

Callers

nothing calls this directly

Calls 3

encoder_paramsFunction · 0.85
load_pretrainedMethod · 0.45
make_dilatedMethod · 0.45

Tested by

no test coverage detected