コード例 #1
0
ファイル: automated_matcher.py プロジェクト: whaozl/ibeis
def run_until_name_decision_signal(ibs, cm, qreq_, incinfo=None):
    r"""
    DECISION STEP 1)

    Either the system or the user makes a decision about the name of the query
    annotation.

    CommandLine:
        python -m ibeis.algo.hots.automated_matcher --test-run_until_name_decision_signal

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.automated_matcher import *  # NOQA
        >>> ibs, qaid_chunk = testdata_automatch()
        >>> exemplar_aids = ibs.get_valid_aids(is_exemplar=True)
        >>> incinfo = {}
        >>> gen = generate_subquery_steps(ibs, qaid_chunk, incinfo)
        >>> item = six.next(gen)
        >>> ibs, cm, qreq_, incinfo = item
        >>> # verify results
        >>> run_until_name_decision_signal(ibs, cm, qreq_, incinfo)

    Ignore::
        cm.ishow_top(ibs, sidebyside=False, show_query=True)
    """
    print('--- Identifying Query Animal ---')
    qaid = cm.qaid
    choicetup = automatch_suggestor.get_qres_name_choices(ibs, cm)
    name_suggest_tup = get_name_suggestion(ibs, qaid, choicetup, incinfo)
    # Have the system ask the user if it is not confident in its decision
    autoname_msg, chosen_names, name_confidence = name_suggest_tup
    print('autoname_msg=')
    print(autoname_msg)
    print('... checking confidence=%r in name decision.' % (name_confidence, ))
    if name_confidence < incinfo.get('name_confidence_thresh', 1.0):
        print('... confidence is too low. need user input')
        if incinfo.get('interactive', False):
            print('... asking user for input')
            if qreq_.normalizer is not None:
                VIZ_SCORE_NORM = False
                #VIZ_SCORE_NORM = ut.is_developer()
                if VIZ_SCORE_NORM:
                    qreq_.normalizer.visualize(fnum=511, verbose=False)
            user_dialogs.wait_for_user_name_decision(ibs,
                                                     cm,
                                                     qreq_,
                                                     choicetup,
                                                     name_suggest_tup,
                                                     incinfo=incinfo)
        else:
            run_until_finish(incinfo=incinfo)
            print('... cannot ask user for input. doing nothing')
    else:
        print('... confidence is above threshold. Making decision')
        #return ('CALLBACK', chosen_names)
        name_decision_callback = incinfo['name_decision_callback']
        name_decision_callback(chosen_names)
コード例 #2
0
ファイル: automated_matcher.py プロジェクト: Erotemic/ibeis
def run_until_name_decision_signal(ibs, cm, qreq_, incinfo=None):
    r"""
    DECISION STEP 1)

    Either the system or the user makes a decision about the name of the query
    annotation.

    CommandLine:
        python -m ibeis.algo.hots.automated_matcher --test-run_until_name_decision_signal

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.automated_matcher import *  # NOQA
        >>> ibs, qaid_chunk = testdata_automatch()
        >>> exemplar_aids = ibs.get_valid_aids(is_exemplar=True)
        >>> incinfo = {}
        >>> gen = generate_subquery_steps(ibs, qaid_chunk, incinfo)
        >>> item = six.next(gen)
        >>> ibs, cm, qreq_, incinfo = item
        >>> # verify results
        >>> run_until_name_decision_signal(ibs, cm, qreq_, incinfo)

    Ignore::
        cm.ishow_top(ibs, sidebyside=False, show_query=True)
    """
    print('--- Identifying Query Animal ---')
    qaid = cm.qaid
    choicetup = automatch_suggestor.get_qres_name_choices(ibs, cm)
    name_suggest_tup = get_name_suggestion(ibs, qaid, choicetup, incinfo)
    # Have the system ask the user if it is not confident in its decision
    autoname_msg, chosen_names, name_confidence = name_suggest_tup
    print('autoname_msg=')
    print(autoname_msg)
    print('... checking confidence=%r in name decision.' % (name_confidence,))
    if name_confidence < incinfo.get('name_confidence_thresh', 1.0):
        print('... confidence is too low. need user input')
        if incinfo.get('interactive', False):
            print('... asking user for input')
            if qreq_.normalizer is not None:
                VIZ_SCORE_NORM = False
                #VIZ_SCORE_NORM = ut.is_developer()
                if VIZ_SCORE_NORM:
                    qreq_.normalizer.visualize(fnum=511, verbose=False)
            user_dialogs.wait_for_user_name_decision(ibs, cm, qreq_, choicetup,
                                                     name_suggest_tup,
                                                     incinfo=incinfo)
        else:
            run_until_finish(incinfo=incinfo)
            print('... cannot ask user for input. doing nothing')
    else:
        print('... confidence is above threshold. Making decision')
        #return ('CALLBACK', chosen_names)
        name_decision_callback = incinfo['name_decision_callback']
        name_decision_callback(chosen_names)
