MCPcopy Create free account
hub / github.com/NVIDIA/semantic-segmentation / two_scale_forward

Method two_scale_forward

network/mscale.py:182–220  ·  view source on GitHub ↗
(self, inputs)

Source from the content-addressed store, hash-verified

180 return output_dict
181
182 def two_scale_forward(self, inputs):
183 assert 'images' in inputs
184
185 x_1x = inputs['images']
186 x_lo = ResizeX(x_1x, cfg.MODEL.MSCALE_LO_SCALE)
187
188 pred_05x, attn_05x, aspp_attn, aspp_lo = \
189 self._fwd(x_lo)
190
191 p_1x, _, _, _ = self._fwd(x_1x, aspp_lo=aspp_lo,
192 aspp_attn=aspp_attn)
193
194 p_lo = attn_05x * pred_05x
195 p_lo = scale_as(p_lo, p_1x)
196 logit_attn = scale_as(attn_05x, p_1x)
197 joint_pred = p_lo + (1 - logit_attn) * p_1x
198
199 if self.training:
200 assert 'gts' in inputs
201 gts = inputs['gts']
202 loss = self.criterion(joint_pred, gts)
203
204 # Optionally, apply supervision to the multi-scale predictions
205 # directly. Turn off RMI to keep things lightweight
206 if cfg.LOSS.SUPERVISED_MSCALE_WT:
207 scaled_pred_05x = scale_as(pred_05x, p_1x)
208 loss_lo = self.criterion(scaled_pred_05x, gts, do_rmi=False)
209 loss_hi = self.criterion(p_1x, gts, do_rmi=False)
210 loss += cfg.LOSS.SUPERVISED_MSCALE_WT * loss_lo
211 loss += cfg.LOSS.SUPERVISED_MSCALE_WT * loss_hi
212 return loss
213 else:
214 output_dict = {
215 'pred': joint_pred,
216 'pred_05x': pred_05x,
217 'pred_10x': p_1x,
218 'attn_05x': attn_05x,
219 }
220 return output_dict
221
222 def forward(self, inputs):
223 if cfg.MODEL.N_SCALES and not self.training:

Callers 1

forwardMethod · 0.95

Calls 3

_fwdMethod · 0.95
ResizeXFunction · 0.90
scale_asFunction · 0.90

Tested by

no test coverage detected