Exemple #1
0
    def show_each_dstncvs_chip(self, dodraw=True):
        """
        CommandLine:
            python -m wbia.viz.interact.interact_matches --test-show_each_dstncvs_chip --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from wbia.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])
        logger.info('dstncvs1_stats = ' + ut.get_stats_str(dstncvs1))
        logger.info('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:
            # self.draw()
            pt.draw()
Exemple #2
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())
     pt.draw()
Exemple #3
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)
     pt.draw()
Exemple #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()
Exemple #5
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)
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)
    logger.info(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,
    }
    logger.info('-' * 80)
    logger.info('')
    logger.info('WARNING!!!')
    logger.info('Hough image is not used often and not worth putting into depcache.')
    logger.info('This image is computed as needed and not cached to disk.')
    logger.info('')
    logger.info('-' * 80)
    results_list = list(  # NOQA
        randomforest.detect_gpath_list_with_species(
            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 on_click_inside(self, event, ax):
        import wbia.plottool as pt

        viztype = ph.get_plotdat(ax, 'viztype', None)
        logger.info('[ik] viztype=%r' % viztype)
        if viztype is None:
            pass
        elif viztype == 'keypoints':
            kpts = ph.get_plotdat(ax, 'kpts', [])
            if len(kpts) == 0:
                logger.info('...nokpts')
            else:
                logger.info('...nearest')
                x, y = event.xdata, event.ydata
                import vtool as vt

                fx = vt.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:
            logger.info('...unhandled')
        self.draw()
 def show_sver_process_to_aid(self, aid2):
     if self.verbose:
         logger.info('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()
 def show_matches_to_aid(self, aid2):
     if self.verbose:
         logger.info('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()
Exemple #10
0
 def sv_view(self, dodraw=True):
     """spatial verification view"""
     # fnum = viz.FNUMS['special']
     aid = self.daid
     fnum = pt.next_fnum()
     fig = pt.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:
         # self.draw()
         pt.draw()
    def _on_chip_click(event):
        logger.info('[inter] clicked chip')
        ax, x, y = event.inaxes, event.xdata, event.ydata
        if ih.clicked_outside_axis(event):
            if not ischild:
                logger.info('... out of axis')
                mode_ptr[0] = (mode_ptr[0] + 1) % 3
                _chip_view(**kwargs)
        else:
            if event.button == 3:  # right-click
                import wbia.guitool as gt

                # from wbia.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')
                logger.info('[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]
                        logger.info('... clicked fx=%r' % fx)
                        _select_fxth_kpt(fx)
                    else:
                        logger.info('... 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:
                    logger.info('...Unknown viztype: %r' % viztype)

        viz.draw()
Exemple #12
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()
Exemple #13
0
    def on_click_inside(self, event, ax):
        from wbia.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
        logger.info('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
            logger.info('.. control click')
            return self.sv_view()
        elif viztype in ['warped', 'unwarped']:
            logger.info('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)
            logger.info('hs_fx = %r' % (hs_fx, ))
            logger.info('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()
    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 wbia.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 __init__(co_wgt, ibs, gid_list, parent=None, hack=False):
        logger.info('[co_gui] Initializing')
        logger.info('[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()
Exemple #16
0
def show_keypoint_gradient_orientations(ibs,
                                        rchip,
                                        kp,
                                        vec,
                                        fnum=None,
                                        pnum=None,
                                        config2_=None):
    # Draw the gradient vectors of a patch overlaying the keypoint
    import wbia.plottoola as pt

    if fnum is None:
        fnum = pt.next_fnum()
    # rchip = ibs.get_annot_chips(aid, config2_=config2_)
    # kp    = ibs.get_annot_kpts(aid, config2_=config2_)[fx]
    # sift  = ibs.get_annot_vecs(aid, config2_=config2_)[fx]
    pt.draw_keypoint_gradient_orientations(rchip,
                                           kp,
                                           sift=vec,
                                           mode='vec',
                                           fnum=fnum,
                                           pnum=pnum)
Exemple #17
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:
            # from wbia.viz.interact import interact_matches
            # 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()
Exemple #18
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):  wbia 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 wbia.viz.viz_image --test-show_image --show
        python -m wbia.viz.viz_image --test-show_image --show --db GZ_ALL
        python -m wbia.viz.viz_image --test-show_image --show --db GZ_ALL --gid 100
        python -m wbia.viz.viz_image --test-show_image --show --db PZ_MTEST --aid 10

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

    Example:
        >>> # SLOW_DOCTEST
        >>> # VIZ_TEST
        >>> from wbia.viz.viz_image import *  # NOQA
        >>> import wbia
        >>> # build test data
        >>> ibs = wbia.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
Exemple #19
0
    def __init__(
        self,
        ibs,
        cm,
        aid2=None,
        fnum=None,
        qreq_=None,
        figtitle='Match Interaction',
        **kwargs,
    ):
        # logger.info('[ibs] MatchInteraction.__init__')
        self.ibs = ibs
        self.cm = cm
        self.qreq_ = qreq_
        # 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]
            fm = self.cm.fm_list[index]
            fk = self.cm.fk_list[index]
            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
            fs = None if fs_list is None else fs_list[index]
            H1 = None if self.cm.H_list is None else cm.H_list[index]
            self.score = None if self.cm.score_list is None else self.cm.score_list[
                index]
        else:
            self.qaid = self.cm.qaid
            self.daid = aid2
            fm = np.empty((0, 2), dtype=hstypes.FM_DTYPE)
            fk = np.empty(0, dtype=hstypes.FK_DTYPE)
            fsv = np.empty((0, 2), dtype=hstypes.FS_DTYPE)
            fs = np.empty(0, dtype=hstypes.FS_DTYPE)
            H1 = None
            self.score = None

        # Read properties
        self.query_config2_ = (None if self.qreq_ is None else
                               self.qreq_.extern_query_config2)
        self.data_config2_ = (None if self.qreq_ is None else
                              self.qreq_.extern_data_config2)

        rchip1 = vh.get_chips(ibs, [self.qaid],
                              config2_=self.query_config2_)[0]
        rchip2 = vh.get_chips(ibs, [self.daid], config2_=self.data_config2_)[0]

        kpts1 = ibs.get_annot_kpts([self.qaid],
                                   config2_=self.query_config2_)[0]
        kpts2 = ibs.get_annot_kpts([self.daid], config2_=self.data_config2_)[0]

        vecs1 = ibs.get_annot_vecs([self.qaid],
                                   config2_=self.query_config2_)[0]
        vecs2 = ibs.get_annot_vecs([self.daid], config2_=self.data_config2_)[0]

        self.figtitle = figtitle
        self.kwargs = kwargs
        self.fnum2 = pt.next_fnum()

        super(MatchInteraction, self).__init__(
            rchip1,
            rchip2,
            kpts1,
            kpts2,
            fm,
            fs,
            fsv,
            vecs1,
            vecs2,
            H1,
            H2=None,
            fk=fk,
            fnum=fnum,
            **kwargs,
        )
Exemple #20
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 wbia.algo.hots.devcases --test-myquery
        python -m wbia.algo.hots.devcases --test-myquery --show --index 0
        python -m wbia.algo.hots.devcases --test-myquery --show --index 1
        python -m wbia.algo.hots.devcases --test-myquery --show --index 2

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

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.algo.hots.devcases import *  # NOQA
        >>> ut.dev_ipython_copypaster(myquery) if ut.inIPython() else myquery()
        >>> pt.show_if_requested()
    """
    from wbia.algo.hots import special_query  # NOQA
    from wbia.algo.hots import distinctiveness_normalizer  # NOQA
    from wbia import viz  # NOQA
    import wbia.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 try_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, ))
    logger.info('Begin Grid Search')
    for cfgdict in ut.ProgressIter(gridsearch, lbl='GridSearch'):
        qres_copy, tp_score, tn_score = try_config(qreq_, qres_orig, cfgdict)
        gridsearch.append_result(tp_score, tn_score)
    logger.info('Finish Grid Search')

    # Get best result
    best_cfgdict = gridsearch.get_rank_cfgdict()
    qres_copy, tp_score, tn_score = try_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)
    logger.info(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)
    logger.info(param_stats_str)

    csvtext = gridsearch.get_csv_results(10)
    logger.info(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)
    # logger.info(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()
    # logger.info(ut.repr2()))
    # TODO: plot max variation dims
    # import wbia.plottool as pt
    # pt.plot(p_list, diff_list)
    """
Exemple #21
0
def run_devcmds(ibs, qaid_list, daid_list, acfg=None):
    """
    This function runs tests passed in with the -t flag
    """
    params.parse_args()
    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.repr2(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'):
        raise NotImplementedError('export')
    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'):
        raise NotImplementedError('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_
Exemple #22
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 wbia.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)
    stack_side = kwargs.pop('stack_side', 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)

    if stack_side:
        # hack to stack all database images vertically
        num = 0

    # TODO: heatmask

    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
def ishow_name(ibs,
               nid,
               sel_aids=[],
               select_aid_callback=None,
               fnum=5,
               dodraw=True,
               **kwargs):
    r"""
    Args:
        ibs (IBEISController):  wbia controller object
        nid (?):
        sel_aids (list):
        select_aid_callback (None):
        fnum (int):  figure number

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

    Example:
        >>> # DISABLE_DOCTEST
        >>> from wbia.viz.interact.interact_name import *  # NOQA
        >>> import wbia
        >>> # build test data
        >>> ibs = wbia.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')
                logger.info('... aid=%r' % aid)
                if event.button == 3:  # right-click
                    from wbia import guitool
                    from wbia.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