Ejemplo n.º 1
0
def set_annot_lblannot_from_value(ibs, aid_list, value_list, _lbltype, ensure=True):
    """
    Associates the annot and lblannot of a specific type and value
    Adds the lblannot if it doesnt exist.
    Wrapper around convenience function for set_annot_from_lblannot_rowid
    """
    assert value_list is not None
    assert _lbltype is not None
    if ensure:
        pass
    # a value consisting of an empty string or all spaces is set to the default
    DEFAULT_VALUE = const.KEY_DEFAULTS[_lbltype]
    EMPTY_KEY = const.EMPTY_KEY
    # setting a name to DEFAULT_VALUE or EMPTY is equivalent to unnaming it
    value_list_ = [DEFAULT_VALUE if value.strip() == EMPTY_KEY else value for value in value_list]
    notdefault_list = [value != DEFAULT_VALUE for value in value_list_]
    aid_list_to_delete = ut.get_dirty_items(aid_list, notdefault_list)
    # Set all the valid valids
    aids_to_set   = ut.compress(aid_list, notdefault_list)
    values_to_set = ut.compress(value_list_, notdefault_list)
    ibs.delete_annot_relations_oftype(aid_list_to_delete, _lbltype)
    # remove the relationships that have now been unnamed
    # Convert names into lblannot_rowid
    # FIXME: This function should not be able to set label realationships
    # to labels that have not been added!!
    # This is an inefficient way of getting lblannot_rowids!
    lbltype_rowid_list = [ibs.lbltype_ids[_lbltype]] * len(values_to_set)
    # auto ensure
    lblannot_rowid_list = ibs.add_lblannots(lbltype_rowid_list, values_to_set)
    # Call set_annot_from_lblannot_rowid to finish the conditional adding
    ibs.set_annot_lblannot_from_rowid(aids_to_set, lblannot_rowid_list, _lbltype)
def set_annot_lblannot_from_value(ibs, aid_list, value_list, _lbltype, ensure=True):
    """
    Associates the annot and lblannot of a specific type and value
    Adds the lblannot if it doesnt exist.
    Wrapper around convenience function for set_annot_from_lblannot_rowid
    """
    assert value_list is not None
    assert _lbltype is not None
    if ensure:
        pass
    # a value consisting of an empty string or all spaces is set to the default
    DEFAULT_VALUE = const.KEY_DEFAULTS[_lbltype]
    EMPTY_KEY = const.EMPTY_KEY
    # setting a name to DEFAULT_VALUE or EMPTY is equivalent to unnaming it
    value_list_ = [
        DEFAULT_VALUE if value.strip() == EMPTY_KEY else value for value in value_list
    ]
    notdefault_list = [value != DEFAULT_VALUE for value in value_list_]
    aid_list_to_delete = ut.get_dirty_items(aid_list, notdefault_list)
    # Set all the valid valids
    aids_to_set = ut.compress(aid_list, notdefault_list)
    values_to_set = ut.compress(value_list_, notdefault_list)
    ibs.delete_annot_relations_oftype(aid_list_to_delete, _lbltype)
    # remove the relationships that have now been unnamed
    # Convert names into lblannot_rowid
    # FIXME: This function should not be able to set label realationships
    # to labels that have not been added!!
    # This is an inefficient way of getting lblannot_rowids!
    lbltype_rowid_list = [ibs.lbltype_ids[_lbltype]] * len(values_to_set)
    # auto ensure
    lblannot_rowid_list = ibs.add_lblannots(lbltype_rowid_list, values_to_set)
    # Call set_annot_from_lblannot_rowid to finish the conditional adding
    ibs.set_annot_lblannot_from_rowid(aids_to_set, lblannot_rowid_list, _lbltype)
