videos = db.get_subset_videos(args.subset)

# generate proposals and name them
gt_spans = [[(x.num_label, x.time_span) for x in v.instances] for v in videos]
proposal_list = list([
    gen_exponential_sw_proposal(x,
                                overlap=args.overlap,
                                time_step=args.time_step,
                                max_level=args.max_level) for x in videos
])
print(("average # of proposals: {} at overlap param {}".format(
    np.mean(list(map(len, proposal_list))), args.overlap)))

named_proposal_list = [
    name_proposal(x, y) for x, y in zip(gt_spans, proposal_list)
]
recall_list = []
IOU_thresh = [0.5, 0.7, 0.9]
for th in IOU_thresh:
    pv, pi = get_temporal_proposal_recall(proposal_list, [[y[1] for y in x]
                                                          for x in gt_spans],
                                          th)
    print((
        "IOU threshold {}. per video recall: {:02f}, per instance recall: {:02f}"
        .format(th, pv * 100, pi * 100)))
    recall_list.append(
        [args.overlap, th,
         np.mean(list(map(len, proposal_list))), pv, pi])
print(("average per video recall: {:.2f}, average per instance recall: {:.2f}".
       format(np.mean([x[3] for x in recall_list]),
print('average # of proposals: {}'.format(np.mean(list(map(len, proposal_list)))))
IOU_thresh = np.arange(0.5, 1.0, 0.05)
p_list = []
for th in IOU_thresh:
    pv, pi = get_temporal_proposal_recall(proposal_list, gt_spans, th)
    print('IOU threshold {}. per video recall: {:02f}, per instance recall: {:02f}'.format(th, pv * 100, pi * 100))
    p_list.append((pv, pi))
print('Average Recall: {:.04f} {:.04f}'.format(*(np.mean(p_list, axis=0)*100)))

if args.write_proposals:

    name_pattern = 'frame*.jpg'
    frame_path = args.frame_path

    named_proposal_list = [name_proposal(x, y) for x, y in zip(gt_spans_full, proposal_list)]
    # allow_empty = args.dataset == 'activitynet' and args.subset == 'testing'
    dumped_list = [dump_window_list(v, prs, frame_path, name_pattern, score=score, allow_empty=True) for v, prs, score in
                   zip(filter(lambda x: x.id in pr_dict, video_list), named_proposal_list, score_list)]

    with open(args.write_proposals, 'w') as of:
        for i, e in enumerate(dumped_list):
            of.write('# {}\n'.format(i + 1))
            of.write(e)

    print('list {} written. got {} videos'.format(args.write_proposals, len(dumped_list)))


import pandas as pd
video_lst, t_start_lst, t_end_lst, score_lst = [], [], [], []
for k, v in pr_dict.items():