| 1 | #include "UNet.h" |
| 2 | |
| 3 | UNetImpl::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 | |
| 21 | torch::Tensor UNetImpl::forward(torch::Tensor x){ |
| 22 | std::vector<torch::Tensor> features = encoder->features(x); |
nothing calls this directly
no test coverage detected