Example #1
0
def bootstrap_matching(ctx, n=100, filter=None, cb_post_match=None):
    all_res = dict()
    all_epochs = []
    all_imgs = dict()
    for i, file in enumerate(ctx.files):
        img = ctx.open_file(file)
        all_epochs.append(img.get_epoch())

        res = ctx.detection(img, filter=filter)
        all_res[img.get_epoch()] = res
        all_imgs[img.get_epoch()] = img

    t = time.time()
    all_match_ratio = []
    for i in range(n):
        eta = ""
        if i > 0:
            remaining = (np.round((time.time() - t) / float(i) * (n - i)))
            eta = " (ETA: %s)" % time.strftime("%H:%M:%S", time.localtime(time.time() + remaining))
        print "Run %s / %s%s" % (i + 1, n, eta)
        
        shuffled = nputils.permutation_no_succesive(all_epochs)
        match_ratio_list = []
        match_results = project.AnalysisResult(ctx.config)

        for epoch1, epoch2 in nputils.pairwise(shuffled):
            res1 = all_res[epoch1].copy()
            res2 = all_res[epoch2].copy()
            # print "Matching:", res1.get_epoch(), "vs", res2.get_epoch()

            res1.epoch = epoch1
            for segments in res1:
                segments.epoch = epoch1

            res2.epoch = epoch2
            for segments in res2:
                segments.epoch = epoch2

            full_match_res = ctx.match(res1, res2, verbose=False)
            match_results.add_match_result(full_match_res)
            match_results.add_detection_result(all_imgs[epoch1], res1)

            for match_res in full_match_res:
                n_segments = match_res.segments1.size()
                match_ratio = (match_res.get_match().size()) / (float(n_segments))
                match_ratio_list.append(match_ratio)

        all_match_ratio.append(np.mean(match_ratio_list))

        if cb_post_match is not None:
            cb_post_match(shuffled, match_results)

        # print "Match ratio stat:", nputils.stat(match_ratio_list)

    # print all_match_ratio

    print "Match ratio stat:", nputils.stat(all_match_ratio)
Example #2
0
def match_all(ctx, filter=None):
    '''Run matching on all selected files
    
    Parameters
    ----------
    ctx : :class:`wise.project.AnalysisContext`
    filter : :class:`wise.features.FeatureFilter`, optional


    .. _tags: task_detection
    '''
    ctx.result = project.AnalysisResult(ctx.config)
    prev_result = None
    prev_img = None
    match_ratio_list = []
    for i, file in enumerate(ctx.files):
        img = ctx.open_file(file)
        res = ctx.detection(img, filter=filter)
        result_copy = res.copy()

        ctx.result.add_detection_result(img, result_copy)

        if prev_result is not None:
            print "Matching %s vs %s (%s / %s)" % (prev_img, img, i, len(ctx.files) - 1)
            match_res = ctx.match(prev_result, res)
            ctx.result.add_match_result(match_res)

            for match_res_scale in match_res:
                n_segments = match_res_scale.segments1.size()
                match_ratio = (match_res_scale.get_match().size()) / (float(n_segments))
                # print match_res_scale.get_match().size(), n_segments
                match_ratio_list.append(match_ratio)
            # print match_ratio_list

        prev_result = result_copy
        prev_img = img

    print "Match ratio stat:", nputils.stat(match_ratio_list)