Exemple #1
0
def viz_threshold_matchings(hsA, hsB, count2rr_AB, thresh_out_dir):
    'returns database, cx, database cx'
    import numpy as np
    valid_cxsB = hsB.cm.get_valid_cxs()
    num_matching = 0

    MATCH_THRESHOLD = __method_2_matchthresh__.get(__METHOD__, 10)
    results_name = get_results_name(hsA, hsB)
    print('  * Visualizing threshold matchings ' + results_name +
          ' give it some time to plot...')
    threshdb_out_dir = join_mkdir(thresh_out_dir, results_name)
    # For each query run in hsA vs hsB
    for count in xrange(len(count2rr_AB)):
        rr = count2rr_AB[count]
        qcx = rr.qcx
        res = QueryResult(hsB, rr, hsA)
        qname = res.qhs.cm.cx2_name(qcx)
        # Set matching threshold
        res.top_thresh = MATCH_THRESHOLD
        res.num_top_min = 0
        res.num_top_max = 5
        res.num_extra_return = 0
        # Check to see if any matched over the threshold
        top_cxs = res.top_cx()
        top_names = res.hs.cm.cx2_name(top_cxs)
        top_scores = res.scores()[top_cxs]
        if len(top_cxs) > 0:
            # Visualize the result
            # Stupid segfaults #if qcx == 113: #41: #import IPython #IPython.embed() # Get the scores
            num_matching += 1
            res.visualize()
            # Create a filename showing dataset, score, cx, match names
            matchname_set = \
                    set([name.replace('Lionfish','') for name in (top_names+[qname])])
            matchnames = '-'.join(list(matchname_set))
            scorestr = str(int(round(top_scores[0])))

            fig_fname = '-'.join([
                results_name, 'score' + scorestr, 'cx' + str(qcx),
                'MATCHES' + matchnames
            ]) + '.jpg'

            fig = myfigure(0)
            fig_fpath = join(threshdb_out_dir, fig_fname)
            sys.stdout.write('.')
            safe_savefig(fig, fig_fpath)
    print('  * Visualized %d above thresh: %f from expt: %s ' %
          (num_matching, MATCH_THRESHOLD, results_name))
def viz_threshold_matchings(hsA, hsB, count2rr_AB, thresh_out_dir):
    'returns database, cx, database cx'
    import numpy as np
    valid_cxsB = hsB.cm.get_valid_cxs()
    num_matching = 0
    
    MATCH_THRESHOLD = __method_2_matchthresh__.get(__METHOD__, 10)
    results_name = get_results_name(hsA, hsB)
    print('  * Visualizing threshold matchings '+results_name+' give it some time to plot...')
    threshdb_out_dir = join_mkdir(thresh_out_dir, results_name)
    # For each query run in hsA vs hsB
    for count in xrange(len(count2rr_AB)):
        rr    = count2rr_AB[count]
        qcx   = rr.qcx
        res   = QueryResult(hsB, rr, hsA)
        qname = res.qhs.cm.cx2_name(qcx)
        # Set matching threshold
        res.top_thresh       = MATCH_THRESHOLD
        res.num_top_min      = 0
        res.num_top_max      = 5
        res.num_extra_return = 0
        # Check to see if any matched over the threshold
        top_cxs    = res.top_cx()
        top_names  = res.hs.cm.cx2_name(top_cxs)
        top_scores = res.scores()[top_cxs]
        if len(top_cxs) > 0:
            # Visualize the result
            # Stupid segfaults #if qcx == 113: #41: #import IPython #IPython.embed() # Get the scores
            num_matching += 1
            res.visualize()
            # Create a filename showing dataset, score, cx, match names
            matchname_set = \
                    set([name.replace('Lionfish','') for name in (top_names+[qname])])
            matchnames = '-'.join(list(matchname_set))
            scorestr = str(int(round(top_scores[0])))

            fig_fname = '-'.join([results_name,
                                 'score'+scorestr,
                                 'cx'+str(qcx),
                                 'MATCHES'+matchnames])+'.jpg'

            fig = myfigure(0)
            fig_fpath = join(threshdb_out_dir, fig_fname)
            sys.stdout.write('.')
            safe_savefig(fig, fig_fpath)
    print('  * Visualized %d above thresh: %f from expt: %s ' % (num_matching,
                                                                 MATCH_THRESHOLD,
                                                                 results_name))
Exemple #3
0
def write_all_chipscore_results(hsA, hsB, count2rr_AB, txt_output_fpath):
    txt_header = '''#<COMMENTED_XML_HEADER>
#  <filename>
#    ''' + txt_output_fpath + '''
#  </filename>
#  
#  <description> 
#    Sorted Query Results. The results are stored in the format:
#    The first line gives the query image name, the next lines are 
#    a sorted list of result image names and scores. Queries are 
#    separated by two new lines. 
#  </description>
#  
#  <data_format>
#    queryA
#    resultA1 scoreA1
#    resultA2 scoreA2
#    resultA3 scoreA3
#    ...
#    
#    queryB-gname
#    resultB1 scoreB1
#    resultB2 scoreB2
#    resultB3 scoreB3
#    ...
#     
#    ...
#  </data_format>
#</COMMENTED_XML_HEADER>

'''
    txt_body = ''
    for count in range(len(count2rr_AB)):
        rr = count2rr_AB[count]
        res = QueryResult(hsB, rr, hsA)
        txt_body += hsA.cm.cx2_gname(rr.qcx) + '\n'
        top_cxs = res.cx_sort()
        scores = res.scores()
        output_tup_list = []
        for cx in top_cxs:
            output_tup_list.append((hsB.cm.cx2_gname(cx), scores[cx]))
        output_tup_list.sort(key=lambda tup: tup[1])
        output_tup_list = output_tup_list[::-1]
        for tup in output_tup_list:
            txt_body += tup[0] + ' ' + str(tup[1]) + '\n'
        txt_body += '\n'
    with open(txt_output_fpath, 'w') as file:
        file.write(txt_body)
def write_all_chipscore_results(hsA, hsB, count2rr_AB, txt_output_fpath):
    txt_header = '''#<COMMENTED_XML_HEADER>
#  <filename>
#    '''+txt_output_fpath+'''
#  </filename>
#  
#  <description> 
#    Sorted Query Results. The results are stored in the format:
#    The first line gives the query image name, the next lines are 
#    a sorted list of result image names and scores. Queries are 
#    separated by two new lines. 
#  </description>
#  
#  <data_format>
#    queryA
#    resultA1 scoreA1
#    resultA2 scoreA2
#    resultA3 scoreA3
#    ...
#    
#    queryB-gname
#    resultB1 scoreB1
#    resultB2 scoreB2
#    resultB3 scoreB3
#    ...
#     
#    ...
#  </data_format>
#</COMMENTED_XML_HEADER>

'''
    txt_body = ''
    for count in range(len(count2rr_AB)):
        rr = count2rr_AB[count]
        res = QueryResult(hsB, rr, hsA)
        txt_body += hsA.cm.cx2_gname(rr.qcx)+'\n'
        top_cxs = res.cx_sort()
        scores = res.scores()
        output_tup_list = []
        for cx in top_cxs:
            output_tup_list.append((hsB.cm.cx2_gname(cx), scores[cx]))
        output_tup_list.sort(key=lambda tup: tup[1]) 
        output_tup_list = output_tup_list[::-1]
        for tup in output_tup_list:
            txt_body += tup[0]+' '+str(tup[1])+'\n'
        txt_body+='\n'
    with open(txt_output_fpath,'w') as file:
        file.write(txt_body)