Exemplo n.º 1
0
def run_trackers(trackers, seqs, evalType):
    tmpRes_path = RESULT_SRC.format('tmp/{0}/'.format(evalType))
    if not os.path.exists(tmpRes_path):
        os.makedirs(tmpRes_path)

    numSeq = len(seqs)

    trackerResults = dict((t, list()) for t in trackers)
    ##################################################
    # chose sequence to run from below
    ##################################################
    for idxSeq in range(24, numSeq):
        s = seqs[idxSeq]
        subSeqs, subAnno = butil.get_sub_seqs(s, 20.0, evalType)

        for idxTrk in range(len(trackers)):
            t = trackers[idxTrk]

            if not OVERWRITE_RESULT:

                trk_src = os.path.join(RESULT_SRC.format(evalType), t.name)
                result_src = os.path.join(trk_src, s.name + '.json')
                if os.path.exists(result_src):
                    seqResults = butil.load_seq_result(evalType, t, s.name)
                    trackerResults[t].append(seqResults)
                    continue
            seqResults = []
            seqLen = len(subSeqs)
            for idx in range(seqLen):
                print('{0}_{1}, {2}_{3}:{4}/{5} - {6}'.format(
                    idxTrk + 1, t.name, idxSeq + 1, s.name, idx + 1, seqLen,
                    evalType))
                subS = subSeqs[idx]
                subS.name = s.name + '_' + str(idx)
                ####################
                t, res = run_KCF_variant(t, subS)
                ####################
                r = Result(t.name, s.name, subS.startFrame, subS.endFrame,
                           res['type'], evalType, res['res'], res['fps'], None)
                try:
                    r.tmplsize = res['tmplsize'][0]
                except:
                    pass
                r.refresh_dict()
                seqResults.append(r)
            # end for subseqs
            if SAVE_RESULT:
                butil.save_seq_result(seqResults)

            trackerResults[t].append(seqResults)
            # end for tracker
    # end for allseqs
    return trackerResults
Exemplo n.º 2
0
def run_trackers(trackers, seqs, evalType, shiftTypeSet):
    """ Runs a set of trackers in a set of sequences according to the given
    evaluation protocol (evalType).

    Args:
        trackers: A list with all the names of trackers to be used.
        seqs: A list with all the sequences to be evaluated in.
        evalType: The evaluation protocol ['OPE', 'SRE' or 'TRE']
        shiftTypeSet: The list with the shifts to be applied in the SRE
            protocol. Generally defined in the config file.

    Returns:
        trackerResults:

    """
    # Get the path to the results folder for the current evalType
    tmpRes_path = RESULT_SRC.format('tmp/{0}/'.format(evalType))
    if not os.path.exists(tmpRes_path):
        os.makedirs(tmpRes_path)

    numSeq = len(seqs)
    numTrk = len(trackers)

    # print("Run trackers")
    # pdb.set_trace()
    trackerResults = dict((t, list()) for t in trackers)
    # for idxSeq in range(numSeq):
    for idxSeq, s in enumerate(seqs):
        # s = seqs[idxSeq]
        subSeqs, subAnno = seq_config.get_sub_seqs(s, 20.0, evalType)
        for idxTrk, t in enumerate(trackers):
            # t = trackers[idxTrk]
            if not os.path.exists(TRACKER_SRC + t):
                print('{0} does not exists'.format(t))
                sys.exit(1)
            if not OVERWRITE_RESULT:
                trk_src = os.path.join(RESULT_SRC.format(evalType), t)
                result_src = os.path.join(trk_src, s.name + '.json')
                # Checks if the result file already exists for the given tracker
                # and sequence. If it exists it loads it and exits the loop.
                if os.path.exists(result_src):
                    seqResults = load_results.load_seq_result(
                        evalType, t, s.name)
                    trackerResults[t].append(seqResults)
                    continue
            seqResults = []
            seqLen = len(subSeqs)
            # print("Is this executing?")
            # pdb.set_trace()
            for idx in range(seqLen):
                print('{0}_{1}, {2}_{3}:{4}/{5} - {6}'.format(
                    idxTrk + 1, t, idxSeq + 1, s.name, idx + 1, seqLen,
                    evalType))
                rp = tmpRes_path + '_' + t + '_' + str(idx + 1) + '/'
                if SAVE_IMAGE and not os.path.exists(rp):
                    os.makedirs(rp)
                subS = subSeqs[idx]
                subS.name = s.name + '_' + str(idx)

                os.chdir(TRACKER_SRC + t)
                funcName = 'run_{0}(subS, rp, SAVE_IMAGE)'.format(t)
                try:
                    res = eval(funcName)
                except:
                    print('failed to execute {0} : {1}'.format(
                        t, sys.exc_info()))
                    os.chdir(WORKDIR)
                    break
                os.chdir(WORKDIR)

                if evalType == 'SRE':
                    r = Result(t, s.name, subS.startFrame, subS.endFrame,
                               res['type'], evalType, res['res'], res['fps'],
                               shiftTypeSet[idx])
                else:
                    r = Result(t, s.name, subS.startFrame, subS.endFrame,
                               res['type'], evalType, res['res'], res['fps'],
                               None)
                try:
                    r.tmplsize = extra.d_to_f(res['tmplsize'][0])
                except:
                    pass
                # print("What is r")
                # pdb.set_trace()
                r.refresh_dict()
                seqResults.append(r)
            # end for subseqs
            if SAVE_RESULT:
                # print("Main file trace")
                # pdb.set_trace()
                load_results.save_seq_result(seqResults)

            trackerResults[t].append(seqResults)
        # end for tracker
    # end for allseqs
    return trackerResults
