| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | """Calculate mAP @ IoU thresholds for detection.""" |
| |
|
| | import numpy as np |
| | from ..third_party.pkummd import process |
| |
|
| |
|
| | def get_segments(scores, activity_threshold): |
| | """Get prediction segments of a video.""" |
| | |
| | |
| | activity_prob = 1 - scores[:, 0] |
| | |
| | activity_tag = np.zeros(activity_prob.shape, dtype=np.int32) |
| | activity_tag[activity_prob >= activity_threshold] = 1 |
| | assert activity_tag.ndim == 1 |
| | |
| | |
| | padded = np.pad(activity_tag, pad_width=1, mode='constant') |
| | diff = padded[1:] - padded[:-1] |
| | indexes = np.arange(diff.size) |
| | startings = indexes[diff == 1] |
| | endings = indexes[diff == -1] |
| | assert startings.size == endings.size |
| |
|
| | segments = [] |
| | for start, end in zip(startings, endings): |
| | segment_scores = scores[start:end, :] |
| | class_prob = np.mean(segment_scores, axis=0) |
| | segment_class_index = np.argmax(class_prob[1:]) + 1 |
| | confidence = np.mean(segment_scores[:, segment_class_index]) |
| | segments.append((segment_class_index, start, end, confidence)) |
| | return segments |
| |
|
| |
|
| | def calc_map(opt, video_scores, video_names, groundtruth_dir, iou_thresholds): |
| | """Get mAP (action) for IoU 0.1, 0.3 and 0.5.""" |
| | activity_threshold = 0.4 |
| | num_videos = len(video_scores) |
| | video_files = [name + '.txt' for name in video_names] |
| |
|
| | v_props = [] |
| | for i in range(num_videos): |
| | |
| | scores = video_scores[i] |
| | segments = get_segments(scores, activity_threshold) |
| |
|
| | prop = [] |
| | for segment in segments: |
| | cls, start, end, score = segment |
| | |
| | start_index = start * 10 * 10 |
| | end_index = ( |
| | (end - 1) * opt.step_size + opt.n_frames) * 10 - 1 |
| | prop.append([cls, start_index, end_index, score, video_files[i]]) |
| | v_props.append(prop) |
| |
|
| | |
| | mean_aps = [] |
| | for iou in iou_thresholds: |
| | mean_ap = process(v_props, video_files, groundtruth_dir, iou) |
| | mean_aps.append(mean_ap) |
| | return mean_aps |