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

Method forward_train

mmseg/models/segmentors/encoder_decoder.py:136–166  ·  view source on GitHub ↗

Forward function for training. Args: img (Tensor): Input images. img_metas (list[dict]): List of image info dict where each dict has: 'img_shape', 'scale_factor', 'flip', and may also contain 'filename', 'ori_shape', 'pad_shape', and '

(self, img, img_metas, gt_semantic_seg)

Source from the content-addressed store, hash-verified

134 return seg_logit
135
136 def forward_train(self, img, img_metas, gt_semantic_seg):
137 """Forward function for training.
138
139 Args:
140 img (Tensor): Input images.
141 img_metas (list[dict]): List of image info dict where each dict
142 has: 'img_shape', 'scale_factor', 'flip', and may also contain
143 'filename', 'ori_shape', 'pad_shape', and 'img_norm_cfg'.
144 For details on the values of these keys see
145 `mmseg/datasets/pipelines/formatting.py:Collect`.
146 gt_semantic_seg (Tensor): Semantic segmentation masks
147 used if the architecture supports semantic segmentation task.
148
149 Returns:
150 dict[str, Tensor]: a dictionary of loss components
151 """
152
153 x = self.extract_feat(img)
154
155 losses = dict()
156
157 loss_decode = self._decode_head_forward_train(x, img_metas,
158 gt_semantic_seg)
159 losses.update(loss_decode)
160
161 if self.with_auxiliary_head:
162 loss_aux = self._auxiliary_head_forward_train(
163 x, img_metas, gt_semantic_seg)
164 losses.update(loss_aux)
165
166 return losses
167
168 # TODO refactor
169 def slide_inference(self, img, img_meta, rescale):

Callers 2

Calls 3

extract_featMethod · 0.95

Tested by

no test coverage detected