Ejemplo n.º 3
0
def add_annot_chips(ibs, aid_list, qreq_=None):
    """
    FIXME: This is a dirty dirty function
    Adds chip data to the ANNOTATION. (does not create ANNOTATIONs. first use add_annots
    and then pass them here to ensure chips are computed) """
    # Ensure must be false, otherwise an infinite loop occurs
    from ibeis.model.preproc import preproc_chip
    cid_list = ibs.get_annot_chip_rowids(aid_list, ensure=False)
    dirty_aids = ut.get_dirty_items(aid_list, cid_list)
    if len(dirty_aids) > 0:
        if ut.VERBOSE:
            print('[ibs] adding chips')
        try:
            # FIXME: Cant be lazy until chip config / delete issue is fixed
            preproc_chip.compute_and_write_chips(ibs, aid_list)
            #preproc_chip.compute_and_write_chips_lazy(ibs, aid_list)
            params_iter = preproc_chip.add_annot_chips_params_gen(ibs, dirty_aids)
        except AssertionError as ex:
            ut.printex(ex, '[!ibs.add_annot_chips]')
            print('[!ibs.add_annot_chips] ' + ut.list_dbgstr('aid_list'))
            raise
        colnames = (ANNOT_ROWID, 'config_rowid', 'chip_uri', 'chip_width', 'chip_height',)
        get_rowid_from_superkey = functools.partial(ibs.get_annot_chip_rowids, ensure=False, qreq_=qreq_)
        cid_list = ibs.dbcache.add_cleanly(const.CHIP_TABLE, colnames, params_iter, get_rowid_from_superkey)

    return cid_list
Ejemplo n.º 4
0
def set_annot_lblannot_from_rowid(ibs, aid_list, lblannot_rowid_list, _lbltype):
    """ Sets items/lblannot_rowids of a list of annotations."""
    # Get the alrids_list for the aids, using the lbltype as a filter
    alrids_list = ibs.get_annot_alrids_oftype(aid_list, ibs.lbltype_ids[_lbltype])
    # Find the aids which already have relationships (of _lbltype)
    setflag_list = [len(alrids) > 0 for alrids in alrids_list]
    # Add the relationship if it doesn't exist
    aid_list_to_add = ut.get_dirty_items(aid_list, setflag_list)
    lblannot_rowid_list_to_add = ut.get_dirty_items(lblannot_rowid_list, setflag_list)
    # set the existing relationship if one already exists
    alrids_list_to_set = ut.compress(alrids_list, setflag_list)
    lblannot_rowid_list_to_set = ut.compress(lblannot_rowid_list, setflag_list)
    # Assert each annot has only one relationship of this type
    ibsfuncs.assert_singleton_relationship(ibs, alrids_list_to_set)
    alrid_list_to_set = ut.flatten(alrids_list_to_set)
    # Add the new relationships
    ibs.add_annot_relationship(aid_list_to_add, lblannot_rowid_list_to_add)
    # Set the old relationships
    ibs.set_alr_lblannot_rowids(alrid_list_to_set, lblannot_rowid_list_to_set)
def set_annot_lblannot_from_rowid(ibs, aid_list, lblannot_rowid_list, _lbltype):
    """ Sets items/lblannot_rowids of a list of annotations."""
    # Get the alrids_list for the aids, using the lbltype as a filter
    alrids_list = ibs.get_annot_alrids_oftype(aid_list, ibs.lbltype_ids[_lbltype])
    # Find the aids which already have relationships (of _lbltype)
    setflag_list = [len(alrids) > 0 for alrids in alrids_list]
    # Add the relationship if it doesn't exist
    aid_list_to_add = ut.get_dirty_items(aid_list, setflag_list)
    lblannot_rowid_list_to_add = ut.get_dirty_items(lblannot_rowid_list, setflag_list)
    # set the existing relationship if one already exists
    alrids_list_to_set = ut.compress(alrids_list, setflag_list)
    lblannot_rowid_list_to_set = ut.compress(lblannot_rowid_list, setflag_list)
    # Assert each annot has only one relationship of this type
    ibsfuncs.assert_singleton_relationship(ibs, alrids_list_to_set)
    alrid_list_to_set = ut.flatten(alrids_list_to_set)
    # Add the new relationships
    ibs.add_annot_relationship(aid_list_to_add, lblannot_rowid_list_to_add)
    # Set the old relationships
    ibs.set_alr_lblannot_rowids(alrid_list_to_set, lblannot_rowid_list_to_set)
