예제 #1
0
def test_pairwise_temporal_iou():
    target_segments = np.array([])
    candidate_segments = np.array([])
    with pytest.raises(ValueError):
        pairwise_temporal_iou(target_segments, candidate_segments)

    # test temporal iou
    target_segments = np.array([[1, 2], [2, 3]])
    candidate_segments = np.array([[2, 3], [2.5, 3]])
    temporal_iou = pairwise_temporal_iou(candidate_segments, target_segments)
    assert_array_equal(temporal_iou, [[0, 0], [1, 0.5]])

    # test temporal overlap_self
    target_segments = np.array([[1, 2], [2, 3]])
    candidate_segments = np.array([[2, 3], [2.5, 3]])
    temporal_iou, temporal_overlap_self = pairwise_temporal_iou(
        candidate_segments, target_segments, calculate_overlap_self=True)
    assert_array_equal(temporal_overlap_self, [[0, 0], [1, 1]])

    # test temporal overlap_self when candidate_segments is 1d
    target_segments = np.array([[1, 2], [2, 3]])
    candidate_segments = np.array([2.5, 3])
    temporal_iou, temporal_overlap_self = pairwise_temporal_iou(
        candidate_segments, target_segments, calculate_overlap_self=True)
    assert_array_equal(temporal_overlap_self, [0, 1])
예제 #2
0
def test_pairwise_temporal_iou():
    target_segments = np.array([])
    candidate_segments = np.array([])
    with pytest.raises(ValueError):
        pairwise_temporal_iou(target_segments, candidate_segments)

    target_segments = np.array([[1, 2], [2, 3]])
    candidate_segments = np.array([[2, 3], [2.5, 3]])
    temporal_iou = pairwise_temporal_iou(target_segments, candidate_segments)
    assert_array_equal(temporal_iou, [[0, 1], [0, 0.5]])
예제 #3
0
    args = parse_args()
    formatted_proposal_file = open(args.formatted_proposal_file, 'w')

    # The activity index file is constructed according to
    # 'https://github.com/activitynet/ActivityNet/blob/master/Evaluation/eval_classification.py'
    activity_index, class_idx = {}, 0
    for line in open(args.activity_index_file).readlines():
        activity_index[line.strip()] = class_idx
        class_idx += 1

    video_infos = load_annotations(args.ann_file)
    ground_truth = import_ground_truth(video_infos, activity_index)
    proposal, num_proposals = import_proposals(
        mmcv.load(args.proposal_file)['results'])
    video_idx = 0

    for video_info in video_infos:
        video_id = video_info['video_name'][2:]
        num_frames = video_info['duration_frame']
        fps = video_info['fps']
        tiou, t_overlap = pairwise_temporal_iou(
            proposal[video_id][:, :2].astype(float),
            ground_truth[video_id][:, :2].astype(float),
            calculate_overlap_self=True)

        dump_formatted_proposal(video_idx, video_id, num_frames, fps,
                                ground_truth[video_id], proposal[video_id],
                                tiou, t_overlap, formatted_proposal_file)
        video_idx += 1
    formatted_proposal_file.close()