コード例 #3
0
ファイル: automated_matcher.py プロジェクト: Erotemic/ibeis
def update_normalizer(ibs, cm, qreq_, chosen_names):
    r"""
    adds new support data to the current normalizer

    FIXME: broken

    Args:
        ibs (IBEISController):  ibeis controller object
        qreq_ (QueryRequest):  query request object with hyper-parameters
        choicetup (?):
        name (?):

    Returns:
        tuple: (tp_rawscore, tn_rawscore)

    CommandLine:
        python -m ibeis.algo.hots.automated_matcher --test-update_normalizer

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.automated_matcher import *  # NOQA
        >>> ibs, qaid_chunk = testdata_automatch()
        >>> exemplar_aids = ibs.get_valid_aids(is_exemplar=True)
        >>> incinfo = {}
        >>> gen = generate_subquery_steps(ibs, qaid_chunk, incinfo)
        >>> item = six.next(gen)
        >>> ibs, cm, qreq_, incinfo = item
        >>> qreq_.load_score_normalizer()
        >>> # verify results
        >>> chosen_names = ['easy']
        >>> update_normalizer(ibs, cm, qreq_, chosen_names)
    """
    # Fixme: duplicate call to get_qres_name_choices
    if qreq_.normalizer is None:
        print('[update_normalizer] NOT UPDATING. qreq_ has not loaded a score normalizer')
        return
    if len(chosen_names) != 1:
        print('[update_normalizer] NOT UPDATING. only updates using simple matches')
        return
    qaid = cm.qaid
    choicetup = automatch_suggestor.get_qres_name_choices(ibs, cm)
    (sorted_nids, sorted_nscore, sorted_rawscore, sorted_aids, sorted_ascores) = choicetup
    # Get new True Negative support data for score normalization
    name = chosen_names[0]
    rank = ut.listfind(ibs.get_name_texts(sorted_nids), name)
    if rank is None:
        return
    nid = sorted_nids[rank]
    tp_rawscore = sorted_rawscore[rank]
    valid_falseranks = set(range(len(sorted_rawscore))) - set([rank])
    if len(valid_falseranks) > 0:
        tn_rank = min(valid_falseranks)
        tn_rawscore = sorted_rawscore[tn_rank][0]
    else:
        tn_rawscore = None
    #return tp_rawscore, tn_rawscore
    canupdate = tp_rawscore is not None and tn_rawscore is not None
    if canupdate:
        # TODO: UPDATE SCORE NORMALIZER HERE
        print('UPDATING! NORMALIZER')
        tp_labels = [ut.deterministic_uuid((qaid, nid))]
        tn_labels = [ut.deterministic_uuid((qaid, nid))]
        print('new normalization example: tp_rawscore={}, tn_rawscore={}'.format(tp_rawscore, tn_rawscore))
        print('new normalization example: tp_labels={}, tn_labels={}'.format(tp_labels, tn_labels))
        tp_scores = [tp_rawscore]
        tn_scores = [tn_rawscore]
        qreq_.normalizer.add_support(tp_scores, tn_scores, tp_labels, tn_labels)
        qreq_.normalizer.retrain()
        species_text = '_'.join(qreq_.get_unique_species())  # HACK
        # TODO: figure out where to store normalizer
        qreq_.normalizer.save(ibs.get_local_species_scorenorm_cachedir(species_text))
    else:
        print('NOUPDATE! cannot update score normalization')
