Example #1
0
 def dev_cls(back):
     """ Help -> Developer Mode"""
     print('[back] dev_cls')
     print('\n'.join([''] * 100))
     back.refresh_state()
     from plottool import draw_func2 as df2
     df2.update()
 def on_click_inside(self, event, ax):
     index = ph.get_plotdat(ax, 'index')
     print('index = %r' % (index, ))
     if index is not None:
         if self.MOUSE_BUTTONS[event.button] == 'right':
             if self.context_option_funcs is not None:
                 #if event.button == 3:
                 options = self.context_option_funcs[index]()
                 self.show_popup_menu(options, event)
         elif self.MOUSE_BUTTONS[event.button] == 'left':
             #bbox_list  = ph.get_plotdat(ax, 'bbox_list')
             gpath = self.gpath_list[index]
             if ut.is_funclike(gpath):
                 print('gpath_isfunklike')
                 print('gpath = %r' % (gpath, ))
                 import plottool as pt
                 fnum = pt.next_fnum()
                 gpath(fnum=fnum)
                 df2.update()
             else:
                 bbox_list = self.bboxes_list[index]
                 print('Bbox of figure: %r' % (bbox_list, ))
                 theta_list = self.thetas_list[index]
                 print('theta_list = %r' % (theta_list, ))
                 #img = mpimg.imread(gpath)
                 if isinstance(gpath, six.string_types):
                     img = vt.imread(gpath)
                 else:
                     img = gpath
                 fnum = df2.next_fnum()
                 mc = interact_annotations.ANNOTATIONInteraction(
                     img,
                     index,
                     self.update_images,
                     bbox_list=bbox_list,
                     theta_list=theta_list,
                     fnum=fnum)
                 mc.start()
                 self.mc = mc
                 # """wait for accept
                 # have a flag to tell if a bbox has been changed, on the bbox
                 # list that is brought it" on accept: viz_image2.show_image
                 # callback
                 # """
                 df2.update()
         print('Clicked: ax: num=%r' % index)
 def on_click_inside(self, event, ax):
     index = ph.get_plotdat(ax, 'index')
     print('index = %r' % (index,))
     if index is not None:
         if self.MOUSE_BUTTONS[event.button] == 'right':
             if self.context_option_funcs is not None:
                 #if event.button == 3:
                 options = self.context_option_funcs[index]()
                 self.show_popup_menu(options, event)
         elif self.MOUSE_BUTTONS[event.button] == 'left':
             #bbox_list  = ph.get_plotdat(ax, 'bbox_list')
             gpath = self.gpath_list[index]
             if ut.is_funclike(gpath):
                 print('gpath_isfunklike')
                 print('gpath = %r' % (gpath,))
                 import plottool as pt
                 fnum = pt.next_fnum()
                 gpath(fnum=fnum)
                 df2.update()
             else:
                 bbox_list = self.bboxes_list[index]
                 print('Bbox of figure: %r' % (bbox_list,))
                 theta_list = self.thetas_list[index]
                 print('theta_list = %r' % (theta_list,))
                 #img = mpimg.imread(gpath)
                 if isinstance(gpath, six.string_types):
                     img = vt.imread(gpath)
                 else:
                     img = gpath
                 fnum = df2.next_fnum()
                 mc = interact_annotations.ANNOTATIONInteraction(
                     img, index, self.update_images, bbox_list=bbox_list,
                     theta_list=theta_list, fnum=fnum)
                 mc.start()
                 self.mc = mc
                 # """wait for accept
                 # have a flag to tell if a bbox has been changed, on the bbox
                 # list that is brought it" on accept: viz_image2.show_image
                 # callback
                 # """
                 df2.update()
         print('Clicked: ax: num=%r' % index)
Example #4
0
 def __init__(self, ibs, gid, next_callback=None, prev_callback=None, rows_updated_callback=lambda: None, reset_window=True):
     self.ibs = ibs
     self.gid = gid
     self.rows_updated_callback = rows_updated_callback
     img = ibs.get_images(self.gid)
     self.aid_list = ibs.get_image_aids(self.gid)
     bbox_list = ibs.get_annot_bboxes(self.aid_list)
     theta_list = ibs.get_annot_thetas(self.aid_list)
     species_list = ibs.get_annot_species(self.aid_list)
     self.interact_ANNOTATIONS = interact_annotations.ANNOTATIONInteraction(
         img,
         bbox_list=bbox_list,
         theta_list=theta_list,
         species_list=species_list,
         callback=self.callback,
         default_species=self.ibs.cfg.detect_cfg.species,
         next_callback=next_callback,
         prev_callback=prev_callback,
         fnum=12,
         #figure_to_use=None if reset_window else self.interact_ANNOTATIONS.fig,
     )
     df2.update()
