def load_result(evalType, tracker): resultSRC = RESULT_SRC.format(evalType) print('Loading \'{0}\'...'.format(tracker), end=' ') src = os.path.join(resultSRC, tracker) resultNames = os.listdir(src) attrs = [] results = [] for name in resultNames: if name == 'attributes': attrSrc = os.path.join(src, name) attrNames = os.listdir(attrSrc) for attrName in attrNames: attrFile = open(os.path.join(attrSrc, attrName)) string = attrFile.read() j = json.loads(string) attr = Attribute(**j) attr.successRateList = [o * 100 for o in attr.successRateList] attrs.append(attr) attrs.sort() elif name.endswith('.json'): resultFile = open(os.path.join(src, name)) string = resultFile.read() jsonList = json.loads(string) if type(jsonList) is list: results.append([Result(**j) for j in jsonList]) elif type(jsonList) is dict: results.append([Result(**jsonList)]) print('({0} seqs)'.format(len(resultNames) - 1)) return results, attrs
def load_seq_result(result_src): resultFile = open(result_src) string = resultFile.read() jsonList = json.loads(string) if type(jsonList) is list: return [Result(**j) for j in jsonList] elif type(jsonList) is dict: return [Result(**jsonList)] return None
def load_seq_result(evalType, tracker, sequence): resultSRC = RESULT_SRC.format(evalType) print('Loading {0}/{1}...'.format(tracker, sequence)) src = os.path.join(resultSRC, tracker) result_src = os.path.join(src, sequence + '.json') resultFile = open(result_src) string = resultFile.read() jsonList = json.loads(string) if type(jsonList) is list: return [Result(**j) for j in jsonList] elif type(jsonList) is dict: return [Result(**jsonList)] return None
def run_trackers(tracker, seqs, evalType): numSeq = len(seqs) seqResults = [] ################################################## # chose sequence to run from below ################################################## for idxSeq in range(0, numSeq): subS = seqs[idxSeq] print('{0}:{1}, total frame: {2}'.format( idxSeq + 1, subS.name, subS.endFrame - subS.startFrame)) if not OVERWRITE_RESULT: trk_src = os.path.join(RESULT_SRC.format(evalType), tracker.name) result_src = os.path.join(trk_src, subS.name + '.json') if os.path.exists(result_src): r = UAV_script.load_seq_result(result_src) seqResults.append(r) continue #################### # we only re-run tracker with target size small than a threshold: tracker, res = run_KCF_variant(tracker, subS, debug=False) r = Result(tracker.name, subS.name, subS.startFrame, subS.endFrame, res['type'], evalType, res['res'], res['fps'], None) r.refresh_dict() seqResults.append(r) # end for subseqs if SAVE_RESULT: UAV_script.save_seq_result(RESULT_SRC, r) return seqResults
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(25, numSeq): s = seqs[idxSeq] subSeqs, subAnno = butil.get_sub_seqs(s, 20.0, evalType) for idxTrk in range(len(trackers)): t = trackers[idxTrk] seqLen = len(subSeqs) for idx in range(seqLen): subS = subSeqs[idx] subS.name = s.name + '_' + str(idx) #################### r_temp = Result(t.name, s.name, subS.startFrame, subS.endFrame, [], evalType, [], [], None) # if np.min(s.gtRect[0][2:])<12: # print(s.name) t, res = run_KCF_variant(t, subS, r_temp, debug=True) #################### # end for tracker # end for allseqs return trackerResults
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
def main(): parser = argparse.ArgumentParser() parser.add_argument("-s", "--sequence", default="Basketball") parser.add_argument("-e", "--evaltype", default="OPE") parser.add_argument("-t", "--tracker", default="ALL") parser.add_argument("--save", action='store_true', default=False) args = parser.parse_args() #assert args.evaltype in ["OPE", "SRE", "TRE"], "Invalid evaltype: {}".format(args.evaltype) base_src = RESULT_SRC.format(args.evaltype) trackers = os.listdir(base_src) assert args.tracker == "ALL" or args.tracker in trackers, "Invalid tracker: {}".format( args.tracker) selected_trackers = [args.tracker] if args.tracker == "ALL": selected_trackers = trackers results = OrderedDict() start_frame = None seq = None for t in selected_trackers: src = os.path.join(base_src, t) seq_name = [ x for x in os.listdir(src) if x == "{}.json".format(args.sequence) ][0] with open(os.path.join(src, seq_name)) as fh: j = json.load(fh) result = Result(**j[0]) if not start_frame: start_frame = result.startFrame elif start_frame != result.startFrame: print("Skipping {} due to incompatible start_frame".format(t)) continue if not seq: seq = load_seq_config(result.seqName) elif seq.name != result.seqName: print("Skipping {} due to incompatible sequence".format(t)) continue results[t] = result.res view_result(seq, results, start_frame, args.save)
def run_trackers(tracker, seqs, evalType): numSeq = len(seqs) seqResults = [] ################################################## # chose sequence to run from below ################################################## for idxSeq in range(68, numSeq): subS = seqs[idxSeq] print('{0}:{1}, total frame: {2}'.format( idxSeq + 1, subS.name, subS.endFrame - subS.startFrame)) #################### tracker, res = run_KCF_variant(tracker, subS, debug=True) #################### r = Result(tracker.name, subS.name, subS.startFrame, subS.endFrame, res['type'], evalType, res['res'], res['fps'], None) r.refresh_dict() seqResults.append(r) # end for subseqs return seqResults
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(12, 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 seqLen = len(subSeqs) for idx in range(seqLen): subS = subSeqs[idx] subS.name = s.name + '_' + str(idx) #################### r_temp = Result(t.name, s.name, subS.startFrame, subS.endFrame, [], evalType, [], [], None) t, res = run_KCF_variant(t, subS, r_temp) return 0 #################### # end for tracker # end for allseqs return trackerResults
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
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