Beispiel #1
0
    def on_click_inside(self, event, ax):
        from plottool import plot_helpers as ph
        ibs       = self.ibs
        viztype = ph.get_plotdat(ax, 'viztype', '')
        is_match_type = viztype in ['matches', 'multi_match']

        key = '' if event.key is None else event.key
        print('key=%r ' % key)
        ctrl_down = key.find('control') == 0
        # Click in match axes
        if event.button == 3:
            return super(MatchInteraction, self).on_click_inside(event, ax)
        if is_match_type and ctrl_down:
            # Ctrl-Click
            print('.. control click')
            return self.sv_view()
        elif viztype in ['warped', 'unwarped']:
            print('clicked at patch')
            ut.print_dict(ph.get_plotdat_dict(ax))
            hs_aid = {
                'aid1': self.qaid,
                'aid2': self.daid,
            }[vh.get_ibsdat(ax, 'aid', None)]
            hs_fx = vh.get_ibsdat(ax, 'fx', None)
            print('hs_fx = %r' % (hs_fx,))
            print('hs_aid = %r' % (hs_aid,))
            if hs_aid is not None and viztype == 'unwarped':
                ishow_chip(ibs, hs_aid, fx=hs_fx, fnum=pt.next_fnum())
            elif hs_aid is not None and viztype == 'warped':
                viz.show_keypoint_gradient_orientations(ibs, hs_aid, hs_fx,
                                                        fnum=pt.next_fnum())
        else:
            return super(MatchInteraction, self).on_click_inside(event, ax)
        self.draw()