Ejemplo n.º 6
0
def compute_and_write_chips_lazy(ibs, aid_list):
    """
    Will write a chip if it does not exist on disk, regardless of if it exists
    in the SQL database
    """
    print('[preproc_chip] compute_and_write_chips_lazy')
    # Mark which aid's need their chips computed
    cfpath_list = get_annot_cfpath_list(ibs, aid_list)
    exists_flags = [exists(cfpath) for cfpath in cfpath_list]
    invalid_aids = utool.get_dirty_items(aid_list, exists_flags)
    print('[preproc_chip] %d / %d chips need to be computed' %
          (len(invalid_aids), len(aid_list)))
    compute_and_write_chips(ibs, invalid_aids)
Ejemplo n.º 7
0
def add_chip_feats(ibs, cid_list, force=False, qreq_=None):
    """ Computes the features for every chip without them """
    from ibeis.model.preproc import preproc_feat
    fid_list = ibs.get_chip_fids(cid_list, ensure=False, qreq_=qreq_)
    dirty_cids = ut.get_dirty_items(cid_list, fid_list)
    if len(dirty_cids) > 0:
        if ut.VERBOSE:
            print('[ibs] adding %d / %d features' % (len(dirty_cids), len(cid_list)))
        params_iter = preproc_feat.add_feat_params_gen(ibs, dirty_cids, qreq_=qreq_)
        colnames = (CHIP_ROWID, 'config_rowid', FEAT_NUM_FEAT, FEAT_KPTS, FEAT_VECS)
        get_rowid_from_superkey = functools.partial(ibs.get_chip_fids, ensure=False, qreq_=qreq_)
        fid_list = ibs.dbcache.add_cleanly(const.FEATURE_TABLE, colnames, params_iter, get_rowid_from_superkey)

    return fid_list
Ejemplo n.º 8
0
def compute_and_write_detectimg_lazy(ibs, gid_list):
    """
    Will write a img if it does not exist on disk, regardless of if it exists
    in the SQL database
    """
    print('[preproc] compute_and_write_detectimg_lazy')
    # Mark which aid's need their detectimg computed
    new_gfpath_list = get_image_detectimg_fpath_list(ibs, gid_list)
    exists_flags = [exists(gfpath) for gfpath in new_gfpath_list]
    invalid_gids = utool.get_dirty_items(gid_list, exists_flags)
    print('[preproc_detectimg] %d / %d detectimgs need to be computed' %
          (len(invalid_gids), len(gid_list)))
    compute_and_write_detectimg(ibs, invalid_gids)
    return new_gfpath_list
Ejemplo n.º 9
0
    def postingest_tesdb1_func(ibs):
        print('postingest_tesdb1_func')
        # Adjust data as we see fit
        import numpy as np
        gid_list = np.array(ibs.get_valid_gids())
        unixtimes_even = (gid_list[0::2] + 100).tolist()
        unixtimes_odd  = (gid_list[1::2] + 9001).tolist()
        unixtime_list = unixtimes_even + unixtimes_odd
        ibs.set_image_unixtime(gid_list, unixtime_list)
        # Unname first aid in every name
        aid_list = ibs.get_valid_aids()
        nid_list = ibs.get_annot_nids(aid_list)
        nid_list = [ (nid if nid > 0 else None) for nid in nid_list]
        unique_flag = utool.flag_unique_items(nid_list)
        unique_nids = utool.filter_items(nid_list, unique_flag)
        none_nids = [ nid is not None for nid in nid_list]
        flagged_nids = [nid for nid in unique_nids if nid_list.count(nid) > 1]
        plural_flag = [nid in flagged_nids for nid in nid_list]
        flag_list = map(all, izip(plural_flag, unique_flag, none_nids))
        flagged_aids = utool.filter_items(aid_list, flag_list)
        if utool.VERYVERBOSE:
            def print2(*args):
                print('[post_testdb1] ' + ', '.join(args))
            print2('aid_list=%r' % aid_list)
            print2('nid_list=%r' % nid_list)
            print2('unique_flag=%r' % unique_flag)
            print2('plural_flag=%r' % plural_flag)
            print2('unique_nids=%r' % unique_nids)
            print2('none_nids=%r' % none_nids)
            print2('flag_list=%r' % flag_list)
            print2('flagged_nids=%r' % flagged_nids)
            print2('flagged_aids=%r' % flagged_aids)
            # print2('new_nids=%r' % new_nids)
        # Unname, some annotations for testing
        delete_aids = utool.filter_items(aid_list, flag_list)
        ibs.delete_annot_nids(delete_aids)
        # Add all annotations with names as exemplars
        from ibeis.control.IBEISControl import IBEISController
        assert isinstance(ibs, IBEISController)
        unflagged_aids = utool.get_dirty_items(aid_list, flag_list)
        exemplar_flags = [True] * len(unflagged_aids)
        ibs.set_annot_exemplar_flag(unflagged_aids, exemplar_flags)

        return None
