Exemplo n.º 1
0
def get_annot_alrids_oftype(ibs, aid_list, lbltype_rowid, configid=None):
    """
    Get all the relationship ids belonging to the input annotations where the
    relationship ids are filtered to be only of a specific lbltype/category/type
    """
    alrids_list = ibs.get_annot_alrids(aid_list, configid=configid)
    # Get lblannot_rowid of each relationship
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    # Get the type of each lblannot
    lbltype_rowids_list = ibsfuncs.unflat_map(ibs.get_lblannot_lbltypes_rowids, lblannot_rowids_list)
    # only want the nids of individuals, not species, for example
    valids_list = [[typeid == lbltype_rowid for typeid in rowids] for rowids in lbltype_rowids_list]
    alrids_list = [ut.compress(alrids, valids) for alrids, valids in zip(alrids_list, valids_list)]
    if configid is None:
        def resolution_func_first(alrid_list):
            return [ alrid_list[0] ]

        def resolution_func_lowest_config(alrid_list):
            config_rowid_list = ibs.get_alr_config(alrid_list)
            temp = sorted(list(zip(config_rowid_list, alrid_list)))
            return [ temp[0][0] ]

        alrids_list = [
            resolution_func_first(alrid_list)
            if len(alrid_list) > 1 else
            alrid_list
            for alrid_list in alrids_list
        ]
    assert all([len(alrid_list) < 2 for alrid_list in alrids_list]),\
        ("More than one type per lbltype.  ALRIDS: " + str(alrids_list) +
         ", ROW: " + str(lbltype_rowid) + ", KEYS:" + str(ibs.lbltype_ids))
    return alrids_list
Exemplo n.º 2
0
def get_annot_alrids_oftype(ibs, aid_list, lbltype_rowid):
    """
    Get all the relationship ids belonging to the input annotations where the
    relationship ids are filtered to be only of a specific lbltype/category/type
    """
    alrids_list = ibs.get_annot_alrids(aid_list)
    # Get lblannot_rowid of each relationship
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    # Get the type of each lblannot
    lbltype_rowids_list = ibsfuncs.unflat_map(ibs.get_lblannot_lbltypes_rowids,
                                              lblannot_rowids_list)
    # only want the nids of individuals, not species, for example
    valids_list = [[typeid == lbltype_rowid for typeid in rowids]
                   for rowids in lbltype_rowids_list]
    alrids_list = [ut.compress(alrids, valids)
                   for alrids, valids in zip(alrids_list, valids_list)]
    def resolution_func_first(alrid_list):
        return [ alrid_list[0] ]

    alrids_list = [
        resolution_func_first(alrid_list)
        if len(alrid_list) > 1 else
        alrid_list
        for alrid_list in alrids_list
    ]
    assert all([len(alrid_list) < 2 for alrid_list in alrids_list]),\
        ("More than one type per lbltype.  ALRIDS: " + str(alrids_list) +
         ", ROW: " + str(lbltype_rowid) + ", KEYS:" + str(ibs.lbltype_ids))
    return alrids_list
Exemplo n.º 3
0
def tst_name_consistency(ibs):
    """
    Example:
        >>> import ibeis
        >>> ibs = ibeis.opendb(db='PZ_Master0')
        >>> #ibs = ibeis.opendb(db='GZ_ALL')

    """
    from ibeis.other import ibsfuncs
    import utool as ut
    max_ = -1
    #max_ = 10
    valid_aids = ibs.get_valid_aids()[0:max_]
    valid_nids = ibs.get_valid_nids()[0:max_]
    ax2_nid = ibs.get_annot_name_rowids(valid_aids)
    nx2_aids = ibs.get_name_aids(valid_nids)

    print('len(valid_aids) = %r' % (len(valid_aids),))
    print('len(valid_nids) = %r' % (len(valid_nids),))
    print('len(ax2_nid) = %r' % (len(ax2_nid),))
    print('len(nx2_aids) = %r' % (len(nx2_aids),))

    # annots are grouped by names, so mapping aid back to nid should
    # result in each list having the same value
    _nids_list = ibsfuncs.unflat_map(ibs.get_annot_name_rowids, nx2_aids)
    print(_nids_list[-20:])
    print(nx2_aids[-20:])
    assert all(map(ut.allsame, _nids_list))
