def main(args): for model_result in os.listdir(args.detection_dir): detection_path = os.path.join(args.detection_dir, model_result) outdir = os.path.join(args.output_dir, model_result) if not os.path.exists(outdir): os.makedirs(outdir) dpaths = glob.glob(detection_path + '/*.txt') total_time = 0 total_frames = 0 for dpath in dpaths: detections = load_viva(dpath) name = os.path.basename(dpath) print("Processing %s." % (name[:-4])) start = time() tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min, start_idx=0) end = time() total_time += end - start total_frames += len(detections) save_to_csv(os.path.join(outdir, name), tracks) print("Model: %s Total Tracking took: %.3f for %d frames or %.1f FPS" % (model_result, total_time, total_frames, total_frames / total_time))
def main(args): detections = load_mot(args.detection_path) start = time() tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min) end = time() num_frames = len(detections) print("finished at " + str(int(num_frames / (end - start))) + " fps!") save_to_csv(args.output_path, tracks)
def main(args): formats = ["motchallenge", "visdrone"] assert ( args.format in formats), "format '{}' unknown supported formats are: {}".format( args.format, formats) with_classes = False if args.format == "visdrone": with_classes = True detections = load_mot( args.detection_path, nms_overlap_thresh=args.nms, with_classes=with_classes, min_short=args.min_short, max_short=args.max_short, max_long=args.max_long, ) if args.visual: tracks = track_viou( args.frames_path, detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min, args.ttl, args.visual, args.keep_upper_height_ratio, ) else: if with_classes: # track_viou can also be used without visual tracking, but note that the speed will be much slower compared # to track_iou. However, this way supports the optimal LAP solving and the handling of multiple object classes: tracks = track_viou( args.frames_path, detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min, args.ttl, "NONE", args.keep_upper_height_ratio, ) else: tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min) save_to_csv(args.output_path, tracks, fmt=args.format)
def _save(stock, date): data = util.collect_detail(stock, date, pause=1) if data is None: pfile = CONF.DATAFILENAME if not os.path.exists(pfile): os.mknod(pfile) util.append_to_pkl((stock, date), pfile) return if len(data) < 10: return data = util.data_adapter(date, data) filename = stock + ".csv" tmpfile = os.path.join(CONF.TMPFILEDIR, filename) util.save_to_csv(data, tmpfile)
def main(datasetPath): if 'Fluo-N2DL-HeLa' in datasetPath: mode = 'Fluo-N2DL-HeLa' elif 'PhC-C2DL-PSC' in datasetPath: mode = 'PhC-C2DL-PSC' else: mode = 'DIC-C2DH-HeLa' detPath = datasetPath.replace(r'/', '_') + '.txt' detAbsPath = os.path.join('det', detPath) genDets(datasetPath, mode) print('loading detections...') detections = load_mot(detAbsPath, nms_overlap_thresh=cfg.nms, with_classes=False) print('tracking...') tracks = track_iou(detections, cfg.sigma_l, cfg.sigma_h, cfg.sigma_iou, cfg.t_min, cfg.max_missing) save_to_csv(os.path.join(cfg.output_path, detPath), tracks, fmt=cfg.format)
def main(args): with open(args.seqmap) as fd: seqs = [line.rstrip('\n') for line in fd] for idx, seq in enumerate(seqs): if seq == "name" or seq == "": continue else: if "DPM" in seq: sigma_l = -0.5 sigma_h = 0.5 sigma_iou = 0.4 t_min = 4 elif "FRCNN" in seq: sigma_l = 0.0 sigma_h = 0.9 sigma_iou = 0.3 t_min = 3 elif "SDP" in seq: sigma_l = 0.4 sigma_h = 0.5 sigma_iou = 0.2 t_min = 2 else: print("No detector name found, this could happen with the " "wrong seqmap seqmap file. " "Please use c10-train.txt, c10-test.txt or c10-all.txt") exit() # Take the pre-computed detections. det_path = args.benchmark_dir + "/" + seq + "/det/det.txt" out_path = args.res_dir + "/" + seq + ".txt" detections = load_mot(det_path) start = time() tracks = track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min) end = time() num_frames = len(detections) print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!") save_to_csv(out_path, tracks)
def main(args): with open(args.seqmap) as fd: seqs = [line.rstrip('\n') for line in fd] for idx, seq in enumerate(seqs): if seq == "name" or seq == "": continue else: if "DPM" in seq: sigma_l = -0.5 sigma_h = 0.5 sigma_iou = 0.4 t_min = 4 elif "FRCNN" in seq: sigma_l = 0.0 sigma_h = 0.9 sigma_iou = 0.3 t_min = 3 elif "SDP" in seq: sigma_l = 0.4 sigma_h = 0.5 sigma_iou = 0.2 t_min = 2 else: print("No detector name found, this could happen with the wrong seqmap seqmap file. " "Please use c10-train.txt, c10-test.txt or c10-all.txt") exit() det_path = args.benchmark_dir + "/" + seq + "/det/det.txt" out_path = args.res_dir + "/" + seq + ".txt" detections = load_mot(det_path) start = time() tracks = track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min) end = time() num_frames = len(detections) print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!") save_to_csv(out_path, tracks)
def main(args): print('loading detections...') det_path = os.path.expanduser('~/') + args.detection_path detections = load_mot(det_path) print('tracking...') start = time() tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min) end = time() print("Finished Tracking", tracks) num_frames = len(detections) print("finished at " + str(int(num_frames / (end - start))) + " fps!") orig_out_path = os.path.expanduser('~/') + args.output_path save_to_csv(orig_out_path, tracks) out_path = os.path.expanduser('~/') + args.output_path + 'ordredfrm' if args.frameorder: #reading in all the data again for re-formatting idorder_frameorder(orig_out_path, out_path)
def main(args): with open(args.seqmap) as fd: seqs = [line.rstrip('\n') for line in fd] for idx, seq in enumerate(seqs): if seq == "name" or seq == "": continue else: det_path = args.benchmark_dir + "/" + seq + "/det/det.txt" out_path = args.res_dir + "/" + seq + ".txt" detections = load_mot(det_path, with_classes=False) start = time() tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min) end = time() num_frames = len(detections) print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!") save_to_csv(out_path, tracks)
def extractAnsTime(c, DIR, MODE, VERSION): if not os.path.exists(DIR + 'posts'): os.makedirs(DIR + 'posts') if MODE == 'FIRST': ans_time_first = query.firstAnsTime(c) util.save_to_csv(ans_time_first, header['ans_time_first'], 'posts/ans_time_first.csv') elif MODE == 'ACCEPTED': ans_time_accepted = pd.DataFrame(query.acceptAnsTime(c), columns=header['ans_time_accepted']) ans_time_accepted.to_csv(DIR + 'posts/ans_time_accepted.csv', index=False) elif MODE == 'UPVOTED': ans_time_upvoted = query.upvotedAnsTime(c) util.save_to_csv(ans_time_upvoted, header['ans_time_upvoted'], 'ans_time_upvoted.csv') if VERSION == 'EXTENDED': ans_time_upvoted_ex = query.upvotedAnsTime1(c) util.save_to_csv(ans_time_upvoted_ex, header['ans_time_upvoted_ex'], 'ans_time_upvoted_ex.csv')
def run(self): self.vc = cv2.VideoCapture(self.mot_video_dir) sigma_l = 0.4 sigma_h = 0.5 sigma_iou = 0.2 t_min = 2 # load bounding boxes. detections = load_mot(self.mot_det_dir) tracks_finished = [] # set the color of the object randomly. color_for_boundingbox = [(13 * i % 255, (255 - 5 * i) % 255, (240 + 10 * i) % 255) for i in range(0, 51)] # run algorithm. for frame_num, detections_frame in enumerate(detections, start=1): # apply low threshold to detections dets = [det for det in detections_frame if det['score'] >= sigma_l] updated_tracks = [] for track in self.tracks_active: if len(dets) > 0: # get det with highest iou best_match = max(dets, key=lambda x: iou(track['bboxes'][-1], x['bbox'])) if iou(track['bboxes'][-1], best_match['bbox']) >= sigma_iou: track['bboxes'].append(best_match['bbox']) track['max_score'] = max(track['max_score'], best_match['score']) updated_tracks.append(track) # remove from best matching detection from detections del dets[dets.index(best_match)] # if track was not updated if len(updated_tracks) == 0 or track is not updated_tracks[-1]: # finish track when the conditions are met if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min: tracks_finished.append(track) # create new tracks new_tracks = [{'bboxes': [det['bbox']], 'max_score': det['score'], 'start_frame': frame_num, 'color': color_for_boundingbox[(len(self.tracks_active) + random.randint(0, 51)) % 51]} for i, det in enumerate(dets)] self.tracks_active = updated_tracks + new_tracks self.retval, current_frame = self.vc.read() labeled_frame = show_tracking_results(current_frame, self.tracks_active) rgb_frame = convert_cvimage_to_qimage(labeled_frame) self.mot_signal.emit(rgb_frame) # finish all remaining active tracks tracks_finished += [track for track in self.tracks_active if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min] output_path = os.path.dirname(self.mot_video_dir) save_to_csv(output_path, tracks_finished) self.vc.release()
def main(args): time_iou = 0 time_ext = 0 time_merge = 0 time_ttl = 0 with open(args.seqmap) as fd: seqs = [line.rstrip('\n') for line in fd] for idx, seq in enumerate(seqs): print(seq) if seq == "name" or seq == "": continue else: if "DPM" in seq: sigma_l = -0.5 sigma_h = 0.5 sigma_iou = 0.5 t_min = 4 elif "FRCNN" in seq: sigma_l = 0.0 sigma_h = 0.9 sigma_iou = 0.4 t_min = 3 elif "SDP" in seq: sigma_l = 0.4 sigma_h = 0.5 sigma_iou = 0.3 t_min = 2 else: sigma_l = -0.5 # default -0.5 sigma_h = 0.5 # default 0.5 sigma_iou = 0.4 # default 0.4 t_min = 3 # default 4 ttl_vtracking = 8 # maximum length of visual track (amount of framess) sigma_iou_merge = 0.4 # uncomment line below if f4k2013 data is used # det_path = os.path.join(args.benchmark_dir,seq+"det.txt") # motchallenge data used det_path = os.path.join(args.benchmark_dir, seq, "det", "det.txt") img_path = os.path.join(args.benchmark_dir, seq, "img1") out_path = os.path.join(args.res_dir, seq + ".txt") detections = load_mot(det_path) # test preprocessing detections if args.prep_detections: detections = detections_preprocessing(detections, iou_filter=0.90) start = time() tracks_iou = track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min) end_iou = time() tracks_iou_ext, tracks_kcf_front, tracks_kcf_rear = track_kcf_2( tracks_iou, img_path, ttl_vtracking) end_ext = time() tracks_merged = merge(tracks_iou_ext, tracks_kcf_front, tracks_kcf_rear, sigma_iou_merge) end = time() num_frames = len(detections) print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!") save_to_csv(out_path, tracks_merged) time_iou += (end_iou - start) time_ext += (end_ext - end_iou) time_merge += (end - end_ext) time_ttl += (end - start) print('Time IOU: ' + str(time_iou)) print('Time VOT: ' + str(time_ext)) print('Time Merge:' + str(time_merge)) print('Time total: ' + str(time_ttl))