Ejemplo n.º 10
0
def compute_and_write_detectimg_lazy(ibs, gid_list):
    """
    Will write a img if it does not exist on disk, regardless of if it exists
    in the SQL database

    Example:
        >>> # SLOW_DOCTEST
        >>> import ibeis
        >>> from ibeis.algo.preproc.preproc_detectimg import *  # NOQA
        >>> ibs = ibeis.opendb('testdb1')
        >>> valid_gids = ibs.get_valid_gids()
        >>> gid_list = valid_gids[0:2]
        >>> result = compute_and_write_detectimg_lazy(ibs, gid_list)
    """
    print('[preproc_detectimg] compute_and_write_detectimg_lazy')
    # Mark which aid's need their detectimg computed
    new_gfpath_list = get_image_detectimg_fpath_list(ibs, gid_list)
    exists_flags = [exists(gfpath) for gfpath in new_gfpath_list]
    invalid_gids = utool.get_dirty_items(gid_list, exists_flags)
    print('[preproc_detectimg] %d / %d detectimgs need to be computed' %
          (len(invalid_gids), len(gid_list)))
    compute_and_write_detectimg(ibs, invalid_gids)
    return new_gfpath_list
Ejemplo n.º 11
0
def get_image_hough_gpaths(ibs, gid_list, species, quick=True):
    detectkw = {
        'quick': quick,
        'save_detection_images': True,
        'save_scales': True,
    }
    #
    # Resize to a standard image size prior to detection
    src_gpath_list = list(imap(str, ibs.get_image_detectpaths(gid_list)))
    dst_gpath_list = [splitext(gpath)[0] for gpath in src_gpath_list]
    hough_gpath_list = [gpath + '_hough.png' for gpath in dst_gpath_list]
    isvalid_list = [exists(gpath) for gpath in hough_gpath_list]

    # Need to recompute hough images for these gids
    dirty_gids = utool.get_dirty_items(gid_list, isvalid_list)
    num_dirty = len(dirty_gids)
    if num_dirty > 0:
        print('[detect.rf] making hough images for %d images' % num_dirty)
        detect_gen = generate_detections(ibs, dirty_gids, species, **detectkw)
        # Execute generator
        for tup in detect_gen:
            pass

    return hough_gpath_list