Example #5
0
def plot_scores2(hs, qcx_list, fnum=1):
    print('[dev] plot_scores(fnum=%r)' % fnum)
    qcx2_res = get_qcx2_res(hs, qcx_list)
    all_score_list = []
    gtscore_ys = []
    gtscore_xs = []
    gtscore_ranks = []
    EXCLUDE_ZEROS = False
    N = 1
    # Append all scores to a giant list
    for res in qcx2_res.itervalues():
        cx2_score = res.cx2_score
        # Get gt scores first
        #gt_cxs = hs.get_other_indexed_cxs(res.qcx)
        gt_cxs = np.array(res.topN_cxs(hs, N=N, only_gt=True))
        gt_ys = cx2_score[gt_cxs]
        if EXCLUDE_ZEROS:
            nonzero_cxs = np.where(cx2_score != 0)[0]
            gt_cxs = gt_cxs[gt_ys != 0]
            gt_ranks = res.get_gt_ranks(gt_cxs)
            gt_cxs = np.array(utool.list_index(nonzero_cxs, gt_cxs))
            gt_ys  = gt_ys[gt_ys != 0]
            score_list = cx2_score[nonzero_cxs].tolist()
        else:
            score_list = cx2_score.tolist()
            gt_ranks = res.get_gt_ranks(gt_cxs)
        gtscore_ys.extend(gt_ys)
        gtscore_xs.extend(gt_cxs + len(all_score_list))
        gtscore_ranks.extend(gt_ranks)
        # Append all scores
        all_score_list.extend(score_list)
    all_score_list = np.array(all_score_list)
    gtscore_ranks = np.array(gtscore_ranks)
    gtscore_ys = np.array(gtscore_ys)

    # Sort all chipmatch scores
    allx_sorted = all_score_list.argsort()  # mapping from sortedallx to allx
    allscores_sorted = all_score_list[allx_sorted]
    # Change the groundtruth positions to correspond to sorted cmatch scores
    # Find position of gtscore_xs in allx_sorted
    gtscore_sortxs = utool.list_index(allx_sorted, gtscore_xs)
    gtscore_sortxs = np.array(gtscore_sortxs)
    # Draw and info
    rank_bounds = [
        (0, 1),
        (1, 5),
        (5, None)
    ]
    rank_colors = [
        df2.TRUE_GREEN,
        df2.UNKNOWN_PURP,
        df2.FALSE_RED
    ]
    print('[dev] matching chipscore stats: ' + utool.stats_str(all_score_list))
    df2.figure(fnum=fnum, doclf=True, docla=True)
    # Finds the knee
    df2.plot(allscores_sorted, color=df2.ORANGE, label='all scores')

    # get positions which are within rank bounds
    for count, ((low, high), rankX_color) in reversed(list(enumerate(zip(rank_bounds, rank_colors)))):
        rankX_flag_low = gtscore_ranks >= low
        if high is not None:
            rankX_flag_high = gtscore_ranks < high
            rankX_flag = np.logical_and(rankX_flag_low, rankX_flag_high)
        else:
            rankX_flag = rankX_flag_low
        rankX_allgtx = np.where(rankX_flag)[0]
        rankX_gtxs = gtscore_sortxs[rankX_allgtx]
        rankX_gtys = gtscore_ys[rankX_allgtx]
        rankX_label = '%d <= gt rank' % low
        if high is not None:
            rankX_label += ' < %d' % high
        if len(rankX_gtxs) > 0:
            df2.plot(rankX_gtxs, rankX_gtys, 'o', color=rankX_color, label=rankX_label)

    rowid = qcx2_res.itervalues().next().rowid

    df2.set_logyscale_from_data(allscores_sorted)

    df2.set_xlabel('chipmatch index')
    df2.dark_background()
    df2.set_figtitle('matching scores\n' + rowid)
    df2.legend(loc='upper left')
    #xmin = 0
    #xmax = utool.order_of_magnitude_ceil(len(allscores_sorted))
    #print('len_ = %r' % (len(allscores_sorted),))
    #print('xmin = %r' % (xmin,))
    #print('xmax = %r' % (xmax,))
    #df2.gca().set_xlim(xmin, xmax)
    df2.update()

    #utool.embed()
    # Second Plot
    #data = sorted(zip(gtscore_sortxs, gtscore_ys, gtscore_ranks))
    #gtxs = [x for (x, y, z) in data]
    #gtys = [y for (x, y, z) in data]
    #gtrs = [z for (x, y, z) in data]
    #nongtxs = np.setdiff1d(np.arange(gtxs[0], gtxs[-1]), gtxs)

    #min_ = min(gtxs)
    #max_ = len(allscores_sorted)
    #len_ = max_ - min_
    #normsum = 0
    #ratsum = 0
    #gtxs = np.array(gtxs)
    #nongtxs = np.array(nongtxs)
    #for ix in xrange(min_, max_):
        #nongtxs_ = nongtxs[nongtxs >= ix]
        #gtxs_ = gtxs[gtxs >= ix]
        #numer = allscores_sorted[gtxs_].sum()
        #denom = allscores_sorted[nongtxs_].sum()
        #ratio = (1 + numer) / (denom + 1)
        #total_support = (len(gtxs_) + len(nongtxs_))
        #normrat = ratio / total_support
        #ratsum += ratio
        #normsum += normrat
        #print(total_support)
    #print(ratsum / len_)
    #print(normsum / len_)
    #print(ratsum / allscores_sorted[min_:max_].sum())
    #print(normsum / allscores_sorted[min_:max_].sum())

    #index_gap = np.diff(gtxs)
    #score_gap = np.diff(gtys)
    #badness = (index_gap - 1) * score_gap
    #np.arange(len(gtxs))

    fnum += 1
    return fnum
Example #6
0
 def query_last_feature():
     viz.show_nearest_descriptors(ibs, qaid, last_state.last_fx, df2.next_fnum())
     fig3 = df2.gcf()
     ih.connect_callback(fig3, 'button_press_event', _click_matches_click)
     df2.update()