예제 #1
0
def get_namescore_nonvoting_feature_flags(fm_list, fs_list, dnid_list, name_groupxs, kpts1=None):
    r"""
    fm_list = [fm[:min(len(fm), 10)] for fm in fm_list]
    fs_list = [fs[:min(len(fs), 10)] for fs in fs_list]
    """
    fx1_list = [fm.T[0] for fm in fm_list]
    # Group annotation matches by name
    name_grouped_fx1_list = vt.apply_grouping_(fx1_list, name_groupxs)
    name_grouped_fs_list  = vt.apply_grouping_(fs_list,  name_groupxs)
    # Stack up all matches to a particular name, keep track of original indicies via offets
    name_invertable_flat_fx1_list = list(map(ut.invertible_flatten2_numpy, name_grouped_fx1_list))
    name_grouped_fx1_flat = ut.get_list_column(name_invertable_flat_fx1_list, 0)
    name_grouped_invertable_cumsum_list = ut.get_list_column(name_invertable_flat_fx1_list, 1)
    name_grouped_fs_flat = list(map(np.hstack, name_grouped_fs_list))
    if kpts1 is not None:
        xys1_ = vt.get_xys(kpts1).T
        kpts_xyid_list = vt.compute_unique_data_ids(xys1_)
        # Make nested group for every name by query feature index (accounting for duplicate orientation)
        name_grouped_xyid_flat = list(kpts_xyid_list.take(fx1) for fx1 in name_grouped_fx1_flat)
        xyid_groupxs_list = list(vt.group_indices(xyid_flat)[1] for xyid_flat in name_grouped_xyid_flat)
        name_group_fx1_groupxs_list = xyid_groupxs_list
    else:
        # Make nested group for every name by query feature index
        fx1_groupxs_list = [vt.group_indices(fx1_flat)[1] for fx1_flat in name_grouped_fx1_flat]
        name_group_fx1_groupxs_list = fx1_groupxs_list
    name_grouped_fid_grouped_fs_list = [
        vt.apply_grouping(fs_flat, fid_groupxs)
        for fs_flat, fid_groupxs in zip(name_grouped_fs_flat, name_group_fx1_groupxs_list)
    ]

    # Flag which features are valid in this grouped space. Only one keypoint should be able to vote
    # for each group
    name_grouped_fid_grouped_isvalid_list = [
        np.array([fs_group.max() == fs_group for fs_group in fid_grouped_fs_list])
        for fid_grouped_fs_list in name_grouped_fid_grouped_fs_list
    ]

    # Go back to being grouped only in name space
    #dtype = np.bool
    name_grouped_isvalid_flat_list = [
        vt.invert_apply_grouping2(fid_grouped_isvalid_list, fid_groupxs, dtype=np.bool)
        for fid_grouped_isvalid_list, fid_groupxs in zip(name_grouped_fid_grouped_isvalid_list, name_group_fx1_groupxs_list)
    ]

    name_grouped_isvalid_unflat_list = [
        ut.unflatten2(isvalid_flat, invertable_cumsum_list)
        for isvalid_flat, invertable_cumsum_list in zip(name_grouped_isvalid_flat_list, name_grouped_invertable_cumsum_list)
    ]

    # Reports which features were valid in name scoring for every annotation
    featflag_list = vt.invert_apply_grouping(name_grouped_isvalid_unflat_list, name_groupxs)
    return featflag_list
예제 #2
0
def compute_and_write_probchip(ibs, aid_list, config2_=None, lazy=True):
    """ Computes probability chips using pyrf

    CommandLine:
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:0 --show
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:1
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:2 --show --cnn

    Example0:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('PZ_MTEST')
        >>> config2_ = None
        >>> lazy = True
        >>> aid_list = ibs.get_valid_aids(species=ibeis.const.TEST_SPECIES.ZEB_PLAIN)[0:4]
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(probchip_fpath_list_, nPerPage=4)
        >>> ut.show_if_requested()

    Example1:
        >>> # SLOW_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> config2_ = None
        >>> lazy = False
        >>> aid_list = ibs.get_valid_aids(species=ibeis.const.TEST_SPECIES.ZEB_PLAIN)
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)

    Example2:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> config2_ = ibs.new_query_params({'featweight_detector': 'cnn'})
        >>> lazy = True
        >>> aid_list = ibs.get_valid_aids()
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(probchip_fpath_list_, nPerPage=4)
        >>> ut.show_if_requested()

    Dev::
        #ibs.delete_annot_chips(aid_list)
        #probchip_fpath_list = get_annot_probchip_fpath_list(ibs, aid_list)
    """
    # Get probchip dest information (output path)
    # TODO; properly ungroup output
    grouped_aids, unique_species, groupxs = group_aids_by_featweight_species(
        ibs, aid_list, config2_)
    nSpecies = len(unique_species)
    nTasks = len(aid_list)
    print(('[preproc_probchip.compute_and_write_probchip] '
          'Preparing to compute %d probchips of %d species')
          % (nTasks, nSpecies))
    cachedir = ibs.get_probchip_dir()
    ut.ensuredir(cachedir)

    grouped_probchip_fpath_list = []
    if ut.VERBOSE:
        print('[preproc_probchip] +--------------------')
    for aids, species in zip(grouped_aids, unique_species):
        if ut.VERBOSE:
            print('[preproc_probchip] Computing probchips for species=%r' % species)
            print('[preproc_probchip] |--------------------')
        if len(aids) == 0:
            continue
        probchip_fpaths = get_annot_probchip_fpath_list(ibs, aids,
                                                        config2_=config2_,
                                                        species=species)

        if lazy:
            # Filter out probchips that are already on disk
            # pyrf used to do this, now we need to do it
            # caching should be implicit due to using the visual_annot_uuid in
            # the filename
            isdirty_list = ut.not_list(map(exists, probchip_fpaths))
            dirty_aids = ut.compress(aids, isdirty_list)
            dirty_probchip_fpath_list = ut.compress(probchip_fpaths, isdirty_list)
            print(('[preproc_probchip.compute_and_write_probchip]'
                  ' Lazy compute of to compute %d/%d of species=%s') %
                  (len(dirty_aids), len(aids), species))
        else:
            # No filtering
            dirty_aids  = aids
            dirty_probchip_fpath_list = probchip_fpaths

        if len(dirty_aids) > 0:
            write_dirty_aids(ibs, dirty_probchip_fpath_list, dirty_aids, config2_, species)

        grouped_probchip_fpath_list.append(probchip_fpaths)
    if ut.VERBOSE:
        print('[preproc_probchip] Done computing probability images')
        print('[preproc_probchip] L_______________________')

    probchip_fpath_list = vt.invert_apply_grouping2(
        grouped_probchip_fpath_list, groupxs, dtype=object)
    return probchip_fpath_list