Beispiel #2
0
    def show_each_dstncvs_chip(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_each_dstncvs_chip --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_each_dstncvs_chip(dodraw=False)
            >>> pt.show_if_requested()
        """
        dstncvs1, dstncvs2 = scoring.get_kpts_distinctiveness(self.ibs,
                                                              [self.qaid,
                                                               self.daid])
        print('dstncvs1_stats = ' + ut.get_stats_str(dstncvs1))
        print('dstncvs2_stats = ' + ut.get_stats_str(dstncvs2))
        weight_label = 'dstncvs'
        showkw = dict(weight_label=weight_label, ell=False, pts=True)
        viz_chip.show_chip(self.ibs, self.qaid, weights=dstncvs1,
                           fnum=pt.next_fnum(), **showkw)
        viz_chip.show_chip(self.ibs, self.daid, weights=dstncvs2,
                           fnum=pt.next_fnum(), **showkw)
        if dodraw:
            viz.draw()
Beispiel #3
0
    def show_each_dstncvs_chip(self, dodraw=True):
        """
        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-show_each_dstncvs_chip --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> self.show_each_dstncvs_chip(dodraw=False)
            >>> pt.show_if_requested()
        """
        dstncvs1, dstncvs2 = scoring.get_kpts_distinctiveness(
            self.ibs, [self.qaid, self.daid])
        print('dstncvs1_stats = ' + ut.get_stats_str(dstncvs1))
        print('dstncvs2_stats = ' + ut.get_stats_str(dstncvs2))
        weight_label = 'dstncvs'
        showkw = dict(weight_label=weight_label, ell=False, pts=True)
        viz_chip.show_chip(self.ibs,
                           self.qaid,
                           weights=dstncvs1,
                           fnum=pt.next_fnum(),
                           **showkw)
        viz_chip.show_chip(self.ibs,
                           self.daid,
                           weights=dstncvs2,
                           fnum=pt.next_fnum(),
                           **showkw)
        if dodraw:
            viz.draw()
Beispiel #4
0
 def show_each_fgweight_chip(self):
     viz_chip.show_chip(self.ibs, self.qaid, fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     viz_chip.show_chip(self.ibs, self.daid, fnum=pt.next_fnum(),
                        weight_label='fg_weights')
     #self.draw()
     pt.draw()
Beispiel #5
0
 def show_each_probchip(self):
     viz_hough.show_probability_chip(self.ibs,
                                     self.qaid,
                                     fnum=pt.next_fnum())
     viz_hough.show_probability_chip(self.ibs,
                                     self.daid,
                                     fnum=pt.next_fnum())
     viz.draw()
Beispiel #6
0
 def show_each_chip(self):
     viz_chip.show_chip(self.ibs,
                        self.qaid,
                        fnum=pt.next_fnum(),
                        nokpts=True)
     viz_chip.show_chip(self.ibs,
                        self.daid,
                        fnum=pt.next_fnum(),
                        nokpts=True)
     viz.draw()
Beispiel #7
0
 def show_sver_process_to_aid(self, aid2):
     if self.verbose:
         print('ctrl+clicked aid2=%r' % aid2)
     fnum_ = pt.next_fnum()
     ishow_sver(self.ibs, self.cm.qaid, aid2, qreq_=self.qreq_, fnum=fnum_)
     self.draw()
     self.bring_to_front()
Beispiel #8
0
 def show_sver_process_to_aid(self, aid2):
     if self.verbose:
         print('ctrl+clicked aid2=%r' % aid2)
     fnum_ = pt.next_fnum()
     ishow_sver(self.ibs, self.cm.qaid, aid2, qreq_=self.qreq_, fnum=fnum_)
     self.draw()
     self.bring_to_front()
Beispiel #9
0
 def dump_match_img(qres, ibs, aid, qreq_=None, fnum=None, *args, **kwargs):
     import plottool as pt
     import matplotlib as mpl
     # Pop save kwargs from kwargs
     save_keys = ['dpi', 'figsize', 'saveax', 'fpath', 'fpath_strict', 'verbose']
     save_vals = ut.dict_take_pop(kwargs, save_keys, None)
     savekw = dict(zip(save_keys, save_vals))
     fpath = savekw.pop('fpath')
     if fpath is None and 'fpath_strict' not in savekw:
         savekw['usetitle'] = True
     was_interactive = mpl.is_interactive()
     if was_interactive:
         mpl.interactive(False)
     # Make new figure
     if fnum is None:
         fnum = pt.next_fnum()
     #fig = pt.figure(fnum=fnum, doclf=True, docla=True)
     fig = pt.plt.figure(fnum)
     fig.clf()
     # Draw Matches
     ax, xywh1, xywh2 = qres.show_matches(ibs, aid, colorbar_=False, qreq_=qreq_, fnum=fnum, **kwargs)
     if not kwargs.get('notitle', False):
         pt.set_figtitle(qres.make_smaller_title())
     # Save Figure
     # Setting fig=fig might make the dpi and figsize code not work
     img_fpath = pt.save_figure(fpath=fpath, fig=fig, **savekw)
     if was_interactive:
         mpl.interactive(was_interactive)
     pt.plt.close(fig)  # Ensure that this figure will not pop up
     #if False:
     #    ut.startfile(img_fpath)
     return img_fpath
Beispiel #10
0
 def on_click(self, event):
     print('[inter] clicked in expandable interact')
     ax = event.inaxes
     if ih.clicked_inside_axis(event):
         func = pt.get_plotdat(ax, 'plot_func', None)
         if ut.VERBOSE:
             print('func = %r' % (func,))
         if func is not None:
             if ut.VERBOSE:
                 print('calling func = %r' % (func,))
             fnum = pt.next_fnum()
             #pt.figure(fnum=fnum)
             pnum = (1, 1, 1)
             index = pt.get_plotdat(ax, 'expandable_index', None)
             if index is not None:
                 ishow_func = self.ishow_func_list[index]
             else:
                 ishow_func = None
             if ishow_func is not None:
                 inter = ishow_func(fnum=fnum)
             else:
                 if check_if_subinteract(func):
                     inter = func(fnum=fnum)
                     inter.show_page()
                 elif hasattr(func, 'plot'):
                     inter = func
                     inter.start()
                     #func.plot(fnum=self.fnum, pnum=pnum)
                 else:
                     func(fnum=fnum, pnum=pnum)
                 #inter.show_page()
             fig = pt.gcf()
             pt.show_figure(fig)
Beispiel #11
0
def show_hough_image(ibs, gid, species=None, fnum=None, **kwargs):
    if fnum is None:
        fnum = pt.next_fnum()
    title = 'Hough Image: ' + vh.get_image_titles(ibs, gid)
    print(title)

    if species is None:
        species = ibs.get_
        #.cfg.detect_cfg.species_text
    src_gpath_list = ibs.get_image_detectpaths([gid])
    dst_gpath_list = [splitext(gpath)[0] for gpath in src_gpath_list]
    hough_gpath_list = [
        gpath + '_' + species + '_hough.png' for gpath in dst_gpath_list
    ]
    # Detect with hough
    config = {
        'output_gpath_list': hough_gpath_list,
    }
    print('-' * 80)
    print('')
    print('WARNING!!!')
    print('Hough image is not used often and not worth putting into depcache.')
    print('This image is computed as needed and not cached to disk.')
    print('')
    print('-' * 80)
    results_list = list(
        randomforest.detect_gpath_list_with_species(  # NOQA
            ibs, src_gpath_list, species, **config))
    # Get path
    hough_gpath = hough_gpath_list[0]
    img = vt.imread(hough_gpath)
    fig, ax = viz_image2.show_image(img, title=title, fnum=fnum, **kwargs)
    return fig, ax
 def show_normalizers(match, fnum=None, pnum=None, update=True):
     import plottool as pt
     from plottool import plot_helpers as ph
     # hack keys out of namespace
     keys = ['rchip', 'kpts']
     rchip1, kpts1 = ut.dict_take(match.annot1.__dict__, keys)
     rchip2, kpts2 = ut.dict_take(match.annot2.__dict__, keys)
     fs, fm = match.fs, match.fm_norm
     cmap = 'cool'
     draw_lines = True
     if fnum is None:
         fnum = pt.next_fnum()
     pt.figure(fnum=fnum, pnum=pnum)
     #doclf=True, docla=True)
     ax, xywh1, xywh2 = pt.show_chipmatch2(rchip1,
                                           rchip2,
                                           kpts1,
                                           kpts2,
                                           fm=fm,
                                           fs=fs,
                                           fnum=fnum,
                                           cmap=cmap,
                                           draw_lines=draw_lines)
     ph.set_plotdat(ax, 'viztype', 'matches')
     ph.set_plotdat(ax, 'key', match.key)
     title = match.key + '\n num=%d, sum=%.2f' % (len(fm), sum(fs))
     pt.set_title(title)
     if update:
         pt.update()
     return ax, xywh1, xywh2
Beispiel #13
0
 def on_click_inside(self, event, ax):
     import plottool as pt
     viztype = ph.get_plotdat(ax, 'viztype', None)
     print('[ik] viztype=%r' % viztype)
     if viztype is None:
         pass
     elif viztype == 'keypoints':
         kpts = ph.get_plotdat(ax, 'kpts', [])
         if len(kpts) == 0:
             print('...nokpts')
         else:
             print('...nearest')
             x, y = event.xdata, event.ydata
             fx = ut.nearest_point(x, y, kpts)[0]
             self._select_ith_kpt(fx)
     elif viztype == 'warped':
         hs_fx = ph.get_plotdat(ax, 'fx', None)
         if hs_fx is not None:
             kp = self.kpts[hs_fx]  # FIXME
             sift = self.vecs[hs_fx]
             df2.draw_keypoint_gradient_orientations(self.chip, kp,
                                                     sift=sift, mode='vec',
                                                     fnum=pt.next_fnum())
             pt.draw()
     elif viztype.startswith('colorbar'):
         pass
     else:
         print('...unhandled')
     self.draw()
Beispiel #14
0
 def test_featcfg_combo(ibs, aid, alldictcomb, count, nKpts_list,
                        cfgstr_list):
     for dict_ in ut.progiter(alldictcomb, lbl='FeatCFG Combo: '):
         # Set ibs parameters to the current config
         for key_, val_ in six.iteritems(dict_):
             ibs.cfg.feat_cfg[key_] = val_
         cfgstr_ = ibs.cfg.feat_cfg.get_cfgstr()
         if count == 0:
             # On first run just record info
             kpts = ibs.get_annot_kpts(aid)
             nKpts_list.append(len(kpts))
             cfgstr_list.append(cfgstr_)
         if count == 1:
             kpts = ibs.get_annot_kpts(aid)
             # If second run happens display info
             cfgpackstr = utool.packstr(cfgstr_,
                                        textwidth=80,
                                        breakchars=',',
                                        newline_prefix='',
                                        break_words=False,
                                        wordsep=',')
             title_suffix = (' len(kpts) = %r \n' % len(kpts)) + cfgpackstr
             viz.show_chip(ibs,
                           aid,
                           fnum=pt.next_fnum(),
                           title_suffix=title_suffix,
                           darken=.8,
                           ell_linewidth=2,
                           ell_alpha=.6)
Beispiel #15
0
 def dump_match_img(qres, ibs, aid, qreq_=None, fnum=None, *args, **kwargs):
     import plottool as pt
     import matplotlib as mpl
     # Pop save kwargs from kwargs
     save_keys = ['dpi', 'figsize', 'saveax', 'fpath', 'fpath_strict', 'verbose']
     save_vals = ut.dict_take_pop(kwargs, save_keys, None)
     savekw = dict(zip(save_keys, save_vals))
     fpath = savekw.pop('fpath')
     if fpath is None and 'fpath_strict' not in savekw:
         savekw['usetitle'] = True
     was_interactive = mpl.is_interactive()
     if was_interactive:
         mpl.interactive(False)
     # Make new figure
     if fnum is None:
         fnum = pt.next_fnum()
     #fig = pt.figure(fnum=fnum, doclf=True, docla=True)
     fig = pt.plt.figure(fnum)
     fig.clf()
     # Draw Matches
     ax, xywh1, xywh2 = qres.show_matches(ibs, aid, colorbar_=False, qreq_=qreq_, fnum=fnum, **kwargs)
     if not kwargs.get('notitle', False):
         pt.set_figtitle(qres.make_smaller_title())
     # Save Figure
     # Setting fig=fig might make the dpi and figsize code not work
     img_fpath = pt.save_figure(fpath=fpath, fig=fig, **savekw)
     if was_interactive:
         mpl.interactive(was_interactive)
     pt.plt.close(fig)  # Ensure that this figure will not pop up
     #if False:
     #    ut.startfile(img_fpath)
     return img_fpath
Beispiel #16
0
def gridsearch_kpts_coverage_mask():
    """
    testing function

    CommandLine:
        python -m vtool.coverage_kpts --test-gridsearch_kpts_coverage_mask --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.coverage_kpts import *  # NOQA
        >>> import plottool as pt
        >>> gridsearch_kpts_coverage_mask()
        >>> pt.show_if_requested()
    """
    import plottool as pt
    cfgdict_list, cfglbl_list = get_coverage_kpts_gridsearch_configs()
    kpts, chipsize, weights = testdata_coverage('easy1.png')
    imgmask_list = [
        255 *  make_kpts_coverage_mask(kpts, chipsize, weights,
                                       return_patch=False, **cfgdict)
        for cfgdict in ut.ProgressIter(cfgdict_list, lbl='coverage grid')
    ]
    #NORMHACK = True
    #if NORMHACK:
    #    imgmask_list = [
    #        255 * (mask / mask.max()) for mask in imgmask_list
    #    ]
    fnum = pt.next_fnum()
    ut.interact_gridsearch_result_images(
        pt.imshow, cfgdict_list, cfglbl_list,
        imgmask_list, fnum=fnum, figtitle='coverage image', unpack=False,
        max_plots=25)
    pt.iup()
 def on_click_inside(self, event, ax):
     import plottool as pt
     viztype = ph.get_plotdat(ax, 'viztype', None)
     print('[ik] viztype=%r' % viztype)
     if viztype is None:
         pass
     elif viztype == 'keypoints':
         kpts = ph.get_plotdat(ax, 'kpts', [])
         if len(kpts) == 0:
             print('...nokpts')
         else:
             print('...nearest')
             x, y = event.xdata, event.ydata
             fx = ut.nearest_point(x, y, kpts)[0]
             self._select_ith_kpt(fx)
     elif viztype == 'warped':
         hs_fx = ph.get_plotdat(ax, 'fx', None)
         if hs_fx is not None:
             kp = self.kpts[hs_fx]  # FIXME
             sift = self.vecs[hs_fx]
             df2.draw_keypoint_gradient_orientations(self.chip,
                                                     kp,
                                                     sift=sift,
                                                     mode='vec',
                                                     fnum=pt.next_fnum())
             pt.draw()
     elif viztype.startswith('colorbar'):
         pass
     else:
         print('...unhandled')
     self.draw()
Beispiel #18
0
def inspect_pdfs(tn_support, tp_support, score_domain, p_tp_given_score,
                 p_tn_given_score, p_score_given_tp, p_score_given_tn, p_score,
                 with_scores=False):
    import plottool as pt  # NOQA

    fnum = pt.next_fnum()
    nRows = 2 + with_scores
    pnum_ = pt.get_pnum_func(nRows=nRows, nCols=1)
    #pnum_ = pt.get_pnum_func(nRows=3, nCols=1)
    #def next_pnum():
    #    return pnum_(

    def generate_pnum():
        for px in range(nRows):
            yield pnum_(px)

    _pnumiter = generate_pnum().next

    pt.figure(fnum=fnum, pnum=pnum_(0))

    if with_scores:
        plot_support(tn_support, tp_support, fnum=fnum, pnum=_pnumiter())

    plot_prebayes_pdf(score_domain, p_score_given_tn, p_score_given_tp, p_score,
                      cfgstr='', fnum=fnum, pnum=_pnumiter())

    plot_postbayes_pdf(score_domain, p_tn_given_score, p_tp_given_score,
                       cfgstr='', fnum=fnum, pnum=_pnumiter())
Beispiel #19
0
def plot_support(tn_support, tp_support, fnum=None, pnum=(1, 1, 1)):
    r"""
    Args:
        tn_support (ndarray):
        tp_support (ndarray):
        fnum (int):  figure number
        pnum (tuple):  plot number

    CommandLine:
        python -m ibeis.algo.hots.score_normalization --test-plot_support

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.score_normalization import *  # NOQA
        >>> tn_support = '?'
        >>> tp_support = '?'
        >>> fnum = None
        >>> pnum = (1, 1, 1)
        >>> result = plot_support(tn_support, tp_support, fnum, pnum)
        >>> print(result)
    """
    import plottool as pt  # NOQA
    if fnum is None:
        fnum = pt.next_fnum()
    true_color = pt.TRUE_BLUE  # pt.TRUE_GREEN
    false_color = pt.FALSE_RED
    pt.plots.plot_sorted_scores(
        (tn_support, tp_support),
        ('trueneg scores', 'truepos scores'),
        score_colors=(false_color, true_color),
        #logscale=True,
        logscale=False,
        figtitle='sorted nscores',
        fnum=fnum,
        pnum=pnum)
Beispiel #20
0
    def visualize(normalizer, update=True, verbose=True, fnum=None):
        """
        CommandLine:
            python -m ibeis.algo.hots.score_normalization --test-visualize --index 0
            --cmd

        Example:
            >>> # DISABLE_DOCTEST
            >>> import plottool as pt
            >>> from ibeis.algo.hots.score_normalization import *  # NOQA
            >>> #import ibeis
            >>> index = ut.get_argval('--index', type_=int, default=0)
            >>> normalizer = load_precomputed_normalizer(index, with_global=False)
            >>> normalizer.visualize()
            >>> six.exec_(pt.present(), globals(), locals())

        """
        import plottool as pt
        if verbose:
            print(normalizer.get_infostr())
        if normalizer.score_domain is None:
            return
        if fnum is None:
            fnum = pt.next_fnum()
        pt.figure(fnum=fnum, pnum=(2, 1, 1), doclf=True, docla=True)
        normalizer.visualize_probs(fnum=fnum, pnum=(2, 1, 1), update=False)
        normalizer.visualize_support(fnum=fnum, pnum=(2, 1, 2), update=False)
        if update:
            pt.update()
Beispiel #21
0
def show_hough_image(ibs, gid, species=None, fnum=None, **kwargs):
    if fnum is None:
        fnum = pt.next_fnum()
    title = 'Hough Image: ' + vh.get_image_titles(ibs, gid)
    print(title)

    if species is None:
        species = ibs.cfg.detect_cfg.species_text
    src_gpath_list = ibs.get_image_detectpaths([gid])
    dst_gpath_list = [splitext(gpath)[0] for gpath in src_gpath_list]
    hough_gpath_list = [gpath + '_' + species + '_hough.png' for gpath in dst_gpath_list]
    # Detect with hough
    config = {
        'output_gpath_list': hough_gpath_list,
    }
    print('-' * 80)
    print('')
    print('WARNING!!!')
    print('Hough image is not used often and not worth putting into depcache.')
    print('This image is computed as needed and not cached to disk.')
    print('')
    print('-' * 80)
    results_list = list(randomforest.detect_gpath_list_with_species(ibs, src_gpath_list, species, **config))  # NOQA
    # Get path
    hough_gpath = hough_gpath_list[0]
    img = vt.imread(hough_gpath)
    fig, ax = viz_image2.show_image(img, title=title, fnum=fnum, **kwargs)
    return fig, ax
Beispiel #22
0
def show_coverage_map(chip,
                      mask,
                      patch,
                      kpts,
                      fnum=None,
                      ell_alpha=.6,
                      show_mask_kpts=False):
    """ testing function """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    pnum_ = pt.get_pnum_func(nRows=2, nCols=2)
    if patch is not None:
        pt.imshow((patch * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=pnum_(0),
                  title='patch')
        #ut.embed()
        pt.imshow((mask * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=pnum_(1),
                  title='mask')
    else:
        pt.imshow((mask * 255).astype(np.uint8),
                  fnum=fnum,
                  pnum=(2, 1, 1),
                  title='mask')
    if show_mask_kpts:
        pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    pt.imshow(chip, fnum=fnum, pnum=pnum_(2), title='chip')
    pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    masked_chip = (chip * mask[:, :, None]).astype(np.uint8)
    pt.imshow(masked_chip, fnum=fnum, pnum=pnum_(3), title='masked chip')
Beispiel #23
0
    def show_normalizers(match, fnum=None, pnum=None, update=True):
        import plottool as pt
        from plottool import plot_helpers as ph

        # hack keys out of namespace
        keys = ["rchip", "kpts"]
        rchip1, kpts1 = ut.dict_take(match.annot1.__dict__, keys)
        rchip2, kpts2 = ut.dict_take(match.annot2.__dict__, keys)
        fs, fm = match.fs, match.fm_norm
        cmap = "cool"
        draw_lines = True
        if fnum is None:
            fnum = pt.next_fnum()
        pt.figure(fnum=fnum, pnum=pnum)
        # doclf=True, docla=True)
        ax, xywh1, xywh2 = pt.show_chipmatch2(
            rchip1, rchip2, kpts1, kpts2, fm=fm, fs=fs, fnum=fnum, cmap=cmap, draw_lines=draw_lines
        )
        ph.set_plotdat(ax, "viztype", "matches")
        ph.set_plotdat(ax, "key", match.key)
        title = match.key + "\n num=%d, sum=%.2f" % (len(fm), sum(fs))
        pt.set_title(title)
        if update:
            pt.update()
        return ax, xywh1, xywh2
Beispiel #24
0
def show_hist_submaxima(hist_, edges=None, centers=None, maxima_thresh=.8, pnum=(1, 1, 1)):
    r"""
    For C++ to show data

    Args:
        hist_ (?):
        edges (None):
        centers (None):

    CommandLine:
        python -m vtool.histogram --test-show_hist_submaxima --show
        python -m pyhesaff._pyhesaff --test-test_rot_invar --show
        python -m vtool.histogram --test-show_hist_submaxima --dpath figures --save ~/latex/crall-candidacy-2015/figures/show_hist_submaxima.jpg

    Example:
        >>> # DISABLE_DOCTEST
        >>> import plottool as pt
        >>> from vtool.histogram import *  # NOQA
        >>> # build test data
        >>> hist_ = np.array(list(map(float, ut.get_argval('--hist', type_=list, default=[1, 4, 2, 5, 3, 3]))))
        >>> edges = np.array(list(map(float, ut.get_argval('--edges', type_=list, default=[0, 1, 2, 3, 4, 5, 6]))))
        >>> maxima_thresh = ut.get_argval('--maxima_thresh', type_=float, default=.8)
        >>> centers = None
        >>> # execute function
        >>> show_hist_submaxima(hist_, edges, centers, maxima_thresh)
        >>> pt.show_if_requested()
    """
    #print(repr(hist_))
    #print(repr(hist_.shape))
    #print(repr(edges))
    #print(repr(edges.shape))
    #ut.embed()
    import plottool as pt
    #ut.embed()
    if centers is None:
        centers = hist_edges_to_centers(edges)
    bin_colors = pt.get_orientation_color(centers)
    pt.figure(fnum=pt.next_fnum(), pnum=pnum)
    POLAR = False
    if POLAR:
        pt.df2.plt.subplot(*pnum, polar=True, axisbg='#000000')
    pt.draw_hist_subbin_maxima(hist_, centers, bin_colors=bin_colors, maxima_thresh=maxima_thresh)
    #pt.gca().set_rmax(hist_.max() * 1.1)
    #pt.gca().invert_yaxis()
    #pt.gca().invert_xaxis()
    pt.dark_background()
    #if ut.get_argflag('--legend'):
    #    pt.figure(fnum=pt.next_fnum())
    #    centers_ = np.append(centers, centers[0])
    #    r = np.ones(centers_.shape) * .2
    #    ax = pt.df2.plt.subplot(111, polar=True)
    #    pt.plots.colorline(centers_, r, cmap=pt.df2.plt.get_cmap('hsv'), linewidth=10)
    #    #ax.plot(centers_, r, 'm', color=bin_colors, linewidth=100)
    #    ax.set_rmax(.2)
    #    #ax.grid(True)
    #    #ax.set_title("Angle Colors", va='bottom')
    title = ut.get_argval('--title', default='')
    import plottool as pt
    pt.set_figtitle(title)
Beispiel #25
0
 def query_last_feature(self):
     ibs      = self.ibs
     qaid     = self.qaid
     viz.show_nearest_descriptors(ibs, qaid, self.last_fx, pt.next_fnum(),
                                  qreq_=self.qreq_, draw_chip=True)
     fig3 = pt.gcf()
     ih.connect_callback(fig3, 'button_press_event', self.on_click)
     pt.draw()
Beispiel #26
0
 def show_matches_to_aid(self, aid2):
     if self.verbose:
         print('clicked aid2=%r' % aid2)
     fnum_ = pt.next_fnum()
     #if isinstance(self.cm, chip_match.ChipMatch):
     self.cm.ishow_match(self.qreq_, aid2, fnum=fnum_)
     #else:
     #    self.cm.ishow_matches(self.ibs, aid2, qreq_=self.qreq_, fnum=fnum_)
     self.draw()
Beispiel #27
0
 def show_matches_to_aid(self, aid2):
     if self.verbose:
         print('clicked aid2=%r' % aid2)
     fnum_ = pt.next_fnum()
     #if isinstance(self.cm, chip_match.ChipMatch):
     self.cm.ishow_match(self.qreq_, aid2, fnum=fnum_)
     #else:
     #    self.cm.ishow_matches(self.ibs, aid2, qreq_=self.qreq_, fnum=fnum_)
     self.draw()
Beispiel #28
0
def show_ori_image(gori,
                   weights,
                   patch,
                   gradx=None,
                   grady=None,
                   gauss=None,
                   fnum=None):
    """
        python -m pyhesaff._pyhesaff --test-test_rot_invar --show --nocpp
    """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    print('gori.max = %r' % gori.max())
    assert gori.max() <= TAU
    assert gori.min() >= 0
    bgr_ori = pt.color_orimag(gori, weights, False, encoding='bgr')
    print('bgr_ori.max = %r' % bgr_ori.max())

    #ut.embed()

    bgr_ori = (255 * bgr_ori).astype(np.uint8)
    print('bgr_ori.max = %r' % bgr_ori.max())
    #bgr_ori = np.array(bgr_ori, dtype=np.uint8)
    legend = pt.make_ori_legend_img()
    #gorimag_, woff, hoff = vt.stack_images(bgr_ori, legend, vert=False, modifysize=True)
    import vtool as vt
    gorimag_, offsets, sftup = vt.stack_images(bgr_ori,
                                               legend,
                                               vert=False,
                                               modifysize=True,
                                               return_offset=True,
                                               return_sf=True)
    (woff, hoff) = offsets[1]
    if patch is None:
        pt.imshow(gorimag_, fnum=fnum)
    else:
        pt.imshow(gorimag_,
                  fnum=fnum,
                  pnum=(3, 1, 1),
                  title='colored by orientation')
        #pt.imshow(patch, fnum=fnum, pnum=(2, 2, 1))
        #gradx, grady = np.cos(gori + TAU / 4.0), np.sin(gori + TAU / 4.0)
        if gradx is not None and grady is not None:
            if weights is not None:
                gradx *= weights
                grady *= weights
            pt.imshow(np.array(gradx * 255, dtype=np.uint8),
                      fnum=fnum,
                      pnum=(3, 3, 4))
            pt.imshow(np.array(grady * 255, dtype=np.uint8),
                      fnum=fnum,
                      pnum=(3, 3, 5))
            #pt.imshow(bgr_ori, pnum=(2, 2, 4))
            pt.draw_vector_field(gradx, grady, pnum=(3, 3, 6), invert=True)
        pt.imshow(patch, fnum=fnum, pnum=(3, 1, 3))
Beispiel #29
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Beispiel #30
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Beispiel #31
0
def plot_postbayes_pdf(score_domain, p_tn_given_score, p_tp_given_score,
                       cfgstr='', fnum=None, pnum=(1, 1, 1)):
    import plottool as pt  # NOQA
    if fnum is None:
        fnum = pt.next_fnum()
    true_color = pt.TRUE_BLUE  # pt.TRUE_GREEN
    false_color = pt.FALSE_RED

    pt.plots.plot_probabilities(
        (p_tn_given_score, p_tp_given_score),
        ('p(tn | score)', 'p(tp | score)'),
        prob_colors=(false_color, true_color,),
        figtitle='post_bayes pdf score ' + cfgstr,
        xdata=score_domain, fnum=fnum, pnum=pnum)
Beispiel #32
0
    def _on_chip_click(event):
        print('[inter] clicked chip')
        ax, x, y = event.inaxes, event.xdata, event.ydata
        if ih.clicked_outside_axis(event):
            if not ischild:
                print('... out of axis')
                mode_ptr[0] = (mode_ptr[0] + 1) % 3
                _chip_view(**kwargs)
        else:
            if event.button == 3:   # right-click
                import guitool as gt
                #from ibeis.viz.interact import interact_chip
                height = fig.canvas.geometry().height()
                qpoint = gt.newQPoint(event.x, height - event.y)
                refresh_func = partial(_chip_view, **kwargs)

                callback_list = build_annot_context_options(
                    ibs, aid, refresh_func=refresh_func,
                    with_interact_chip=False,
                    config2_=config2_)
                qwin = fig.canvas
                gt.popup_menu(qwin, qpoint, callback_list)
                #interact_chip.show_annot_context_menu(
                #    ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func,
                #    with_interact_chip=False, config2_=config2_)
            else:
                viztype = vh.get_ibsdat(ax, 'viztype')
                print('[ic] viztype=%r' % viztype)
                if viztype == 'chip' and event.key == 'shift':
                    _chip_view(**kwargs)
                    ih.disconnect_callback(fig, 'button_press_event')
                elif viztype == 'chip':
                    kpts = ibs.get_annot_kpts(aid, config2_=config2_)
                    if len(kpts) > 0:
                        fx = vt.nearest_point(
                            x, y, kpts, conflict_mode='next')[0]
                        print('... clicked fx=%r' % fx)
                        _select_fxth_kpt(fx)
                    else:
                        print('... len(kpts) == 0')
                elif viztype in ['warped', 'unwarped']:
                    fx = vh.get_ibsdat(ax, 'fx')
                    if fx is not None and viztype == 'warped':
                        viz.show_keypoint_gradient_orientations(
                            ibs, aid, fx, fnum=pt.next_fnum())
                else:
                    print('...Unknown viztype: %r' % viztype)

        viz.draw()
Beispiel #33
0
def plot_prebayes_pdf(score_domain, p_score_given_tn, p_score_given_tp, p_score,
                      cfgstr='', fnum=None, pnum=(1, 1, 1)):
    import plottool as pt  # NOQA
    if fnum is None:
        fnum = pt.next_fnum()
    true_color = pt.TRUE_BLUE  # pt.TRUE_GREEN
    false_color = pt.FALSE_RED
    unknown_color = pt.UNKNOWN_PURP

    pt.plots.plot_probabilities(
        (p_score_given_tn,  p_score_given_tp, p_score),
        ('p(score | tn)', 'p(score | tp)', 'p(score)'),
        prob_colors=(false_color, true_color, unknown_color),
        figtitle='pre_bayes pdf score',
        xdata=score_domain,
        fnum=fnum,
        pnum=pnum)
 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)
Beispiel #35
0
    def __init__(co_wgt, ibs, gid_list, parent=None, hack=False):
        print('[co_gui] Initializing')
        print('[co_gui] gid_list = %r' % (gid_list, ))

        QtWidgets.QWidget.__init__(co_wgt, parent=parent)

        co_wgt.fnum = pt.next_fnum()

        co_wgt.main_layout = QtWidgets.QVBoxLayout(co_wgt)

        co_wgt.text_layout = gt.newWidget(co_wgt,
                                          orientation=Qt.Vertical,
                                          verticalStretch=10)
        co_wgt.main_layout.addWidget(co_wgt.text_layout)

        co_wgt.control_layout = gt.newWidget(
            co_wgt,
            orientation=Qt.Vertical,
            verticalSizePolicy=QtWidgets.QSizePolicy.MinimumExpanding)
        co_wgt.main_layout.addWidget(co_wgt.control_layout)

        co_wgt.button_layout = gt.newWidget(co_wgt, orientation=Qt.Horizontal)
        co_wgt.control_layout.addWidget(co_wgt.button_layout)

        co_wgt.combo_layout = gt.newWidget(co_wgt, orientation=Qt.Horizontal)
        co_wgt.control_layout.addWidget(co_wgt.combo_layout)

        co_wgt.hack = hack  # hack for edting the time of a single image

        co_wgt.imfig = None
        co_wgt.imax = None

        co_wgt.dtime = None

        co_wgt.ibs = ibs
        co_wgt.gid_list = gid_list
        co_wgt.current_gindex = 0
        co_wgt.offset = 0
        # Set image datetime with first image
        co_wgt.get_image_datetime_()
        co_wgt.add_label()
        co_wgt.add_combo_boxes()
        co_wgt.add_buttons()
        co_wgt.update_ui()
Beispiel #36
0
def test_average_contrast():
    import vtool as vt
    ut.get_valid_test_imgkeys()
    img_fpath_list = [ut.grab_test_imgpath(key) for key in ut.get_valid_test_imgkeys()]
    img_list = [vt.imread(img, grayscale=True) for img in img_fpath_list]
    avecontrast_list = np.array([compute_average_contrast(img) for img in img_list])
    import plottool as pt
    nCols = len(img_list)
    fnum = None
    if fnum is None:
        fnum = pt.next_fnum()
    pt.figure(fnum=fnum, pnum=(2, 1, 1))
    sortx = avecontrast_list.argsort()
    y_list = avecontrast_list[sortx]
    x_list = np.arange(0, nCols) + .5
    pt.plot(x_list, y_list, 'bo-')
    sorted_imgs = ut.take(img_list, sortx)
    for px, img in ut.ProgressIter(enumerate(sorted_imgs, start=1)):
        pt.imshow(img, fnum=fnum, pnum=(2, nCols, nCols + px))
Beispiel #37
0
def show_coverage_map(chip, mask, patch, kpts, fnum=None, ell_alpha=.6,
                      show_mask_kpts=False):
    """ testing function """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    pnum_ = pt.get_pnum_func(nRows=2, nCols=2)
    if patch is not None:
        pt.imshow((patch * 255).astype(np.uint8), fnum=fnum, pnum=pnum_(0), title='patch')
        #ut.embed()
        pt.imshow((mask * 255).astype(np.uint8), fnum=fnum, pnum=pnum_(1), title='mask')
    else:
        pt.imshow((mask * 255).astype(np.uint8), fnum=fnum, pnum=(2, 1, 1), title='mask')
    if show_mask_kpts:
        pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    pt.imshow(chip, fnum=fnum, pnum=pnum_(2), title='chip')
    pt.draw_kpts2(kpts, rect=True, ell_alpha=ell_alpha)
    masked_chip = (chip * mask[:, :, None]).astype(np.uint8)
    pt.imshow(masked_chip, fnum=fnum, pnum=pnum_(3), title='masked chip')
 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 examine(self, aid, event=None):
        print(' examining aid %r against the query result' % aid)
        figtitle = 'Examine a specific image against the query'

        #fnum = 510
        fnum = pt.next_fnum()
        fig = pt.figure(fnum=fnum, pnum=(1, 1, 1), doclf=True, docla=True)
        # can cause freezes should be False
        INTERACT_EXAMINE = False
        if INTERACT_EXAMINE:
            #fig = interact_matches.ishow_matches(self.ibs, self.cm, aid, figtitle=figtitle, fnum=fnum)
            fig = self.cm.ishow_matches(self.ibs, aid, figtitle=figtitle, fnum=fnum)
            print('Finished interact')
            # this is only relevant to matplotlib.__version__ < 1.4.2
            #raise Exception(
            #    'BLACK MAGIC: error intentionally included as a workaround that seems'
            #    'to fix a gui hang on certain computers.')
        else:
            viz_matches.show_matches(self.ibs, self.cm, aid, figtitle=figtitle)
            fig.show()
Beispiel #40
0
def show_ori_image(gori, weights, patch, gradx=None, grady=None, gauss=None, fnum=None):
    """
        python -m pyhesaff._pyhesaff --test-test_rot_invar --show --nocpp
    """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    print('gori.max = %r' % gori.max())
    assert gori.max() <= TAU
    assert gori.min() >= 0
    bgr_ori = pt.color_orimag(gori, weights, False, encoding='bgr')
    print('bgr_ori.max = %r' % bgr_ori.max())

    #ut.embed()

    bgr_ori = (255 * bgr_ori).astype(np.uint8)
    print('bgr_ori.max = %r' % bgr_ori.max())
    #bgr_ori = np.array(bgr_ori, dtype=np.uint8)
    legend = pt.make_ori_legend_img()
    #gorimag_, woff, hoff = vt.stack_images(bgr_ori, legend, vert=False, modifysize=True)
    import vtool as vt
    gorimag_, offsets, sftup = vt.stack_images(bgr_ori, legend, vert=False,
                                               modifysize=True,
                                               return_offset=True,
                                               return_sf=True)
    (woff, hoff) = offsets[1]
    if patch is None:
        pt.imshow(gorimag_, fnum=fnum)
    else:
        pt.imshow(gorimag_, fnum=fnum, pnum=(3, 1, 1), title='colored by orientation')
        #pt.imshow(patch, fnum=fnum, pnum=(2, 2, 1))
        #gradx, grady = np.cos(gori + TAU / 4.0), np.sin(gori + TAU / 4.0)
        if gradx is not None and grady is not None:
            if weights is not None:
                gradx *= weights
                grady *= weights
            pt.imshow(np.array(gradx * 255, dtype=np.uint8), fnum=fnum, pnum=(3, 3, 4))
            pt.imshow(np.array(grady * 255, dtype=np.uint8), fnum=fnum, pnum=(3, 3, 5))
            #pt.imshow(bgr_ori, pnum=(2, 2, 4))
            pt.draw_vector_field(gradx, grady, pnum=(3, 3, 6), invert=True)
        pt.imshow(patch, fnum=fnum, pnum=(3, 1, 3))
Beispiel #41
0
def show_hough_image(ibs, gid, species=None, fnum=None, **kwargs):
    if fnum is None:
        fnum = pt.next_fnum()
    title = 'Hough Image: ' + vh.get_image_titles(ibs, gid)
    print(title)

    if species is None:
        species = ibs.cfg.detect_cfg.species_text
    src_gpath_list = ibs.get_image_detectpaths([gid])
    dst_gpath_list = [splitext(gpath)[0] for gpath in src_gpath_list]
    hough_gpath_list = [gpath + '_' + species + '_hough.png' for gpath in dst_gpath_list]
    # Detect with hough
    config = {
        'output_gpath_list': hough_gpath_list,
    }
    results_list = list(randomforest.detect_gpath_list_with_species(ibs, src_gpath_list, species, **config))  # NOQA
    # Get path
    hough_gpath = hough_gpath_list[0]
    img = gtool.imread(hough_gpath)
    fig, ax = viz_image2.show_image(img, title=title, fnum=fnum, **kwargs)
    return fig, ax
Beispiel #42
0
 def test_featcfg_combo(ibs, aid, alldictcomb, count, nKpts_list, cfgstr_list):
     for dict_ in ut.progiter(alldictcomb, lbl='FeatCFG Combo: '):
         # Set ibs parameters to the current config
         for key_, val_ in six.iteritems(dict_):
             ibs.cfg.feat_cfg[key_] = val_
         cfgstr_ = ibs.cfg.feat_cfg.get_cfgstr()
         if count == 0:
             # On first run just record info
             kpts = ibs.get_annot_kpts(aid)
             nKpts_list.append(len(kpts))
             cfgstr_list.append(cfgstr_)
         if count == 1:
             kpts = ibs.get_annot_kpts(aid)
             # If second run happens display info
             cfgpackstr = utool.packstr(cfgstr_, textwidth=80,
                                           breakchars=',', newline_prefix='',
                                           break_words=False, wordsep=',')
             title_suffix = (' len(kpts) = %r \n' % len(kpts)) + cfgpackstr
             viz.show_chip(ibs, aid, fnum=pt.next_fnum(),
                           title_suffix=title_suffix, darken=.8,
                           ell_linewidth=2, ell_alpha=.6)
Beispiel #43
0
def test_average_contrast():
    import vtool as vt
    ut.get_valid_test_imgkeys()
    img_fpath_list = [
        ut.grab_test_imgpath(key) for key in ut.get_valid_test_imgkeys()
    ]
    img_list = [vt.imread(img, grayscale=True) for img in img_fpath_list]
    avecontrast_list = np.array(
        [compute_average_contrast(img) for img in img_list])
    import plottool as pt
    nCols = len(img_list)
    fnum = None
    if fnum is None:
        fnum = pt.next_fnum()
    pt.figure(fnum=fnum, pnum=(2, 1, 1))
    sortx = avecontrast_list.argsort()
    y_list = avecontrast_list[sortx]
    x_list = np.arange(0, nCols) + .5
    pt.plot(x_list, y_list, 'bo-')
    sorted_imgs = ut.take(img_list, sortx)
    for px, img in ut.ProgressIter(enumerate(sorted_imgs, start=1)):
        pt.imshow(img, fnum=fnum, pnum=(2, nCols, nCols + px))
Beispiel #44
0
    def __init__(co_wgt, ibs, gid_list, parent=None, hack=False):
        print('[co_gui] Initializing')
        print('[co_gui] gid_list = %r' % (gid_list,))

        QtGui.QWidget.__init__(co_wgt, parent=parent)

        co_wgt.fnum = next_fnum()

        co_wgt.main_layout = QtGui.QVBoxLayout(co_wgt)

        co_wgt.text_layout = guitool.newWidget(co_wgt, orientation=Qt.Vertical, verticalStretch=10)
        co_wgt.main_layout.addWidget(co_wgt.text_layout)

        co_wgt.control_layout = guitool.newWidget(co_wgt, orientation=Qt.Vertical, verticalSizePolicy=QtGui.QSizePolicy.MinimumExpanding)
        co_wgt.main_layout.addWidget(co_wgt.control_layout)

        co_wgt.button_layout = guitool.newWidget(co_wgt, orientation=Qt.Horizontal)
        co_wgt.control_layout.addWidget(co_wgt.button_layout)

        co_wgt.combo_layout = guitool.newWidget(co_wgt, orientation=Qt.Horizontal)
        co_wgt.control_layout.addWidget(co_wgt.combo_layout)

        co_wgt.hack = hack  # hack for edting the time of a single image

        co_wgt.imfig = None
        co_wgt.imax = None

        co_wgt.dtime = None

        co_wgt.ibs = ibs
        co_wgt.gid_list = gid_list
        co_wgt.current_gindex = 0
        co_wgt.offset = 0
        # Set image datetime with first image
        co_wgt.get_image_datetime()
        co_wgt.add_label()
        co_wgt.add_combo_boxes()
        co_wgt.add_buttons()
        co_wgt.update_ui()
Beispiel #45
0
    def examine(self, aid, event=None):
        print(' examining aid %r against the query result' % aid)
        figtitle = 'Examine a specific image against the query'

        #fnum = 510
        fnum = pt.next_fnum()
        fig = pt.figure(fnum=fnum, pnum=(1, 1, 1), doclf=True, docla=True)
        # can cause freezes should be False
        INTERACT_EXAMINE = False
        if INTERACT_EXAMINE:
            #fig = interact_matches.ishow_matches(self.ibs, self.cm, aid, figtitle=figtitle, fnum=fnum)
            fig = self.cm.ishow_matches(self.ibs,
                                        aid,
                                        figtitle=figtitle,
                                        fnum=fnum)
            print('Finished interact')
            # this is only relevant to matplotlib.__version__ < 1.4.2
            #raise Exception(
            #    'BLACK MAGIC: error intentionally included as a workaround that seems'
            #    'to fix a gui hang on certain computers.')
        else:
            viz_matches.show_matches(self.ibs, self.cm, aid, figtitle=figtitle)
            fig.show()
Beispiel #46
0
def gridsearch_kpts_coverage_mask():
    """
    testing function

    CommandLine:
        python -m vtool.coverage_kpts --test-gridsearch_kpts_coverage_mask --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.coverage_kpts import *  # NOQA
        >>> import plottool as pt
        >>> gridsearch_kpts_coverage_mask()
        >>> pt.show_if_requested()
    """
    import plottool as pt
    cfgdict_list, cfglbl_list = get_coverage_kpts_gridsearch_configs()
    kpts, chipsize, weights = testdata_coverage('easy1.png')
    imgmask_list = [
        255 * make_kpts_coverage_mask(
            kpts, chipsize, weights, return_patch=False, **cfgdict)
        for cfgdict in ut.ProgressIter(cfgdict_list, lbl='coverage grid')
    ]
    #NORMHACK = True
    #if NORMHACK:
    #    imgmask_list = [
    #        255 * (mask / mask.max()) for mask in imgmask_list
    #    ]
    fnum = pt.next_fnum()
    ut.interact_gridsearch_result_images(pt.imshow,
                                         cfgdict_list,
                                         cfglbl_list,
                                         imgmask_list,
                                         fnum=fnum,
                                         figtitle='coverage image',
                                         unpack=False,
                                         max_plots=25)
    pt.iup()
Beispiel #47
0
def test_score_normalization():
    """

    CommandLine:
        python ibeis/algo/hots/score_normalization.py --test-test_score_normalization

        python dev.py -t custom --cfg codename:vsone_unnorm --db PZ_MTEST --allgt --vf --va
        python dev.py -t custom --cfg codename:vsone_unnorm --db PZ_MTEST --allgt --vf --va --index 0:8:3 --dindex 0:10 --verbose

    Example:
        >>> # DISABLE_DOCTEST
        >>> #from ibeis.algo.hots import score_normalization
        >>> #score_normalization.rrr()
        >>> from ibeis.algo.hots.score_normalization import *   # NOQA
        >>> locals_ = test_score_normalization()
        >>> execstr = ut.execstr_dict(locals_)
        >>> #print(execstr)
        >>> exec(execstr)
        >>> import plottool as pt
        >>> exec(pt.present())

    """
    import ibeis
    import plottool as pt  # NOQA

    # Load IBEIS database
    dbname = 'PZ_MTEST'
    #dbname = 'GZ_ALL'

    ibs = ibeis.opendb(dbname)
    qaid_list = daid_list = ibs.get_valid_aids()

    # Get unnormalized query results
    #cfgdict = dict(codename='nsum_unnorm')
    cfgdict = dict(codename='vsone_unnorm')
    cm_list = ibs.query_chips(qaid_list, daid_list, cfgdict, return_cm=True)

    # Get a training sample
    datatup = get_ibeis_score_training_data(ibs, cm_list)
    (tp_support, tn_support, tp_support_labels, tn_support_labels) = datatup

    # Print raw score statistics
    ut.print_stats(tp_support, lbl='tp_support')
    ut.print_stats(tn_support, lbl='tn_support')

    normkw_list = ut.util_dict.all_dict_combinations(
        {
            'monotonize': [True],  # [True, False],
            #'adjust': [1, 4, 8],
            'adjust': [4, 8],
            #'adjust': [8],
        }
    )

    if len(normkw_list) > 32:
        raise AssertionError('Too many plots to test!')

    fnum = pt.next_fnum()
    true_color = pt.TRUE_BLUE  # pt.TRUE_GREEN
    false_color = pt.FALSE_RED
    unknown_color = pt.UNKNOWN_PURP
    pt.plots.plot_sorted_scores(
        (tn_support, tp_support),
        ('true negative scores', 'true positive scores'),
        score_colors=(false_color, true_color),
        #logscale=True,
        logscale=False,
        figtitle='sorted nscores',
        fnum=fnum)

    for normkw in normkw_list:
        # Learn the appropriate normalization
        #normkw = {}  # dict(gridsize=1024, adjust=8, clip_factor=ut.PHI + 1, return_all=True)
        (score_domain, p_tp_given_score, p_tn_given_score, p_score_given_tp, p_score_given_tn,
         p_score, clip_score) = learn_score_normalization(tp_support, tn_support, return_all=True, **normkw)

        assert clip_score > tn_support.max()

        inspect_pdfs(tn_support, tp_support, score_domain,
                     p_tp_given_score, p_tn_given_score, p_score_given_tp, p_score_given_tn, p_score)

        pt.set_figtitle('ScoreNorm ' + ibs.get_dbname() + ' ' + ut.dict_str(normkw))
    locals_ = locals()
    return locals_
Beispiel #48
0
def viz_netx_chipgraph(ibs, netx_graph, fnum=None, with_images=False, zoom=ZOOM):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        netx_graph (?):
        fnum (int):  figure number(default = None)
        with_images (bool): (default = False)
        zoom (float): (default = 0.4)

    Returns:
        ?: pos

    CommandLine:
        python -m ibeis.viz.viz_graph --exec-viz_netx_chipgraph --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_graph import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb(defaultdb='testdb1')
        >>> nid_list = ibs.get_valid_nids()[0:5]
        >>> fnum = None
        >>> with_images = True
        >>> zoom = 0.4
        >>> #pos = viz_netx_chipgraph(ibs, netx_graph, fnum, with_images, zoom)
        >>> make_name_graph_interaction(ibs, None, ibs.get_valid_aids()[0:1])
        >>> #make_name_graph_interaction(ibs, nid_list)
        >>> ut.show_if_requested()
    """
    if fnum is None:
        fnum = pt.next_fnum()

    #zoom = .8
    print('[viz_graph] drawing chip graph')
    pt.figure(fnum=fnum, pnum=(1, 1, 1))
    ax = pt.gca()
    #pos = netx.spring_layout(graph)

    aid_list = netx_graph.nodes()

    IMPLICIT_LAYOUT = len(set(ibs.get_annot_nids(aid_list))) != 1
    # FIXME
    print('zoom = %r' % (zoom,))

    if IMPLICIT_LAYOUT:
        # HACK:
        # Use name edge to make pos (very bad)
        aids1, aids2 = get_name_rowid_edges_from_aids(ibs, aid_list)
        netx_graph_hack = make_netx_graph_from_aidpairs(ibs, aids1, aids2, unique_aids=aid_list)
        pos = netx.graphviz_layout(netx_graph_hack)
    else:
        pos = netx.graphviz_layout(netx_graph)

    #pos = netx.fruchterman_reingold_layout(netx_graph)
    #pos = netx.spring_layout(netx_graph)
    netx.draw(netx_graph, pos=pos, ax=ax)

    with_nid_edges = True
    if with_nid_edges:
        import matplotlib as mpl
        import scipy.sparse as spsparse

        aids1, aids2 = get_name_rowid_edges_from_aids(ibs, aid_list)
        edge_pts1 = np.array(ut.dict_take(pos, aids1), dtype=np.int32)
        edge_pts2 = np.array(ut.dict_take(pos, aids2), dtype=np.int32)

        if len(edge_pts1) == 0:
            edge_pts1 = edge_pts1[:, None]

        if len(edge_pts2) == 0:
            edge_pts2 = edge_pts2[:, None]

        I = np.array(aids1)
        J = np.array(aids2)
        if len(aid_list) > 0:
            N = max(aid_list) + 1
        else:
            N = 1
        forced_edge_idxs = ut.dict_take(dict(zip(zip(I, J), range(len(I)))), netx_graph.edges())
        data = vt.L2(edge_pts1, edge_pts2)
        if len(forced_edge_idxs) > 0:
            data[forced_edge_idxs] = 0.00001

        graph = spsparse.coo_matrix((data, (I, J)), shape=(N, N))

        def extract_connected_compoments(graph):
            import scipy.sparse as spsparse
            import utool as ut
            # I think this is how extraction is done?
            # only returns edge info
            # so singletons are not represented
            shape = graph.shape
            csr_graph = graph.tocsr()
            num_components, labels = spsparse.csgraph.connected_components(csr_graph)
            unique_labels = np.unique(labels)
            group_flags_list = [labels == groupid for groupid in unique_labels]
            subgraph_list = []
            for label, group_flags in zip(unique_labels, group_flags_list):
                num_members = group_flags.sum()
                ixs = list(range(num_members))
                if num_members == 0:
                    continue
                group_rowix, group_cols = csr_graph[group_flags, :].nonzero()
                if len(group_cols) == 0:
                    continue
                ix2_row = dict(zip(ixs, np.nonzero(group_flags)[0]))
                group_rows = ut.dict_take(ix2_row, group_rowix)
                component = (group_rows, group_cols.tolist())
                data = csr_graph[component].tolist()[0]
                subgraph = spsparse.coo_matrix((data, component), shape=shape)
                subgraph_list.append(subgraph)
            #assert len(compoment_list) == num_components, 'bad impl'
            return subgraph_list
        subgraph_list = extract_connected_compoments(graph)

        spantree_aids1_ = []
        spantree_aids2_ = []

        for subgraph in subgraph_list:
            subgraph_spantree = spsparse.csgraph.minimum_spanning_tree(subgraph)
            min_aids1_, min_aids2_ = subgraph_spantree.nonzero()
            spantree_aids1_.extend(min_aids1_)
            spantree_aids2_.extend(min_aids2_)

        edge_pts1_ = np.array(ut.dict_take(pos, spantree_aids1_))
        edge_pts2_ = np.array(ut.dict_take(pos, spantree_aids2_))

        segments = list(zip(edge_pts1_, edge_pts2_))
        #pt.distinct_colors
        color_list = pt.DARK_ORANGE
        #color_list = pt.BLACK
        line_group = mpl.collections.LineCollection(segments, color=color_list, alpha=.3, lw=4)
        ax.add_collection(line_group)

    if with_images:
        import cv2
        pos_list = ut.dict_take(pos, aid_list)
        img_list = ibs.get_annot_chips(aid_list)
        img_list = [vt.resize_thumb(img, (220, 220)) for img in img_list]
        img_list = [cv2.cvtColor(img, cv2.COLOR_BGR2RGB) for img in img_list]
        artist_list = netx_draw_images_at_positions(img_list, pos_list, zoom=zoom)
        for artist, aid in zip(artist_list, aid_list):
            pt.set_plotdat(artist, 'aid', aid)
    return pos
Beispiel #49
0
def devfunc(ibs, qaid_list):
    """ Function for developing something """
    print('[dev] devfunc')
    import ibeis  # NOQA
    from ibeis.algo import Config  # NOQA
    #from ibeis.algo.Config import *  # NOQA
    feat_cfg = Config.FeatureConfig()
    #feat_cfg.printme3()
    print('\ncfgstr..')
    print(feat_cfg.get_cfgstr())
    print(utool.dict_str(feat_cfg.get_hesaff_params()))
    from ibeis import viz
    aid = 1
    ibs.cfg.feat_cfg.threshold = 16.0 / 3.0
    kpts = ibs.get_annot_kpts(aid)
    print('len(kpts) = %r' % len(kpts))
    from ibeis.expt import experiment_configs
    #varyparams_list = [
    #    #{
    #    #    'threshold': [16.0 / 3.0, 32.0 / 3.0],  # 8.0  / 3.0
    #    #    'numberOfScales': [3, 2, 1],
    #    #    'maxIterations': [16, 32],
    #    #    'convergenceThreshold': [.05, .1],
    #    #    'initialSigma': [1.6, 1.2],
    #    #},
    #    {
    #        #'threshold': [16.0 / 3.0, 32.0 / 3.0],  # 8.0  / 3.0
    #        'numberOfScales': [1],
    #        #'maxIterations': [16, 32],
    #        #'convergenceThreshold': [.05, .1],
    #        #'initialSigma': [6.0, 3.0, 2.0, 1.6, 1.2, 1.1],
    #        'initialSigma': [3.2, 1.6, 0.8],
    #        'edgeEigenValueRatio': [10, 5, 3],
    #    },
    #]
    varyparams_list = [experiment_configs.featparams]

    # low threshold = more keypoints
    # low initialSigma = more keypoints

    nKpts_list = []
    cfgstr_list = []

    alldictcomb = utool.flatten([
        utool.util_dict.all_dict_combinations(varyparams)
        for varyparams in featparams_list
    ])
    NUM_PASSES = 1 if not utool.get_argflag('--show') else 2
    for count in range(NUM_PASSES):
        for aid in qaid_list:
            #for dict_ in utool.progiter(alldictcomb, lbl='feature param comb: ', total=len(alldictcomb)):
            for dict_ in alldictcomb:
                for key_, val_ in six.iteritems(dict_):
                    ibs.cfg.feat_cfg[key_] = val_
                cfgstr_ = ibs.cfg.feat_cfg.get_cfgstr()
                cfgstr = utool.packstr(cfgstr_,
                                       textwidth=80,
                                       breakchars=',',
                                       newline_prefix='',
                                       break_words=False,
                                       wordsep=',')
                if count == 0:
                    kpts = ibs.get_annot_kpts(aid)
                    #print('___________')
                    #print('len(kpts) = %r' % len(kpts))
                    #print(cfgstr)
                    nKpts_list.append(len(kpts))
                    cfgstr_list.append(cfgstr_)
                if count == 1:
                    title_suffix = (' len(kpts) = %r \n' % len(kpts)) + cfgstr
                    viz.show_chip(ibs,
                                  aid,
                                  fnum=pt.next_fnum(),
                                  title_suffix=title_suffix,
                                  darken=.4,
                                  ell_linewidth=2,
                                  ell_alpha=.8)

        if count == 0:
            nKpts_list = np.array(nKpts_list)
            cfgstr_list = np.array(cfgstr_list)
            print(get_sortbystr(cfgstr_list, nKpts_list, 'cfg', 'nKpts'))
    pt.present()
    locals_ = locals()
    return locals_
Beispiel #50
0
def devfunc(ibs, qaid_list):
    """ Function for developing something """
    print('[dev] devfunc')
    import ibeis  # NOQA
    from ibeis.algo import Config  # NOQA
    #from ibeis.algo.Config import *  # NOQA
    feat_cfg = Config.FeatureConfig()
    #feat_cfg.printme3()
    print('\ncfgstr..')
    print(feat_cfg.get_cfgstr())
    print(utool.dict_str(feat_cfg.get_hesaff_params()))
    from ibeis import viz
    aid = 1
    ibs.cfg.feat_cfg.threshold = 16.0 / 3.0
    kpts = ibs.get_annot_kpts(aid)
    print('len(kpts) = %r' % len(kpts))
    from ibeis.expt import experiment_configs
    #varyparams_list = [
    #    #{
    #    #    'threshold': [16.0 / 3.0, 32.0 / 3.0],  # 8.0  / 3.0
    #    #    'numberOfScales': [3, 2, 1],
    #    #    'maxIterations': [16, 32],
    #    #    'convergenceThreshold': [.05, .1],
    #    #    'initialSigma': [1.6, 1.2],
    #    #},
    #    {
    #        #'threshold': [16.0 / 3.0, 32.0 / 3.0],  # 8.0  / 3.0
    #        'numberOfScales': [1],
    #        #'maxIterations': [16, 32],
    #        #'convergenceThreshold': [.05, .1],
    #        #'initialSigma': [6.0, 3.0, 2.0, 1.6, 1.2, 1.1],
    #        'initialSigma': [3.2, 1.6, 0.8],
    #        'edgeEigenValueRatio': [10, 5, 3],
    #    },
    #]
    varyparams_list = [experiment_configs.featparams]

    # low threshold = more keypoints
    # low initialSigma = more keypoints

    nKpts_list = []
    cfgstr_list = []

    alldictcomb = utool.flatten([utool.util_dict.all_dict_combinations(varyparams) for varyparams in featparams_list])
    NUM_PASSES = 1 if not utool.get_argflag('--show') else 2
    for count in range(NUM_PASSES):
        for aid in qaid_list:
            #for dict_ in utool.progiter(alldictcomb, lbl='feature param comb: ', total=len(alldictcomb)):
            for dict_ in alldictcomb:
                for key_, val_ in six.iteritems(dict_):
                    ibs.cfg.feat_cfg[key_] = val_
                cfgstr_ = ibs.cfg.feat_cfg.get_cfgstr()
                cfgstr = utool.packstr(cfgstr_, textwidth=80,
                                        breakchars=',', newline_prefix='', break_words=False, wordsep=',')
                if count == 0:
                    kpts = ibs.get_annot_kpts(aid)
                    #print('___________')
                    #print('len(kpts) = %r' % len(kpts))
                    #print(cfgstr)
                    nKpts_list.append(len(kpts))
                    cfgstr_list.append(cfgstr_)
                if count == 1:
                    title_suffix = (' len(kpts) = %r \n' % len(kpts)) + cfgstr
                    viz.show_chip(ibs, aid, fnum=pt.next_fnum(),
                                   title_suffix=title_suffix, darken=.4,
                                   ell_linewidth=2, ell_alpha=.8)

        if count == 0:
            nKpts_list = np.array(nKpts_list)
            cfgstr_list = np.array(cfgstr_list)
            print(get_sortbystr(cfgstr_list, nKpts_list, 'cfg', 'nKpts'))
    pt.present()
    locals_ = locals()
    return locals_
Beispiel #51
0
def ishow_name(ibs,
               nid,
               sel_aids=[],
               select_aid_callback=None,
               fnum=5,
               dodraw=True,
               **kwargs):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

    CommandLine:
        python -m ibeis.viz.interact.interact_name --test-ishow_name --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_name import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> nid = ut.get_argval('--nid', int, default=1)
        >>> sel_aids = []
        >>> select_aid_callback = None
        >>> fnum = 5
        >>> dodraw = ut.show_was_requested()
        >>> # execute function
        >>> result = ishow_name(ibs, nid, sel_aids, select_aid_callback, fnum, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    if fnum is None:
        fnum = pt.next_fnum()
    fig = ih.begin_interaction('name', fnum)

    def _on_name_click(event):
        ax = event.inaxes
        if ih.clicked_inside_axis(event):
            viztype = vh.get_ibsdat(ax, 'viztype')
            if viztype == 'chip':
                aid = vh.get_ibsdat(ax, 'aid')
                print('... aid=%r' % aid)
                if event.button == 3:  # right-click
                    import guitool
                    from ibeis.viz.interact import interact_chip
                    height = fig.canvas.geometry().height()
                    qpoint = guitool.newQPoint(event.x, height - event.y)
                    refresh_func = functools.partial(viz.show_name,
                                                     ibs,
                                                     nid,
                                                     fnum=fnum,
                                                     sel_aids=sel_aids)
                    interact_chip.show_annot_context_menu(
                        ibs,
                        aid,
                        fig.canvas,
                        qpoint,
                        refresh_func=refresh_func,
                        with_interact_name=False)
                else:
                    viz.show_name(ibs,
                                  nid,
                                  fnum=fnum,
                                  sel_aids=[aid],
                                  in_image=True)
                    if select_aid_callback is not None:
                        select_aid_callback(aid)
        viz.draw()

    viz.show_name(ibs, nid, fnum=fnum, sel_aids=sel_aids, in_image=True)
    if dodraw:
        viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_name_click)
    pass
Beispiel #52
0
def run_devcmds(ibs, qaid_list, daid_list, acfg=None):
    """
    This function runs tests passed in with the -t flag
    """
    print('\n')
    #print('[dev] run_devcmds')
    print('==========================')
    print('[DEV] RUN EXPERIMENTS %s' % ibs.get_dbname())
    print('==========================')
    input_test_list = params.args.tests[:]
    print('input_test_list = %s' % (ut.list_str(input_test_list),))
    # fnum = 1

    valid_test_list = []  # build list for printing in case of failure
    valid_test_helpstr_list = []  # for printing

    def mark_test_handled(testname):
        input_test_list.remove(testname)

    def intest(*args, **kwargs):
        helpstr = kwargs.get('help', '')
        valid_test_helpstr_list.append('   -t ' + ', '.join(args) + helpstr)
        for testname in args:
            valid_test_list.append(testname)
            ret = testname in input_test_list
            ret2 = testname in params.unknown  # Let unparsed args count towards tests
            if ret or ret2:
                if ret:
                    mark_test_handled(testname)
                else:
                    ret = ret2
                print('\n+===================')
                print(' [dev] running testname = %s' % (args,))
                print('+-------------------\n')
                return ret
        return False

    valid_test_helpstr_list.append('    # --- Simple Tests ---')

    # Explicit (simple) test functions
    if intest('export'):
        export(ibs)
    if intest('dbinfo'):
        dbinfo.get_dbinfo(ibs)
    if intest('headers', 'schema'):
        ibs.db.print_schema()
    if intest('info'):
        print(ibs.get_infostr())
    if intest('printcfg'):
        printcfg(ibs)
    if intest('tables'):
        ibs.print_tables()
    if intest('imgtbl'):
        ibs.print_image_table()

    valid_test_helpstr_list.append('    # --- Decor Tests ---')

    locals_ = locals()

    # Implicit (decorated) test functions
    for (func_aliases, func) in DEVCMD_FUNCTIONS:
        if intest(*func_aliases):
            funcname = get_funcname(func)
            #with utool.Indenter('[dev.' + funcname + ']'):
            with utool.Timer(funcname):
                #print('[dev] qid_list=%r' % (qaid_list,))
                # FIXME: , daid_list
                if len(ut.get_func_argspec(func).args) == 0:
                    ret = func()
                else:
                    ret = func(ibs, qaid_list, daid_list)
                # Add variables returned by the function to the
                # "local scope" (the exec scop)
                if hasattr(ret, 'items'):
                    for key, val in ret.items():
                        if utool.is_valid_varname(key):
                            locals_[key] = val

    valid_test_helpstr_list.append('    # --- Config Tests ---')

    # ------
    # RUNS EXPERIMENT HARNESS OVER VALID TESTNAMES SPECIFIED WITH -t
    # ------

    # Config driven test functions
    # Allow any testcfg to be in tests like: vsone_1 or vsmany_3
    test_cfg_name_list = []
    for test_cfg_name in experiment_configs.TEST_NAMES:
        if intest(test_cfg_name):
            test_cfg_name_list.append(test_cfg_name)
    # Hack to allow for very customized harness tests
    for testname in input_test_list[:]:
        if testname.startswith('custom:'):
            test_cfg_name_list.append(testname)
            mark_test_handled(testname)
    if len(test_cfg_name_list):
        fnum = pt.next_fnum()
        # Run Experiments
        # backwards compatibility yo
        acfgstr_name_list = {'OVERRIDE_HACK': (qaid_list, daid_list)}
        assert False, 'This way of running tests no longer works. It may be fixed in the future'
        #acfg
        harness.test_configurations(ibs, acfgstr_name_list, test_cfg_name_list)

    valid_test_helpstr_list.append('    # --- Help ---')

    if intest('help'):
        print('valid tests are:')
        print('\n'.join(valid_test_helpstr_list))
        return locals_

    if len(input_test_list) > 0:
        print('valid tests are: \n')
        print('\n'.join(valid_test_list))
        raise Exception('Unknown tests: %r ' % input_test_list)
    return locals_
Beispiel #53
0
    def __init__(self,
                 ibs,
                 cm,
                 aid2=None,
                 fnum=None,
                 figtitle='Match Interaction',
                 same_fig=True,
                 qreq_=None,
                 **kwargs):
        self.qres = cm

        self.ibs = ibs
        self.cm = cm
        self.qreq_ = qreq_
        self.fnum = pt.ensure_fnum(fnum)
        # Unpack Args
        if aid2 is None:
            index = 0
            # FIXME: no sortself
            cm.sortself()
            self.rank = index
        else:
            index = cm.daid2_idx.get(aid2, None)
            # TODO: rank?
            self.rank = None
        if index is not None:
            self.qaid = self.cm.qaid
            self.daid = self.cm.daid_list[index]
            self.fm = self.cm.fm_list[index]
            self.fk = self.cm.fk_list[index]
            self.fsv = self.cm.fsv_list[index]
            if self.cm.fs_list is None:
                fs_list = self.cm.get_fsv_prod_list()
            else:
                fs_list = self.cm.fs_list
            self.fs = None if fs_list is None else fs_list[index]
            self.score = None if self.cm.score_list is None else self.cm.score_list[
                index]
            self.H1 = None if self.cm.H_list is None else cm.H_list[index]
        else:
            self.qaid = self.cm.qaid
            self.daid = aid2
            self.fm = np.empty((0, 2), dtype=hstypes.FM_DTYPE)
            self.fk = np.empty(0, dtype=hstypes.FK_DTYPE)
            self.fsv = np.empty((0, 2), dtype=hstypes.FS_DTYPE)
            self.fs = np.empty(0, dtype=hstypes.FS_DTYPE)
            self.score = None
            self.H1 = None

        # Read properties
        self.query_config2_ = (None if self.qreq_ is None else
                               self.qreq_.get_external_query_config2())
        self.data_config2_ = (None if self.qreq_ is None else
                              self.qreq_.get_external_data_config2())
        self.rchip1 = vh.get_chips(ibs, [self.qaid],
                                   config2_=self.query_config2_)[0]
        self.rchip2 = vh.get_chips(ibs, [self.daid],
                                   config2_=self.data_config2_)[0]
        # Begin Interaction
        # call doclf docla and make figure
        self.fig = ih.begin_interaction('matches', self.fnum)
        self.xywh2_ptr = [None]
        self.mode = kwargs.pop('mode', 0)
        # New state vars
        self.same_fig = same_fig
        self.use_homog = False
        self.vert = kwargs.pop('vert', None)
        self.mx = kwargs.pop('mx', None)
        self.last_fx = 0
        self.fnum2 = pt.next_fnum()
        self.figtitle = figtitle
        self.kwargs = kwargs

        abstract_interaction.register_interaction(self)
        ut.inject_func_as_method(self,
                                 AbstractInteraction.append_button.im_func)
        ut.inject_func_as_method(self,
                                 AbstractInteraction.show_popup_menu.im_func)
        self.scope = []

        if not kwargs.get('nobegin', False):
            dodraw = kwargs.get('dodraw', True)
            self.begin(dodraw=dodraw)
Beispiel #54
0
def myquery():
    r"""

    BUG::
        THERE IS A BUG SOMEWHERE: HOW IS THIS POSSIBLE?
        if everything is weightd ) how di the true positive even get a score
        while the true negative did not
        qres_copy.filtkey_list = ['ratio', 'fg', 'homogerr', 'distinctiveness']
        CORRECT STATS
        {
            'max'  : [0.832, 0.968, 0.604, 0.000],
            'min'  : [0.376, 0.524, 0.000, 0.000],
            'mean' : [0.561, 0.924, 0.217, 0.000],
            'std'  : [0.114, 0.072, 0.205, 0.000],
            'nMin' : [1, 1, 1, 51],
            'nMax' : [1, 1, 1, 1],
            'shape': (52, 4),
        }
        INCORRECT STATS
        {
            'max'  : [0.759, 0.963, 0.264, 0.000],
            'min'  : [0.379, 0.823, 0.000, 0.000],
            'mean' : [0.506, 0.915, 0.056, 0.000],
            'std'  : [0.125, 0.039, 0.078, 0.000],
            'nMin' : [1, 1, 1, 24],
            'nMax' : [1, 1, 1, 1],
            'shape': (26, 4),
        #   score_diff,  tp_score,  tn_score,       p,   K,  dcvs_clip_max,  fg_power,  homogerr_power
             0.494,     0.494,     0.000,  73.000,   2,          0.500,     0.100,          10.000

    see how seperability changes as we very things

    CommandLine:
        python -m ibeis.algo.hots.devcases --test-myquery
        python -m ibeis.algo.hots.devcases --test-myquery --show --index 0
        python -m ibeis.algo.hots.devcases --test-myquery --show --index 1
        python -m ibeis.algo.hots.devcases --test-myquery --show --index 2

    References:
        http://en.wikipedia.org/wiki/Pareto_distribution <- look into

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.all_imports import *  # NOQA
        >>> from ibeis.algo.hots.devcases import *  # NOQA
        >>> ut.dev_ipython_copypaster(myquery) if ut.inIPython() else myquery()
        >>> pt.show_if_requested()
    """
    from ibeis.algo.hots import special_query  # NOQA
    from ibeis.algo.hots import distinctiveness_normalizer  # NOQA
    from ibeis import viz  # NOQA
    import plottool as pt
    index = ut.get_argval('--index', int, 0)
    ibs, aid1, aid2, tn_aid = testdata_my_exmaples(index)
    qaids = [aid1]
    daids = [aid2] + [tn_aid]
    qvuuid = ibs.get_annot_visual_uuids(aid1)

    cfgdict_vsone = dict(
        sv_on=True,
        #sv_on=False,
        #codename='vsone_unnorm_dist_ratio_extern_distinctiveness',
        codename='vsone_unnorm_ratio_extern_distinctiveness',
        sver_output_weighting=True,
    )

    use_cache = False
    save_qcache = False

    qres_list, qreq_ = ibs.query_chips(qaids,
                                       daids,
                                       cfgdict=cfgdict_vsone,
                                       return_request=True,
                                       use_cache=use_cache,
                                       save_qcache=save_qcache,
                                       verbose=True)

    qreq_.load_distinctiveness_normalizer()
    qres = qres_list[0]
    top_aids = qres.get_top_aids()  # NOQA
    qres_orig = qres  # NOQA

    def test_config(qreq_, qres_orig, cfgdict):
        """ function to grid search over """
        qres_copy = copy.deepcopy(qres_orig)
        qreq_vsone_ = qreq_
        qres_vsone = qres_copy
        filtkey = hstypes.FiltKeys.DISTINCTIVENESS
        newfsv_list, newscore_aids = special_query.get_extern_distinctiveness(
            qreq_, qres_copy, **cfgdict)
        special_query.apply_new_qres_filter_scores(qreq_vsone_, qres_vsone,
                                                   newfsv_list, newscore_aids,
                                                   filtkey)
        tp_score = qres_copy.aid2_score[aid2]
        tn_score = qres_copy.aid2_score[tn_aid]
        return qres_copy, tp_score, tn_score

    #[.01, .1, .2, .5, .6, .7, .8, .9, 1.0]),
    #FiltKeys = hstypes.FiltKeys
    # FIXME: Use other way of doing gridsearch
    grid_basis = distinctiveness_normalizer.DCVS_DEFAULT.get_grid_basis()
    gridsearch = ut.GridSearch(grid_basis, label='qvuuid=%r' % (qvuuid, ))
    print('Begin Grid Search')
    for cfgdict in ut.ProgressIter(gridsearch, lbl='GridSearch'):
        qres_copy, tp_score, tn_score = test_config(qreq_, qres_orig, cfgdict)
        gridsearch.append_result(tp_score, tn_score)
    print('Finish Grid Search')

    # Get best result
    best_cfgdict = gridsearch.get_rank_cfgdict()
    qres_copy, tp_score, tn_score = test_config(qreq_, qres_orig, best_cfgdict)

    # Examine closely what you can do with scores
    if False:
        qres_copy = copy.deepcopy(qres_orig)
        qreq_vsone_ = qreq_
        filtkey = hstypes.FiltKeys.DISTINCTIVENESS
        newfsv_list, newscore_aids = special_query.get_extern_distinctiveness(
            qreq_, qres_copy, **cfgdict)
        ut.embed()

        def make_cm_very_old_tuple(qres_copy):
            assert ut.listfind(qres_copy.filtkey_list, filtkey) is None
            weight_filters = hstypes.WEIGHT_FILTERS
            weight_filtxs, nonweight_filtxs = special_query.index_partition(
                qres_copy.filtkey_list, weight_filters)

            aid2_fsv = {}
            aid2_fs = {}
            aid2_score = {}

            for new_fsv_vsone, daid in zip(newfsv_list, newscore_aids):
                pass
                break
                #scorex_vsone  = ut.listfind(qres_copy.filtkey_list, filtkey)
                #if scorex_vsone is None:
                # TODO: add spatial verification as a filter score
                # augment the vsone scores
                # TODO: paramaterize
                weighted_ave_score = True
                if weighted_ave_score:
                    # weighted average scoring
                    new_fs_vsone = special_query.weighted_average_scoring(
                        new_fsv_vsone, weight_filtxs, nonweight_filtxs)
                else:
                    # product scoring
                    new_fs_vsone = special_query.product_scoring(new_fsv_vsone)
                new_score_vsone = new_fs_vsone.sum()
                aid2_fsv[daid] = new_fsv_vsone
                aid2_fs[daid] = new_fs_vsone
                aid2_score[daid] = new_score_vsone
            return aid2_fsv, aid2_fs, aid2_score

        # Look at plot of query products
        for new_fsv_vsone, daid in zip(newfsv_list, newscore_aids):
            new_fs_vsone = special_query.product_scoring(new_fsv_vsone)
            scores_list = np.array(new_fs_vsone)[:, None].T
            pt.plot_sorted_scores(scores_list,
                                  logscale=False,
                                  figtitle=str(daid))
        pt.iup()
        special_query.apply_new_qres_filter_scores(qreq_vsone_, qres_copy,
                                                   newfsv_list, newscore_aids,
                                                   filtkey)

    # PRINT INFO
    import functools
    #ut.rrrr()
    get_stats_str = functools.partial(ut.get_stats_str,
                                      axis=0,
                                      newlines=True,
                                      precision=3)
    tp_stats_str = ut.align(get_stats_str(qres_copy.aid2_fsv[aid2]), ':')
    tn_stats_str = ut.align(get_stats_str(qres_copy.aid2_fsv[tn_aid]), ':')
    info_str_list = []
    info_str_list.append('qres_copy.filtkey_list = %r' %
                         (qres_copy.filtkey_list, ))
    info_str_list.append('CORRECT STATS')
    info_str_list.append(tp_stats_str)
    info_str_list.append('INCORRECT STATS')
    info_str_list.append(tn_stats_str)
    info_str = '\n'.join(info_str_list)
    print(info_str)

    # SHOW BEST RESULT
    #qres_copy.ishow_top(ibs, fnum=pt.next_fnum())
    #qres_orig.ishow_top(ibs, fnum=pt.next_fnum())

    # Text Informatio
    param_lbl = 'dcvs_power'
    param_stats_str = gridsearch.get_dimension_stats_str(param_lbl)
    print(param_stats_str)

    csvtext = gridsearch.get_csv_results(10)
    print(csvtext)

    # Paramter visuzliation
    fnum = pt.next_fnum()
    # plot paramter influence
    param_label_list = gridsearch.get_param_lbls()
    pnum_ = pt.get_pnum_func(2, len(param_label_list))
    for px, param_label in enumerate(param_label_list):
        gridsearch.plot_dimension(param_label, fnum=fnum, pnum=pnum_(px))
    # plot match figure
    pnum2_ = pt.get_pnum_func(2, 2)
    qres_copy.show_matches(ibs, aid2, fnum=fnum, pnum=pnum2_(2))
    qres_copy.show_matches(ibs, tn_aid, fnum=fnum, pnum=pnum2_(3))
    # Add figure labels
    figtitle = 'Effect of parameters on vsone separation for a single case'
    subtitle = 'qvuuid = %r' % (qvuuid)
    figtitle += '\n' + subtitle
    pt.set_figtitle(figtitle)
    # Save Figure
    #fig_fpath = pt.save_figure(usetitle=True)
    #print(fig_fpath)
    # Write CSV Results
    #csv_fpath = fig_fpath + '.csv.txt'
    #ut.write_to(csv_fpath, csvtext)

    #qres_copy.ishow_top(ibs)
    #from matplotlib import pyplot as plt
    #plt.show()
    #print(ut.list_str()))
    # TODO: plot max variation dims
    #import plottool as pt
    #pt.plot(p_list, diff_list)
    """
Beispiel #55
0
def ishow_name(ibs, nid, sel_aids=[], select_aid_callback=None, fnum=5, dodraw=True, **kwargs):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

    CommandLine:
        python -m ibeis.viz.interact.interact_name --test-ishow_name --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.interact.interact_name import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> nid = ut.get_argval('--nid', int, default=1)
        >>> sel_aids = []
        >>> select_aid_callback = None
        >>> fnum = 5
        >>> dodraw = ut.show_was_requested()
        >>> # execute function
        >>> result = ishow_name(ibs, nid, sel_aids, select_aid_callback, fnum, dodraw)
        >>> # verify results
        >>> pt.show_if_requested()
        >>> print(result)
    """
    if fnum is None:
        fnum = pt.next_fnum()
    fig = ih.begin_interaction('name', fnum)

    def _on_name_click(event):
        print_('[inter] clicked name')
        ax = event.inaxes
        if ih.clicked_inside_axis(event):
            viztype = vh.get_ibsdat(ax, 'viztype')
            print_(' viztype=%r' % viztype)
            if viztype == 'chip':
                aid = vh.get_ibsdat(ax, 'aid')
                print('... aid=%r' % aid)
                if event.button == 3:   # right-click
                    import guitool
                    from ibeis.viz.interact import interact_chip
                    height = fig.canvas.geometry().height()
                    qpoint = guitool.newQPoint(event.x, height - event.y)
                    refresh_func = functools.partial(viz.show_name, ibs, nid, fnum=fnum, sel_aids=sel_aids)
                    interact_chip.show_annot_context_menu(
                        ibs, aid, fig.canvas, qpoint, refresh_func=refresh_func,
                        with_interact_name=False)
                else:
                    viz.show_name(ibs, nid, fnum=fnum, sel_aids=[aid], in_image=True)
                    if select_aid_callback is not None:
                        select_aid_callback(aid)
        viz.draw()

    viz.show_name(ibs, nid, fnum=fnum, sel_aids=sel_aids, in_image=True)
    if dodraw:
        viz.draw()
    ih.connect_callback(fig, 'button_press_event', _on_name_click)
    pass
Beispiel #56
0
def show_image(ibs, gid, sel_aids=[], fnum=None, annote=True, draw_lbls=True,
               notitle=False,
               rich_title=False, pnum=(1, 1, 1), **kwargs):
    """
    Driver function to show images

    Args:
        ibs (IBEISController):  ibeis controller object
        gid (int): image row id
        sel_aids (list):
        fnum (int):  figure number
        annote (bool):
        draw_lbls (bool):

    Returns:
        tuple: (fig, ax)

    CommandLine:
        python -m ibeis.viz.viz_image --test-show_image --show
        python -m ibeis.viz.viz_image --test-show_image --show --db GZ_ALL
        python -m ibeis.viz.viz_image --test-show_image --show --db GZ_ALL --gid 100
        python -m ibeis.viz.viz_image --test-show_image --show --db PZ_MTEST --aid 10

        python -m ibeis.viz.viz_image --test-show_image --show --db PZ_MTEST --aid 91 --no-annot --rich-title
        python -m ibeis.viz.viz_image --test-show_image --show --db GIR_Tanya --aid 1 --no-annot --rich-title

    Example:
        >>> # SLOW_DOCTEST
        >>> # VIZ_TEST
        >>> from ibeis.viz.viz_image import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb(ut.get_argval('--db', str, 'testdb1'))
        >>> #gid = ibs.get_valid_gids()[0]
        >>> gid = ut.get_argval('--gid', int, 1)
        >>> aid = ut.get_argval('--aid', int, None)
        >>> if aid is not None:
        >>>    gid = ibs.get_annot_gids(aid)
        >>> sel_aids = []
        >>> fnum = None
        >>> annote = not ut.get_argflag('--no-annot')
        >>> rich_title = ut.get_argflag('--rich-title')
        >>> draw_lbls = True
        >>> # execute function
        >>> (fig, ax) = show_image(ibs, gid, sel_aids, fnum, annote, draw_lbls, rich_title)
        >>> pt.show_if_requested()
    """
    if fnum is None:
        fnum = pt.next_fnum()
    # Read Image
    img = ibs.get_images(gid)
    aid_list = ibs.get_image_aids(gid)
    if sel_aids == 'all':
        sel_aids = aid_list
    annotekw = get_annot_annotations(ibs, aid_list, sel_aids, draw_lbls)
    annotation_centers = vh.get_bbox_centers(annotekw['bbox_list'])
    title = vh.get_image_titles(ibs, gid)
    if rich_title:
        title += ', aids=%r' % (aid_list)
        title += ', db=%r' % (ibs.get_dbname())
    showkw = {
        'title'      : title,
        'annote'     : annote,
        'fnum'       : fnum,
        'pnum'       : pnum,
    }
    if notitle:
        del showkw['title']
    showkw.update(annotekw)
    fig, ax = viz_image2.show_image(img, **showkw)
    # Label the axis with data
    ph.set_plotdat(ax, 'annotation_centers', annotation_centers)
    ph.set_plotdat(ax, 'aid_list', aid_list)
    ph.set_plotdat(ax, 'viztype', 'image')
    ph.set_plotdat(ax, 'gid', gid)
    return fig, ax
Beispiel #57
0
def show_convolutional_weights(all_weights, use_color=None, limit=144, fnum=None, pnum=(1, 1, 1)):
    r"""
    Args:
        all_weights (?):
        use_color (bool):
        limit (int):

    CommandLine:
        python -m ibeis_cnn.draw_net --test-show_convolutional_weights --show
        python -m ibeis_cnn.draw_net --test-show_convolutional_weights --show --index=1

        # Need to fit mnist first
        python -m ibeis_cnn _ModelFitting.fit:1 --vd


    Example:
        >>> # DISABLE_DOCTEST
        >>> # Assumes mnist is trained
        >>> from ibeis_cnn.draw_net import *  # NOQA
        >>> from ibeis_cnn import ingest_data
        >>> from ibeis_cnn.models import MNISTModel
        >>> dataset = ingest_data.grab_mnist_category_dataset()
        >>> model = MNISTModel(batch_size=128, data_shape=dataset.data_shape,
        >>>                    name='bnorm',
        >>>                    output_dims=len(dataset.unique_labels),
        >>>                    batch_norm=True,
        >>>                    dataset_dpath=dataset.dataset_dpath)
        >>> model.encoder = None
        >>> model.init_arch()
        >>> model.load_model_state()
        >>> nn_layers = model.get_all_layers()
        >>> weighted_layers = [layer for layer in nn_layers if hasattr(layer, 'W')]
        >>> all_weights = weighted_layers[0].W.get_value()
        >>> print('all_weights.shape = %r' % (all_weights.shape,))
        >>> use_color = None
        >>> limit = 64
        >>> fig = show_convolutional_weights(all_weights, use_color, limit)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> pt.qt4ensure()
        >>> fig = show_convolutional_weights(all_weights, use_color, limit)
        >>> ut.show_if_requested()

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis_cnn.draw_net import *  # NOQA
        >>> from ibeis_cnn import models
        >>> from lasagne import layers
        >>> model = models.SiameseCenterSurroundModel(autoinit=True)
        >>> output_layer = model.get_output_layer()
        >>> nn_layers = layers.get_all_layers(output_layer)
        >>> weighted_layers = [layer for layer in nn_layers if hasattr(layer, 'W')]
        >>> index = ut.get_argval('--index', type_=int, default=0)
        >>> all_weights = weighted_layers[index].W.get_value()
        >>> print('all_weights.shape = %r' % (all_weights.shape,))
        >>> use_color = None
        >>> limit = 64
        >>> fig = show_convolutional_weights(all_weights, use_color, limit)
        >>> ut.show_if_requested()
    """
    import plottool as pt
    if fnum is None:
        fnum = pt.next_fnum()
    fig = pt.figure(fnum=fnum, pnum=pnum, docla=True)
    num, channels, height, width = all_weights.shape
    if use_color is None:
        # Try to infer if use_color should be shown
        use_color = (channels == 3)

    stacked_img = make_conv_weight_image(all_weights, limit)
    #ax = fig.add_subplot(111)
    if len(stacked_img.shape) == 3 and stacked_img.shape[-1] == 1:
        stacked_img = stacked_img.reshape(stacked_img.shape[:-1])
    pt.imshow(stacked_img)
    return fig
Beispiel #58
0
def show_multichip_match(rchip1,
                         rchip2_list,
                         kpts1,
                         kpts2_list,
                         fm_list,
                         fs_list,
                         featflag_list,
                         fnum=None,
                         pnum=None,
                         **kwargs):
    """
    move to df2
    rchip = rchip1
    H = H1 = None
    target_wh = None

    """
    import vtool.image as gtool
    import plottool as pt
    import numpy as np
    import vtool as vt
    kwargs = kwargs.copy()

    colorbar_ = kwargs.pop('colorbar_', True)
    stack_larger = kwargs.pop('stack_larger', False)
    # mode for features disabled by name scoring
    NONVOTE_MODE = kwargs.get('nonvote_mode', 'filter')

    def preprocess_chips(rchip, H, target_wh):
        rchip_ = rchip if H is None else gtool.warpHomog(rchip, H, target_wh)
        return rchip_

    if fnum is None:
        fnum = pt.next_fnum()

    target_wh1 = None
    H1 = None
    rchip1_ = preprocess_chips(rchip1, H1, target_wh1)
    # Hack to visually identify the query
    rchip1_ = vt.draw_border(rchip1_,
                             out=rchip1_,
                             thickness=15,
                             color=(pt.UNKNOWN_PURP[0:3] * 255).astype(
                                 np.uint8).tolist())
    wh1 = gtool.get_size(rchip1_)
    rchip2_list_ = [
        preprocess_chips(rchip2, None, wh1) for rchip2 in rchip2_list
    ]
    wh2_list = [gtool.get_size(rchip2) for rchip2 in rchip2_list_]

    num = 0 if len(rchip2_list) < 3 else 1
    #vert = True if len(rchip2_list) > 1 else False
    vert = True if len(rchip2_list) > 1 else None
    #num = 0

    if False and kwargs.get('fastmode', False):
        # This doesn't actually help the speed very much
        stackkw = dict(
            # Hack draw results faster Q
            #initial_sf=.4,
            #initial_sf=.9,
            use_larger=stack_larger,
            #use_larger=True,
        )
    else:
        stackkw = dict()
    #use_larger = True
    #vert = kwargs.get('fastmode', False)

    match_img, offset_list, sf_list = vt.stack_image_list_special(rchip1_,
                                                                  rchip2_list_,
                                                                  num=num,
                                                                  vert=vert,
                                                                  **stackkw)
    wh_list = np.array(ut.flatten([[wh1], wh2_list])) * sf_list

    offset1 = offset_list[0]
    wh1 = wh_list[0]
    sf1 = sf_list[0]

    fig, ax = pt.imshow(match_img, fnum=fnum, pnum=pnum)

    if kwargs.get('show_matches', True):
        ut.flatten(fs_list)
        #ut.embed()
        flat_fs, cumlen_list = ut.invertible_flatten2(fs_list)
        flat_colors = pt.scores_to_color(np.array(flat_fs), 'hot')
        colors_list = ut.unflatten2(flat_colors, cumlen_list)
        for _tup in zip(offset_list[1:], wh_list[1:], sf_list[1:], kpts2_list,
                        fm_list, fs_list, featflag_list, colors_list):
            offset2, wh2, sf2, kpts2, fm2_, fs2_, featflags, colors = _tup
            xywh1 = (offset1[0], offset1[1], wh1[0], wh1[1])
            xywh2 = (offset2[0], offset2[1], wh2[0], wh2[1])
            #colors = pt.scores_to_color(fs2)
            if kpts1 is not None and kpts2 is not None:
                if NONVOTE_MODE == 'filter':
                    fm2 = fm2_.compress(featflags, axis=0)
                    fs2 = fs2_.compress(featflags, axis=0)
                elif NONVOTE_MODE == 'only':
                    fm2 = fm2_.compress(np.logical_not(featflags), axis=0)
                    fs2 = fs2_.compress(np.logical_not(featflags), axis=0)
                else:
                    # TODO: optional coloring of nonvotes instead
                    fm2 = fm2_
                    fs2 = fs2_
                pt.plot_fmatch(xywh1,
                               xywh2,
                               kpts1,
                               kpts2,
                               fm2,
                               fs2,
                               fm_norm=None,
                               H1=None,
                               H2=None,
                               scale_factor1=sf1,
                               scale_factor2=sf2,
                               colorbar_=False,
                               colors=colors,
                               **kwargs)
        if colorbar_:
            pt.colorbar(flat_fs, flat_colors)
    bbox_list = [(x, y, w, h) for (x, y), (w, h) in zip(offset_list, wh_list)]
    return offset_list, sf_list, bbox_list
Beispiel #59
0
def run_devcmds(ibs, qaid_list, daid_list, acfg=None):
    """
    This function runs tests passed in with the -t flag
    """
    print('\n')
    #print('[dev] run_devcmds')
    print('==========================')
    print('[DEV] RUN EXPERIMENTS %s' % ibs.get_dbname())
    print('==========================')
    input_test_list = params.args.tests[:]
    print('input_test_list = %s' % (ut.list_str(input_test_list), ))
    # fnum = 1

    valid_test_list = []  # build list for printing in case of failure
    valid_test_helpstr_list = []  # for printing

    def mark_test_handled(testname):
        input_test_list.remove(testname)

    def intest(*args, **kwargs):
        helpstr = kwargs.get('help', '')
        valid_test_helpstr_list.append('   -t ' + ', '.join(args) + helpstr)
        for testname in args:
            valid_test_list.append(testname)
            ret = testname in input_test_list
            ret2 = testname in params.unknown  # Let unparsed args count towards tests
            if ret or ret2:
                if ret:
                    mark_test_handled(testname)
                else:
                    ret = ret2
                print('\n+===================')
                print(' [dev] running testname = %s' % (args, ))
                print('+-------------------\n')
                return ret
        return False

    valid_test_helpstr_list.append('    # --- Simple Tests ---')

    # Explicit (simple) test functions
    if intest('export'):
        export(ibs)
    if intest('dbinfo'):
        dbinfo.get_dbinfo(ibs)
    if intest('headers', 'schema'):
        ibs.db.print_schema()
    if intest('info'):
        print(ibs.get_infostr())
    if intest('printcfg'):
        printcfg(ibs)
    if intest('tables'):
        ibs.print_tables()
    if intest('imgtbl'):
        ibs.print_image_table()

    valid_test_helpstr_list.append('    # --- Decor Tests ---')

    locals_ = locals()

    # Implicit (decorated) test functions
    for (func_aliases, func) in DEVCMD_FUNCTIONS:
        if intest(*func_aliases):
            funcname = get_funcname(func)
            #with utool.Indenter('[dev.' + funcname + ']'):
            with utool.Timer(funcname):
                #print('[dev] qid_list=%r' % (qaid_list,))
                # FIXME: , daid_list
                if len(ut.get_func_argspec(func).args) == 0:
                    ret = func()
                else:
                    ret = func(ibs, qaid_list, daid_list)
                # Add variables returned by the function to the
                # "local scope" (the exec scop)
                if hasattr(ret, 'items'):
                    for key, val in ret.items():
                        if utool.is_valid_varname(key):
                            locals_[key] = val

    valid_test_helpstr_list.append('    # --- Config Tests ---')

    # ------
    # RUNS EXPERIMENT HARNESS OVER VALID TESTNAMES SPECIFIED WITH -t
    # ------

    # Config driven test functions
    # Allow any testcfg to be in tests like: vsone_1 or vsmany_3
    test_cfg_name_list = []
    for test_cfg_name in experiment_configs.TEST_NAMES:
        if intest(test_cfg_name):
            test_cfg_name_list.append(test_cfg_name)
    # Hack to allow for very customized harness tests
    for testname in input_test_list[:]:
        if testname.startswith('custom:'):
            test_cfg_name_list.append(testname)
            mark_test_handled(testname)
    if len(test_cfg_name_list):
        fnum = pt.next_fnum()
        # Run Experiments
        # backwards compatibility yo
        acfgstr_name_list = {'OVERRIDE_HACK': (qaid_list, daid_list)}
        assert False, 'This way of running tests no longer works. It may be fixed in the future'
        #acfg
        harness.test_configurations(ibs, acfgstr_name_list, test_cfg_name_list)

    valid_test_helpstr_list.append('    # --- Help ---')

    if intest('help'):
        print('valid tests are:')
        print('\n'.join(valid_test_helpstr_list))
        return locals_

    if len(input_test_list) > 0:
        print('valid tests are: \n')
        print('\n'.join(valid_test_list))
        raise Exception('Unknown tests: %r ' % input_test_list)
    return locals_