Exemplo n.º 4
0
def get_name_exemplar_aids(ibs, nid_list):
    r"""
    Returns:
        list_ (list):  a list of list of cids in each name


    CommandLine:
        python -m ibeis.control.manual_name_funcs --test-get_name_exemplar_aids

    RESTful:
        Method: GET
        URL:    /api/name/exemplar_aids/

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.control.manual_name_funcs import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> aid_list = ibs.get_valid_aids()
        >>> nid_list = ibs.get_annot_name_rowids(aid_list)
        >>> exemplar_aids_list = ibs.get_name_exemplar_aids(nid_list)
        >>> result = exemplar_aids_list
        >>> print(result)
        [[], [2, 3], [2, 3], [], [5, 6], [5, 6], [7], [8], [], [10], [], [12], [13]]
    """
    # Get all annot ids for each name
    aids_list = ibs.get_name_aids(nid_list, enable_unknown_fix=True)
    # Flag any annots that are not exemplar and remove them
    flags_list = ibsfuncs.unflat_map(ibs.get_annot_exemplar_flags, aids_list)
    exemplar_aids_list = [ut.compress(aids, flags) for aids, flags in
                          zip(aids_list, flags_list)]
    return exemplar_aids_list
Exemplo n.º 5
0
def compute_occurrence_unixtime(ibs, occur_gids):
    #assert isinstance(ibs, IBEISController)
    # TODO: account for -1
    from ibeis.other import ibsfuncs
    unixtimes = ibsfuncs.unflat_map(ibs.get_image_unixtime, occur_gids)
    time_arrs = list(map(np.array, unixtimes))
    occur_unixtimes = list(map(np.mean, time_arrs))
    return occur_unixtimes
Exemplo n.º 6
0
def get_annot_lblannot_rowids(ibs, aid_list):
    """
    Returns:
        list_ (list): the name id of each annotation. """
    # Get all the annotation lblannot relationships
    # filter out only the ones which specify names
    alrids_list = ibs.get_annot_alrids(aid_list)
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    return lblannot_rowids_list
Exemplo n.º 7
0
def get_annot_lblannot_rowids(ibs, aid_list):
    """
    Returns:
        list_ (list): the name id of each annotation. """
    # Get all the annotation lblannot relationships
    # filter out only the ones which specify names
    alrids_list = ibs.get_annot_alrids(aid_list)
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    return lblannot_rowids_list
Exemplo n.º 8
0
def compute_occurrence_unixtime(ibs, occur_gids):
    # assert isinstance(ibs, IBEISController)
    # TODO: account for -1
    from ibeis.other import ibsfuncs

    unixtimes = ibsfuncs.unflat_map(ibs.get_image_unixtime, occur_gids)
    time_arrs = list(map(np.array, unixtimes))
    occur_unixtimes = list(map(np.mean, time_arrs))
    return occur_unixtimes
Exemplo n.º 9
0
def get_annot_lblannot_rowids_oftype(ibs, aid_list, _lbltype=None):
    """
    Returns:
        list_ (list): the name id of each annotation. """
    # Get all the annotation lblannot relationships
    # filter out only the ones which specify names
    assert _lbltype is not None, 'should be using lbltype_rowids anyway'
    alrids_list = ibs.get_annot_alrids_oftype(aid_list, ibs.lbltype_ids[_lbltype])
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    return lblannot_rowids_list
Exemplo n.º 10
0
def get_annot_lblannot_rowids_oftype(ibs, aid_list, _lbltype=None):
    """
    Returns:
        list_ (list): the name id of each annotation. """
    # Get all the annotation lblannot relationships
    # filter out only the ones which specify names
    assert _lbltype is not None, 'should be using lbltype_rowids anyway'
    alrids_list = ibs.get_annot_alrids_oftype(aid_list, ibs.lbltype_ids[_lbltype])
    lblannot_rowids_list = ibsfuncs.unflat_map(ibs.get_alr_lblannot_rowids, alrids_list)
    return lblannot_rowids_list
Exemplo n.º 11
0
def get_name_gids(ibs, nid_list):
    r"""
    Returns:
        list_ (list): the image ids associated with name ids

    RESTful:
        Method: GET
        URL:    /api/name/gids/

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.control.manual_name_funcs import *  # NOQA
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> nid_list = ibs._get_all_known_name_rowids()
        >>> gids_list = ibs.get_name_gids(nid_list)
        >>> result = gids_list
        >>> print(result)
        [[2, 3], [5, 6], [7], [8], [10], [12], [13]]
    """
    # TODO: Optimize
    aids_list = ibs.get_name_aids(nid_list, enable_unknown_fix=True)
    gids_list = ibsfuncs.unflat_map(ibs.get_annot_gids, aids_list)
    return gids_list
