output : from self.forward lane_idx_map : instance-level segmentation map, [20, H, W] where 20=max_lanes
(self, output, lane_idx_map, input_shape)
| 217 | return output |
| 218 | |
| 219 | def loss(self, output, lane_idx_map, input_shape): |
| 220 | """ |
| 221 | output : from self.forward |
| 222 | lane_idx_map : instance-level segmentation map, [20, H, W] where 20=max_lanes |
| 223 | """ |
| 224 | pred_masks = output['pred_masks'] |
| 225 | pred_masks = output['pred_masks'].view( |
| 226 | pred_masks.shape[0], |
| 227 | self.inst_branch.num_group, |
| 228 | self.inst_branch.num_mask, |
| 229 | *pred_masks.shape[2:]) |
| 230 | pred_logits = output['pred_logits'] |
| 231 | pred_logits = output['pred_logits'].view( |
| 232 | pred_logits.shape[0], |
| 233 | self.inst_branch.num_group, |
| 234 | self.inst_branch.num_mask, |
| 235 | *pred_logits.shape[2:]) |
| 236 | pred_scores = output['pred_scores'] |
| 237 | pred_scores = output['pred_scores'].view( |
| 238 | pred_scores.shape[0], |
| 239 | self.inst_branch.num_group, |
| 240 | self.inst_branch.num_mask, |
| 241 | *pred_scores.shape[2:]) |
| 242 | |
| 243 | out = {} |
| 244 | all_matched_indices = [] |
| 245 | for group_idx in range(self.inst_branch.num_group): |
| 246 | sparse_inst_losses, matched_indices = \ |
| 247 | self.sparse_inst_crit( |
| 248 | outputs=dict( |
| 249 | pred_masks=pred_masks[:, group_idx, ...].contiguous(), |
| 250 | pred_logits=pred_logits[:, group_idx, ...].contiguous(), |
| 251 | pred_scores=pred_scores[:, group_idx, ...].contiguous(), |
| 252 | ), |
| 253 | targets=self.prepare_targets(lane_idx_map), |
| 254 | input_shape=input_shape, # seg_bev |
| 255 | ) |
| 256 | for k, v in sparse_inst_losses.items(): |
| 257 | out['%s_%d' % (k, group_idx)] = v |
| 258 | all_matched_indices.append(matched_indices) |
| 259 | return out, all_matched_indices |
| 260 | |
| 261 | def prepare_targets(self, targets): |
| 262 | new_targets = [] |
no test coverage detected