コード例 #4
0
ファイル: automated_matcher.py プロジェクト: whaozl/ibeis
def update_normalizer(ibs, cm, qreq_, chosen_names):
    r"""
    adds new support data to the current normalizer

    FIXME: broken

    Args:
        ibs (IBEISController):  ibeis controller object
        qreq_ (QueryRequest):  query request object with hyper-parameters
        choicetup (?):
        name (?):

    Returns:
        tuple: (tp_rawscore, tn_rawscore)

    CommandLine:
        python -m ibeis.algo.hots.automated_matcher --test-update_normalizer

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.automated_matcher import *  # NOQA
        >>> ibs, qaid_chunk = testdata_automatch()
        >>> exemplar_aids = ibs.get_valid_aids(is_exemplar=True)
        >>> incinfo = {}
        >>> gen = generate_subquery_steps(ibs, qaid_chunk, incinfo)
        >>> item = six.next(gen)
        >>> ibs, cm, qreq_, incinfo = item
        >>> qreq_.load_score_normalizer()
        >>> # verify results
        >>> chosen_names = ['easy']
        >>> update_normalizer(ibs, cm, qreq_, chosen_names)
    """
    # Fixme: duplicate call to get_qres_name_choices
    if qreq_.normalizer is None:
        print(
            '[update_normalizer] NOT UPDATING. qreq_ has not loaded a score normalizer'
        )
        return
    if len(chosen_names) != 1:
        print(
            '[update_normalizer] NOT UPDATING. only updates using simple matches'
        )
        return
    qaid = cm.qaid
    choicetup = automatch_suggestor.get_qres_name_choices(ibs, cm)
    (sorted_nids, sorted_nscore, sorted_rawscore, sorted_aids,
     sorted_ascores) = choicetup
    # Get new True Negative support data for score normalization
    name = chosen_names[0]
    rank = ut.listfind(ibs.get_name_texts(sorted_nids), name)
    if rank is None:
        return
    nid = sorted_nids[rank]
    tp_rawscore = sorted_rawscore[rank]
    valid_falseranks = set(range(len(sorted_rawscore))) - set([rank])
    if len(valid_falseranks) > 0:
        tn_rank = min(valid_falseranks)
        tn_rawscore = sorted_rawscore[tn_rank][0]
    else:
        tn_rawscore = None
    #return tp_rawscore, tn_rawscore
    canupdate = tp_rawscore is not None and tn_rawscore is not None
    if canupdate:
        # TODO: UPDATE SCORE NORMALIZER HERE
        print('UPDATING! NORMALIZER')
        tp_labels = [ut.deterministic_uuid((qaid, nid))]
        tn_labels = [ut.deterministic_uuid((qaid, nid))]
        print(
            'new normalization example: tp_rawscore={}, tn_rawscore={}'.format(
                tp_rawscore, tn_rawscore))
        print('new normalization example: tp_labels={}, tn_labels={}'.format(
            tp_labels, tn_labels))
        tp_scores = [tp_rawscore]
        tn_scores = [tn_rawscore]
        qreq_.normalizer.add_support(tp_scores, tn_scores, tp_labels,
                                     tn_labels)
        qreq_.normalizer.retrain()
        species_text = '_'.join(qreq_.get_unique_species())  # HACK
        # TODO: figure out where to store normalizer
        qreq_.normalizer.save(
            ibs.get_local_species_scorenorm_cachedir(species_text))
    else:
        print('NOUPDATE! cannot update score normalization')