예제 #3
0
def compute_and_write_probchip(ibs, aid_list, config2_=None, lazy=True):
    """ Computes probability chips using pyrf

    CommandLine:
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:0 --show
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:1
        python -m ibeis.algo.preproc.preproc_probchip --test-compute_and_write_probchip:2 --show --cnn

    Example0:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('PZ_MTEST')
        >>> config2_ = None
        >>> lazy = True
        >>> aid_list = ibs.get_valid_aids(species=ibeis.const.TEST_SPECIES.ZEB_PLAIN)[0:4]
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(probchip_fpath_list_, nPerPage=4)
        >>> ut.show_if_requested()

    Example1:
        >>> # SLOW_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> config2_ = None
        >>> lazy = False
        >>> aid_list = ibs.get_valid_aids(species=ibeis.const.TEST_SPECIES.ZEB_PLAIN)
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)

    Example2:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.preproc.preproc_probchip import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> config2_ = ibs.new_query_params({'fw_detector': 'cnn'})
        >>> lazy = True
        >>> aid_list = ibs.get_valid_aids()
        >>> probchip_fpath_list_ = compute_and_write_probchip(ibs, aid_list, config2_, lazy=lazy)
        >>> result = ut.list_str(probchip_fpath_list_)
        >>> print(result)
        >>> ut.quit_if_noshow()
        >>> import plottool as pt
        >>> iteract_obj = pt.interact_multi_image.MultiImageInteraction(probchip_fpath_list_, nPerPage=4)
        >>> ut.show_if_requested()

    Dev::
        #ibs.delete_annot_chips(aid_list)
        #probchip_fpath_list = get_annot_probchip_fpath_list(ibs, aid_list)
    """
    # Get probchip dest information (output path)
    # TODO; properly ungroup output
    grouped_aids, unique_species, groupxs = group_aids_by_featweight_species(
        ibs, aid_list, config2_)
    nSpecies = len(unique_species)
    nTasks = len(aid_list)
    print(('[preproc_probchip.compute_and_write_probchip] '
           'Preparing to compute %d probchips of %d species') %
          (nTasks, nSpecies))
    cachedir = ibs.get_probchip_dir()
    ut.ensuredir(cachedir)

    grouped_probchip_fpath_list = []
    if ut.VERBOSE:
        print('[preproc_probchip] +--------------------')
    for aids, species in zip(grouped_aids, unique_species):
        if ut.VERBOSE:
            print('[preproc_probchip] Computing probchips for species=%r' %
                  species)
            print('[preproc_probchip] |--------------------')
        if len(aids) == 0:
            continue
        probchip_fpaths = get_annot_probchip_fpath_list(ibs,
                                                        aids,
                                                        config2_=config2_,
                                                        species=species)

        if lazy:
            # Filter out probchips that are already on disk
            # pyrf used to do this, now we need to do it
            # caching should be implicit due to using the visual_annot_uuid in
            # the filename
            isdirty_list = ut.not_list(map(exists, probchip_fpaths))
            dirty_aids = ut.compress(aids, isdirty_list)
            dirty_probchip_fpath_list = ut.compress(probchip_fpaths,
                                                    isdirty_list)
            print(('[preproc_probchip.compute_and_write_probchip]'
                   ' Lazy compute of to compute %d/%d of species=%s') %
                  (len(dirty_aids), len(aids), species))
        else:
            # No filtering
            dirty_aids = aids
            dirty_probchip_fpath_list = probchip_fpaths

        if len(dirty_aids) > 0:
            write_dirty_aids(ibs, dirty_probchip_fpath_list, dirty_aids,
                             config2_, species)

        grouped_probchip_fpath_list.append(probchip_fpaths)
    if ut.VERBOSE:
        print('[preproc_probchip] Done computing probability images')
        print('[preproc_probchip] L_______________________')

    probchip_fpath_list = vt.invert_apply_grouping2(
        grouped_probchip_fpath_list, groupxs, dtype=object)
    return probchip_fpath_list