Exemplo n.º 12
0
def TEST_IMAGESETS(ibs):
    print('[TEST_IMAGESETS]')
    assert isinstance(ibs, IBEISController), 'type enforment'
    # Delete all imagesets
    _imgsetid_list1 = ibs.get_valid_imgsetids()
    ibs.delete_imagesets(_imgsetid_list1)
    _imgsetid_list2 = ibs.get_valid_imgsetids()
    assert len(_imgsetid_list2) == 0, 'imgsetids should have been deleted'
    # Recompute imagesets
    ibs.compute_occurrences()

    imgsetid_list = sorted(ibs.get_valid_imgsetids())
    gids_list = ibs.get_imageset_gids(imgsetid_list)
    aids_list = ibs.get_imageset_aids(imgsetid_list)
    nids_list = ibs.get_imageset_nids(imgsetid_list)

    imagesettext_list   = ibs.get_imageset_text(imgsetid_list)
    gid_uuids_list = list(map(list, ibsfuncs.unflat_map(ibs.get_image_uuids, gids_list)))
    annotation_uuids_list = list(map(list, ibsfuncs.unflat_map(ibs.get_annot_uuids, aids_list)))
    names_list     = list(map(list, ibsfuncs.unflat_map(ibs.get_name_texts, nids_list)))

    #target_imagesettexts = ['E0_ENC(agg,sec_60,1)', 'E1_ENC(agg,sec_60,1)']
    target_imagesettexts = [u'ImageSet 0', u'ImageSet 1']

    target_gid_uuids = [[UUID('66ec193a-1619-b3b6-216d-1784b4833b61'),
                         UUID('d8903434-942f-e0f5-d6c2-0dcbe3137bf7'),
                         UUID('b73b72f4-4acb-c445-e72c-05ce02719d3d'),
                         UUID('0cd05978-3d83-b2ee-2ac9-798dd571c3b3'),
                         UUID('0a9bc03d-a75e-8d14-0153-e2949502aba7'),
                         UUID('2deeff06-5546-c752-15dc-2bd0fdb1198a'),
                         UUID('a9b70278-a936-c1dd-8a3b-bc1e9a998bf0')],
                        [UUID('42fdad98-369a-2cbc-67b1-983d6d6a3a60'),
                         UUID('c459d381-fd74-1d99-6215-e42e3f432ea9'),
                         UUID('33fd9813-3a2b-774b-3fcc-4360d1ae151b'),
                         UUID('97e8ea74-873f-2092-b372-f928a7be30fa'),
                         UUID('588bc218-83a5-d400-21aa-d499832632b0'),
                         UUID('163a890c-36f2-981e-3529-c552b6d668a3')],
                        ]

    target_name_texts = [
        ['easy', 'hard', 'jeff'],
        ['lena', 'occl', 'polar', 'zebra'],
    ]

    ibs.print_lblannot_table()
    ibs.print_egpairs_table()
    ibs.print_imageset_table()
    ibs.print_alr_table()
    gids_test_list = ibsfuncs.unflat_map(ibs.get_image_gids_from_uuid, gid_uuids_list)
    gids_target_list = ibsfuncs.unflat_map(ibs.get_image_gids_from_uuid, target_gid_uuids)
    try:
        print('0) gid_uuids_list = %s' % (utool.list_str(gids_test_list),))
        print('0) target_gid_uuids = %s' % (utool.list_str(gids_target_list),))
        print('')
        print('1) gid_uuids_list = %s' % (utool.list_str(gid_uuids_list),))
        print('1) target_gid_uuids = %s' % (utool.list_str(target_gid_uuids),))
        print('')
        print('2) imagesettext_list = %r' % (imagesettext_list,))
        print('2) target_imagesettexts = %r' % (target_imagesettexts,))
        print('')

        aids_test_list = ibsfuncs.unflat_map(ibs.get_image_aids, gids_test_list)
        aids_target_list = ibsfuncs.unflat_map(ibs.get_image_aids, gids_target_list)
        print('a) aids_test_list = %s' % (utool.list_str(aids_test_list),))
        print('a) aids_target_list = %s' % (utool.list_str(aids_target_list),))

        print('3a) aids_list = %s' % (utool.list_str(aids_list),))
        print('3a) nids_list = %s' % (utool.list_str(nids_list),))
        nids_listb = [ ibs.get_annot_name_rowids(aid_list) for aid_list in aids_list ]
        print('3a) nids_listb = %s' % (utool.list_str(nids_listb),))
        print('3b) names_list = %s' % (utool.list_str(names_list),))
        print('3b) target_name_texts = %s' % (utool.list_str(target_name_texts),))
        print('')

        assert gids_test_list == gids_target_list, 'gids_test_list does not match gids_target_list'

        assert gid_uuids_list == target_gid_uuids, 'gid_uuids_list does not match target_gid_uuids'

        assert imagesettext_list == target_imagesettexts, 'imagesettext_list does not match target_imagesettexts'

        assert names_list == target_name_texts, 'names_list does not match target_name_texts'

    except AssertionError as ex:
        utool.printex(ex, 'failed test_imageset')
        raise

    gids_list2 = list(map(list, ibsfuncs.unflat_map(ibs.get_annot_gids, aids_list)))
    assert gids_list2 == list(map(list, gids_list))

    return locals()