MCPcopy Create free account
hub / github.com/NVlabs/SegFormer / CascadeEncoderDecoder

Class CascadeEncoderDecoder

mmseg/models/segmentors/cascade_encoder_decoder.py:11–98  ·  view source on GitHub ↗

Cascade Encoder Decoder segmentors. CascadeEncoderDecoder almost the same as EncoderDecoder, while decoders of CascadeEncoderDecoder are cascaded. The output of previous decoder_head will be the input of next decoder_head.

Source from the content-addressed store, hash-verified

9
10@SEGMENTORS.register_module()
11class CascadeEncoderDecoder(EncoderDecoder):
12 """Cascade Encoder Decoder segmentors.
13
14 CascadeEncoderDecoder almost the same as EncoderDecoder, while decoders of
15 CascadeEncoderDecoder are cascaded. The output of previous decoder_head
16 will be the input of next decoder_head.
17 """
18
19 def __init__(self,
20 num_stages,
21 backbone,
22 decode_head,
23 neck=None,
24 auxiliary_head=None,
25 train_cfg=None,
26 test_cfg=None,
27 pretrained=None):
28 self.num_stages = num_stages
29 super(CascadeEncoderDecoder, self).__init__(
30 backbone=backbone,
31 decode_head=decode_head,
32 neck=neck,
33 auxiliary_head=auxiliary_head,
34 train_cfg=train_cfg,
35 test_cfg=test_cfg,
36 pretrained=pretrained)
37
38 def _init_decode_head(self, decode_head):
39 """Initialize ``decode_head``"""
40 assert isinstance(decode_head, list)
41 assert len(decode_head) == self.num_stages
42 self.decode_head = nn.ModuleList()
43 for i in range(self.num_stages):
44 self.decode_head.append(builder.build_head(decode_head[i]))
45 self.align_corners = self.decode_head[-1].align_corners
46 self.num_classes = self.decode_head[-1].num_classes
47
48 def init_weights(self, pretrained=None):
49 """Initialize the weights in backbone and heads.
50
51 Args:
52 pretrained (str, optional): Path to pre-trained weights.
53 Defaults to None.
54 """
55 self.backbone.init_weights(pretrained=pretrained)
56 for i in range(self.num_stages):
57 self.decode_head[i].init_weights()
58 if self.with_auxiliary_head:
59 if isinstance(self.auxiliary_head, nn.ModuleList):
60 for aux_head in self.auxiliary_head:
61 aux_head.init_weights()
62 else:
63 self.auxiliary_head.init_weights()
64
65 def encode_decode(self, img, img_metas):
66 """Encode images with backbone and decode into a semantic segmentation
67 map of the same size as input."""
68 x = self.extract_feat(img)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected