Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def motp_mota(obj, hyp, threshold=0.5):
- """Calculate MOTP/MOTA
- obj: list
- Ground truth frame detections.
- detections: numpy int array Cx5 [[id, xmin, ymin, xmax, ymax]]
- hyp: list
- Hypothetical frame detections.
- detections: numpy int array Cx5 [[id, xmin, ymin, xmax, ymax]]
- threshold: IOU threshold
- """
- dist_sum = 0 # a sum of IOU distances between matched objects and hypotheses
- match_count = 0
- missed_count = 0
- false_positive = 0
- mismatch_error = 0
- matches = {} # matches between object IDs and hypothesis IDs
- # For every frame
- for frame_obj, frame_hyp in zip(obj, hyp):
- # Step 1: Convert frame detections to dict with IDs as keys
- frame_obj = {el[0]: el[1:] for el in frame_obj}
- frame_hyp = {el[0]: el[1:] for el in frame_hyp}
- # Step 2: Iterate over all previous matches
- # If object is still visible, hypothesis still exists
- # and IOU distance > threshold - we've got a match
- # Update the sum of IoU distances and match count
- # Delete matched detections from frame detections
- for m_id in matches:
- if m_id in frame_obj.keys() and m_id in frame_hyp.keys():
- cur_iou = iou_score(frame_obj[m_id], frame_hyp[m_id])
- if cur_iou > threshold:
- dist_sum += cur_iou
- match_count += 1
- del frame_obj[m_id]
- del frame_hyp[m_id]
- # Step 3: Calculate pairwise detection IOU between remaining frame detections
- # Save IDs with IOU > threshold
- iou_list = []
- for gt_id in frame_obj:
- for h_id in frame_hyp:
- cur_iou = iou_score(frame_obj[gt_id], frame_hyp[h_id])
- if cur_iou > threshold:
- iou_list.append([gt_id, h_id, cur_iou])
- # Step 4: Iterate over sorted pairwise IOU
- # Update the sum of IoU distances and match count
- # Delete matched detections from frame detections
- del_gt = set()
- del_h = set()
- for val in iou_list:
- if val[0] not in del_gt and val[1] not in del_h:
- dist_sum += val[2]
- match_count += 1
- del_gt.add(val[0])
- del_h.add(val[1])
- if val[0] in matches.keys() and matches[val[0]] != val[1]:
- mismatch_error += 1
- matches[val[0]] = val[1]
- # Step 5: If matched IDs contradict previous matched IDs - increase mismatch error
- pass
- # Step 6: Update matches with current matched IDs
- pass
- # Step 7: Errors
- # All remaining hypotheses are considered false positives
- # All remaining objects are considered misses
- for i in frame_obj:
- if i not in del_gt:
- missed_count += 1
- for i in frame_hyp:
- if i not in del_h:
- false_positive += 1
- # Step 8: Calculate MOTP and MOTA
- MOTP = dist_sum / match_count
- MOTA = 1 - (missed_count + mismatch_error + false_positive) / (match_count + missed_count)
- return MOTP, MOTA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement