MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / UNetImpl

Method UNetImpl

lesson6-Segmentation/UNet.cpp:3–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "UNet.h"
2
3UNetImpl::UNetImpl(int _num_classes, std::string encoder_name, std::string pretrained_path, int encoder_depth,
4 std::vector<int> decoder_channels, bool use_attention){
5 num_classes = _num_classes;
6 std::vector<int> encoder_channels = BasicChannels;
7 if(!name2layers.count(encoder_name)) throw "encoder name must in {resnet18, resnet34, resnet50, resnet101}";
8 if(encoder_name!="resnet18" && encoder_name!="resnet34"){
9 encoder_channels = BottleChannels;
10 }
11
12 encoder = pretrained_resnet(1000, encoder_name, pretrained_path);
13 decoder = UNetDecoder(encoder_channels,decoder_channels, encoder_depth, use_attention, false);
14 segmentation_head = SegmentationHead(decoder_channels[decoder_channels.size()-1], num_classes, 1, 1);
15
16 register_module("encoder",encoder);
17 register_module("decoder",decoder);
18 register_module("segmentation_head",segmentation_head);
19}
20
21torch::Tensor UNetImpl::forward(torch::Tensor x){
22 std::vector<torch::Tensor> features = encoder->features(x);

Callers

nothing calls this directly

Calls 3

pretrained_resnetFunction · 0.85
countMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected