(self, outputs: dict)
| 173 | return losses |
| 174 | |
| 175 | def match_for_single_frame(self, outputs: dict): |
| 176 | outputs_without_aux = {k: v for k, v in outputs.items() if k != 'aux_outputs'} |
| 177 | |
| 178 | gt_instances_i = self.gt_instances[self._current_frame_idx] # gt instances of i-th image. |
| 179 | track_instances: Instances = outputs_without_aux['track_instances'] |
| 180 | pred_logits_i = track_instances.pred_logits # predicted logits of i-th image. |
| 181 | pred_boxes_i = track_instances.pred_boxes # predicted boxes of i-th image. |
| 182 | |
| 183 | obj_idxes = gt_instances_i.obj_ids |
| 184 | obj_idxes_list = obj_idxes.detach().cpu().numpy().tolist() |
| 185 | obj_idx_to_gt_idx = {obj_idx: gt_idx for gt_idx, obj_idx in enumerate(obj_idxes_list)} |
| 186 | outputs_i = { |
| 187 | 'pred_logits': pred_logits_i.unsqueeze(0), |
| 188 | 'pred_boxes': pred_boxes_i.unsqueeze(0), |
| 189 | } |
| 190 | |
| 191 | # step1. inherit and update the previous tracks. |
| 192 | num_disappear_track = 0 |
| 193 | for j in range(len(track_instances)): |
| 194 | obj_id = track_instances.obj_idxes[j].item() |
| 195 | # set new target idx. |
| 196 | if obj_id >= 0: |
| 197 | if obj_id in obj_idx_to_gt_idx: |
| 198 | track_instances.matched_gt_idxes[j] = obj_idx_to_gt_idx[obj_id] |
| 199 | else: |
| 200 | num_disappear_track += 1 |
| 201 | track_instances.matched_gt_idxes[j] = -1 # track-disappear case. |
| 202 | else: |
| 203 | track_instances.matched_gt_idxes[j] = -1 |
| 204 | |
| 205 | full_track_idxes = torch.arange(len(track_instances), dtype=torch.long).to(pred_logits_i.device) |
| 206 | matched_track_idxes = (track_instances.obj_idxes >= 0) # occu |
| 207 | prev_matched_indices = torch.stack( |
| 208 | [full_track_idxes[matched_track_idxes], track_instances.matched_gt_idxes[matched_track_idxes]], dim=1).to( |
| 209 | pred_logits_i.device) |
| 210 | |
| 211 | # step2. select the unmatched slots. |
| 212 | # note that the FP tracks whose obj_idxes are -2 will not be selected here. |
| 213 | unmatched_track_idxes = full_track_idxes[track_instances.obj_idxes == -1] |
| 214 | |
| 215 | # step3. select the untracked gt instances (new tracks). |
| 216 | tgt_indexes = track_instances.matched_gt_idxes |
| 217 | tgt_indexes = tgt_indexes[tgt_indexes != -1] |
| 218 | |
| 219 | tgt_state = torch.zeros(len(gt_instances_i)).to(pred_logits_i.device) |
| 220 | tgt_state[tgt_indexes] = 1 |
| 221 | untracked_tgt_indexes = torch.arange(len(gt_instances_i)).to(pred_logits_i.device)[tgt_state == 0] |
| 222 | # untracked_tgt_indexes = select_unmatched_indexes(tgt_indexes, len(gt_instances_i)) |
| 223 | untracked_gt_instances = gt_instances_i[untracked_tgt_indexes] |
| 224 | |
| 225 | def match_for_single_decoder_layer(unmatched_outputs, matcher): |
| 226 | new_track_indices = matcher(unmatched_outputs, |
| 227 | [untracked_gt_instances]) # list[tuple(src_idx, tgt_idx)] |
| 228 | |
| 229 | src_idx = new_track_indices[0][0] |
| 230 | tgt_idx = new_track_indices[0][1] |
| 231 | # concat src and tgt. |
| 232 | new_matched_indices = torch.stack([unmatched_track_idxes[src_idx], untracked_tgt_indexes[tgt_idx]], |
no test coverage detected