Exemplo n.º 3
0
def run_trackers(trackers, seqs, evalType, shiftTypeSet):
    tmpRes_path = RESULT_SRC.format('tmp/{0}/'.format(evalType))
    if not os.path.exists(tmpRes_path):
        os.makedirs(tmpRes_path)

    numSeq = len(seqs)
    numTrk = len(trackers)

    trackerResults = dict((t, list()) for t in trackers)
    for idxSeq in range(numSeq):
        s = seqs[idxSeq]

        subSeqs, subAnno = get_sub_seqs(s, 20.0, evalType)

        for idxTrk in range(len(trackers)):
            t = trackers[idxTrk]
            if not OVERWRITE_RESULT:
                trk_src = os.path.join(RESULT_SRC.format(evalType), t)
                result_src = os.path.join(trk_src, s.name + '.json')
                if os.path.exists(result_src):
                    seqResults = load_seq_result(evalType, t, s.name)
                    trackerResults[t].append(seqResults)
                    continue
            seqResults = []
            seqLen = len(subSeqs)
            for idx in range(seqLen):
                print('{0}_{1}, {2}_{3}:{4}/{5} - {6}'.format(
                    idxTrk + 1, t, idxSeq + 1, s.name, idx + 1, seqLen, evalType))
                rp = tmpRes_path + '_' + t + '_' + str(idx + 1) + '/'
                if SAVE_IMAGE and not os.path.exists(rp):
                    os.makedirs(rp)
                subS = subSeqs[idx]
                subS.name = s.name + '_' + str(idx)

                move_dir = False
                if os.path.exists(os.path.join(TRACKER_SRC, t)):
                    move_dir = True
                    os.chdir(os.path.join(TRACKER_SRC, t))
                funcName = 'run_{0}(subS, rp, SAVE_IMAGE)'.format(t)
                try:
                    res = eval(funcName)
                except:
                    print('failed to execute {0} : {1}'.format(
                        t, sys.exc_info()))
                    if move_dir:
                        os.chdir(WORKDIR)
                    break
                if move_dir:
                    os.chdir(WORKDIR)

                if evalType == 'SRE':
                    r = Result(t, s.name, subS.startFrame, subS.endFrame,
                               res['type'], evalType, res['res'], res['fps'], shiftTypeSet[idx])
                else:
                    r = Result(t, s.name, subS.startFrame, subS.endFrame,
                               res['type'], evalType, res['res'], res['fps'], None)
                try:
                    r.tmplsize = res['tmplsize'][0]
                except:
                    pass
                r.refresh_dict()
                seqResults.append(r)
            # end for subseqs
            if SAVE_RESULT:
                save_seq_result(seqResults)

            trackerResults[t].append(seqResults)
        # end for tracker
    # end for allseqs
    return trackerResults