Ejemplo n.º 12
0
    def postingest_tesdb1_func(ibs):
        import numpy as np
        from ibeis import constants as const
        print('postingest_tesdb1_func')
        # Adjust data as we see fit
        gid_list = np.array(ibs.get_valid_gids())
        # Set image unixtimes
        unixtimes_even = (gid_list[0::2] + 100).tolist()
        unixtimes_odd  = (gid_list[1::2] + 9001).tolist()
        unixtime_list = unixtimes_even + unixtimes_odd
        ibs.set_image_unixtime(gid_list, unixtime_list)
        # Unname first aid in every name
        aid_list = ibs.get_valid_aids()
        nid_list = ibs.get_annot_name_rowids(aid_list)
        nid_list = [ (nid if nid > 0 else None) for nid in nid_list]
        unique_flag = ut.flag_unique_items(nid_list)
        unique_nids = ut.compress(nid_list, unique_flag)
        none_nids = [ nid is not None for nid in nid_list]
        flagged_nids = [nid for nid in unique_nids if nid_list.count(nid) > 1]
        plural_flag = [nid in flagged_nids for nid in nid_list]
        flag_list = list(map(all, zip(plural_flag, unique_flag, none_nids)))
        flagged_aids = ut.compress(aid_list, flag_list)
        if ut.VERYVERBOSE:
            def print2(*args):
                print('[post_testdb1] ' + ', '.join(args))
            print2('aid_list=%r' % aid_list)
            print2('nid_list=%r' % nid_list)
            print2('unique_flag=%r' % unique_flag)
            print2('plural_flag=%r' % plural_flag)
            print2('unique_nids=%r' % unique_nids)
            print2('none_nids=%r' % none_nids)
            print2('flag_list=%r' % flag_list)
            print2('flagged_nids=%r' % flagged_nids)
            print2('flagged_aids=%r' % flagged_aids)
            # print2('new_nids=%r' % new_nids)
        # Unname, some annotations for testing
        unname_aids = ut.compress(aid_list, flag_list)
        ibs.delete_annot_nids(unname_aids)
        # Add all annotations with names as exemplars
        #from ibeis.control.IBEISControl import IBEISController
        #assert isinstance(ibs, IBEISController)
        unflagged_aids = ut.get_dirty_items(aid_list, flag_list)
        exemplar_flags = [True] * len(unflagged_aids)
        ibs.set_annot_exemplar_flags(unflagged_aids, exemplar_flags)
        # Set some test species labels
        species_text_list = ibs.get_annot_species_texts(aid_list)
        for ix in range(0, 6):
            species_text_list[ix] = const.TEST_SPECIES.ZEB_PLAIN
        # These are actually plains zebras.
        for ix in range(8, 10):
            species_text_list[ix] = const.TEST_SPECIES.ZEB_GREVY
        for ix in range(10, 12):
            species_text_list[ix] = const.TEST_SPECIES.BEAR_POLAR

        ibs.set_annot_species(aid_list, species_text_list)
        ibs.set_annot_notes(aid_list[8:10], ['this is actually a plains zebra'] * 2)
        ibs.set_annot_notes(aid_list[0:1], ['aid 1 and 2 are correct matches'])
        ibs.set_annot_notes(aid_list[6:7], ['very simple image to debug feature detector'])
        ibs.set_annot_notes(aid_list[7:8], ['standard test image'])

        # Set some randomish gps flags that are within nnp
        unixtime_list = ibs.get_image_unixtime(gid_list)
        valid_lat_min = -1.4446
        valid_lat_max = -1.3271
        valid_lon_min = 36.7619
        valid_lon_max = 36.9622
        valid_lat_range = valid_lat_max - valid_lat_min
        valid_lon_range = valid_lon_max - valid_lon_min
        randstate = np.random.RandomState(unixtime_list)
        new_gps_list = randstate.rand(len(gid_list), 2)
        new_gps_list[:, 0] = (new_gps_list[:, 0] * valid_lat_range) + valid_lat_min
        new_gps_list[:, 1] = (new_gps_list[:, 1] * valid_lon_range) + valid_lon_min
        new_gps_list[8, :] = [-1, -1]
        ibs.set_image_gps(gid_list, new_gps_list)

        # TODO: add a nan timestamp
        ibs.append_annot_case_tags([2], ['error:bbox'])
        ibs.append_annot_case_tags([4], ['quality:washedout'])
        ibs.append_annot_case_tags([4], ['lighting'])

        aidgroups = ibs.group_annots_by_name(
            ibs.filter_annots_general(min_pername=2, verbose=True))[0]
        aid1_list = ut.take_column(aidgroups, 0)
        aid2_list = ut.take_column(aidgroups, 1)
        annotmatch_rowids = ibs.add_annotmatch(aid1_list, aid2_list)

        ibs.set_annotmatch_truth(annotmatch_rowids, [True] * len(annotmatch_rowids))
        ibs.set_annotmatch_truth(annotmatch_rowids, [True] * len(annotmatch_rowids))
        ibs.set_annotmatch_prop('photobomb', annotmatch_rowids, [True] * len(annotmatch_rowids))

        for aids in aidgroups:
            pass

        return None