def main(data_root='', seqs=('', ), args=""): logger.setLevel(logging.INFO) data_type = 'mot' result_root = os.path.join(Path(data_root), "mot_results") mkdir_if_missing(result_root) cfg = get_config() cfg.merge_from_file(args.config_detection) cfg.merge_from_file(args.config_deepsort) # run tracking accs = [] for seq in seqs: logger.info('start seq: {}'.format(seq)) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) video_path = data_root + "/" + seq + "/video/video.mp4" with VideoTracker(cfg, args, video_path, result_filename) as vdo_trk: vdo_trk.run() # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) # get summary metrics = mm.metrics.motchallenge_metrics mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names) print(strsummary) Evaluator.save_summary(summary, os.path.join(result_root, 'summary_global.xlsx'))
def main(seqs=('2', ), det_types=('', )): # run tracking accs = [] data_root = args.data_root + '/MOT{}/train'.format(args.mot_version) choice = (0, 0, 4, 0, 3, 3) TrackerConfig.set_configure(choice) choice_str = TrackerConfig.get_configure_str(choice) seq_names = [] for seq in seqs: for det_type in det_types: result_filename = track_seq(seq, det_type, choice_str) seq_name = 'MOT{}-{}{}'.format(args.mot_version, seq.zfill(2), det_type) seq_names.append(seq_name) print('Evaluate seq:{}'.format(seq_name)) evaluator = Evaluator(data_root, seq_name, 'mot') accs.append(evaluator.eval_file(result_filename)) # get summary # metrics = ['mota', 'num_switches', 'idp', 'idr', 'idf1', 'precision', 'recall'] metrics = mm.metrics.motchallenge_metrics # metrics = None mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seq_names, metrics) strsummary = mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names) print(strsummary) Evaluator.save_summary( summary, os.path.join(os.path.join(args.log_folder, choice_str), 'summary_{}.xlsx'.format(args.exp_name)))
def main(data_root='/mnt/EEC2C12EC2C0FBB9/Users/mirap/CMP/MOTDT/datasets', det_root=None, seqs=('MOT17-01-DPM ', ), exp_name='demo', save_image=True, show_image=False): logger.setLevel(logging.INFO) result_root = os.path.join(data_root, '..', 'results', exp_name) mkdirs(result_root) data_type = 'mot' # run tracking accs = [] for seq in seqs: output_dir = os.path.join(data_root, 'outputs', seq) if save_image else None logger.info('start seq: {}'.format(seq)) loader = get_loader(data_root, det_root, seq) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) eval_seq(loader, data_type, result_filename, save_dir=output_dir, show_image=show_image) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename))
def main(opt, data_root='/data/MOT16/train', det_root=None, seqs=('MOT16-05',), exp_name='demo', save_images=False, save_videos=False, show_image=True): logger.setLevel(logging.INFO) result_root = os.path.join(data_root, '..', 'results', exp_name) mkdir_if_missing(result_root) data_type = 'mot' # Read config cfg_dict = parse_model_cfg(opt.cfg) opt.img_size = [int(cfg_dict[0]['width']), int(cfg_dict[0]['height'])] # run tracking accs = [] n_frame = 0 timer_avgs, timer_calls = [], [] for seq in seqs: output_dir = os.path.join(data_root, '..','outputs', exp_name, seq) if save_images or save_videos else None logger.info('start seq: {}'.format(seq)) dataloader = datasets.LoadImages(osp.join(data_root, seq, 'img1'), opt.img_size) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) meta_info = open(os.path.join(data_root, seq, 'seqinfo.ini')).read() frame_rate = int(meta_info[meta_info.find('frameRate')+10:meta_info.find('\nseqLength')]) nf, ta, tc = eval_seq(opt, dataloader, data_type, result_filename, save_dir=output_dir, show_image=show_image, frame_rate=frame_rate) n_frame += nf timer_avgs.append(ta) timer_calls.append(tc) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) if save_videos: output_video_path = osp.join(output_dir, '{}.mp4'.format(seq)) cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format(output_dir, output_video_path) os.system(cmd_str) timer_avgs = np.asarray(timer_avgs) timer_calls = np.asarray(timer_calls) all_time = np.dot(timer_avgs, timer_calls) avg_time = all_time / np.sum(timer_calls) logger.info('Time elapsed: {:.2f} seconds, FPS: {:.2f}'.format(all_time, 1.0 / avg_time)) # get summary metrics = mm.metrics.motchallenge_metrics mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary( summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names ) print(strsummary) sys.stdout.flush() Evaluator.save_summary(summary, os.path.join(result_root, 'summary_{}.xlsx'.format(exp_name)))
def main(data_root='', seqs=('', ), args=""): logger = get_logger() logger.setLevel(logging.INFO) model_name = args.MODEL_NAME data_type = 'mot' analyse_every_frames = args.frame_interval dataset_name = data_root.split(sep='/')[-1] tracker_type = get_tracker_type(args) result_root = os.path.join("mot_results", model_name, dataset_name) mkdir_if_missing(result_root) cfg = get_config() cfg.merge_from_file(args.config_detection) cfg.merge_from_file(args.config_tracker) args.save_path = result_root # run tracking accs = [] for seq in seqs: logger.info('start seq: {}'.format(seq)) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) seq_root = os.path.join(data_root, seq) video_root = os.path.join(seq_root, "video") video_path = os.path.join(video_root, os.listdir(video_root)[0]) logger.info(f"Result filename: {result_filename}") logger.info(f'Frame interval: {analyse_every_frames}') if not os.path.exists(result_filename): with VideoTracker(cfg, args, video_path, result_filename) as vdo_trk: vdo_trk.run() else: print( f"Result file {result_filename} already exists. Skipping processing" ) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) # get summary metrics = mm.metrics.motchallenge_metrics mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names) print(strsummary) Evaluator.save_summary(summary, os.path.join(result_root, 'summary_global.xlsx'))
def main(data_root=os.path.expanduser('~/Data/MOT16/train'), det_root=None, seqs=('MOT16-05', ), exp_name='demo', save_image=False, show_image=True, args=None): logger.setLevel(logging.INFO) result_root = os.path.join(data_root, '..', 'results', exp_name) mkdirs(result_root) data_type = 'mot' # run tracking accs = [] for seq in seqs: output_dir = os.path.join(data_root, 'outputs', seq) if save_image else None logger.info('start seq: {}'.format(seq)) loader = get_loader(data_root, det_root, seq) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) eval_seq(loader, data_type, result_filename, save_dir=output_dir, show_image=show_image, args=args) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) # get summary # metrics = ['mota', 'num_switches', 'idp', 'idr', 'idf1', 'precision', 'recall'] metrics = mm.metrics.motchallenge_metrics # metrics = None mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names) print(strsummary) Evaluator.save_summary( summary, os.path.join(result_root, f'summary_{exp_name}.xlsx'))
def main(opt, data_root='/data/MOT16/train', det_root=None, seqs=('MOT16-05', ), exp_name='demo', save_images=False, save_videos=False, show_image=True): logger.setLevel(logging.INFO) result_root = os.path.join(data_root, '..', 'results', exp_name) mkdir_if_missing(result_root) data_type = 'mot' # run tracking timer = Timer() accs = [] n_frame = 0 timer.tic() for seq in seqs: output_dir = os.path.join(data_root, '..', 'outputs', exp_name, seq) if save_images or save_videos else None logger.info('start seq: {}'.format(seq)) dataloader = datasets.LoadImages(osp.join(data_root, seq, 'img1'), opt.img_size) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) meta_info = open(os.path.join(data_root, seq, 'seqinfo.ini')).read() frame_rate = int(meta_info[meta_info.find('frameRate') + 10:meta_info.find('\nseqLength')]) n_frame += eval_seq(opt, dataloader, data_type, result_filename, save_dir=output_dir, show_image=show_image, frame_rate=frame_rate) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) if save_videos: output_video_path = osp.join(output_dir, '{}.mp4'.format(seq)) cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format( output_dir, output_video_path) os.system(cmd_str) timer.toc() logger.info('Time elapsed: {}, FPS {}'.format(timer.average_time, n_frame / timer.average_time)) # get summary # metrics = ['mota', 'num_switches', 'idp', 'idr', 'idf1', 'precision', 'recall'] metrics = mm.metrics.motchallenge_metrics mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names) print(strsummary) Evaluator.save_summary( summary, os.path.join(result_root, 'summary_{}.xlsx'.format(exp_name)))
def main(opt, data_root='/media/dh/data/MOT16/train', det_root=None, seqs=('MOT16-05', ), exp_name='demo', save_images=False, save_videos=False, show_image=True): logger.setLevel(logging.INFO) result_root = os.path.join(data_root, '..', 'results', exp_name) mkdir_if_missing(result_root) data_type = 'mot' # Read config cfg_dict = parse_model_cfg(opt.cfg) opt.img_size = [int(cfg_dict[0]['width']), int(cfg_dict[0]['height'])] # run tracking accs = [] n_frame = 0 timer_avgs, timer_calls = [], [] for seq in seqs: output_dir = os.path.join(data_root, '..', 'outputs', exp_name, seq) if save_images or save_videos else None logger.info('start seq: {}'.format(seq)) #dataloader = datasets.LoadImages(osp.join(data_root, seq, 'img1'), opt.img_size) print(osp.join(data_root, seq)) dataloader = datasets.LoadVideo(osp.join(data_root, seq)) # print ("DATALOADER", dataloader.vw) result_filename = os.path.join(result_root, '{}.csv'.format(seq)) #meta_info = open(os.path.join(data_root, seq, 'seqinfo.ini')).read() #frame_rate = int(meta_info[meta_info.find('frameRate')+10:meta_info.find('\nseqLength')]) frame_rate = 30 nf, ta, tc = eval_seq(opt, dataloader, data_type, result_filename, save_dir=output_dir, show_image=show_image, frame_rate=frame_rate, vw=dataloader.vw) n_frame += nf timer_avgs.append(ta) timer_calls.append(tc) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) if save_videos: output_video_path = osp.join(output_dir, '{}.mp4'.format(seq)) cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format( output_dir, output_video_path) os.system(cmd_str) timer_avgs = np.asarray(timer_avgs) timer_calls = np.asarray(timer_calls) all_time = np.dot(timer_avgs, timer_calls) avg_time = all_time / np.sum(timer_calls) logger.info('Time elapsed: {:.2f} seconds, FPS: {:.2f}'.format( all_time, 1.0 / avg_time))
logger.info('start seq: {}'.format(seq)) dataloader = datasets.LoadImages(osp.join(data_root, seq, 'img1'), opt.img_size) result_filename = os.path.join(result_root, '{}.txt'.format(seq)) meta_info = open(os.path.join(data_root, seq, 'seqinfo.ini')).read() frame_rate = int(meta_info[meta_info.find('frameRate')+10:meta_info.find('\nseqLength')]) nf, ta, tc = eval_seq(opt, dataloader, data_type, result_filename, save_dir=output_dir, show_image=show_image, frame_rate=frame_rate) n_frame += nf timer_avgs.append(ta) timer_calls.append(tc) # eval logger.info('Evaluate seq: {}'.format(seq)) evaluator = Evaluator(data_root, seq, data_type) accs.append(evaluator.eval_file(result_filename)) if save_videos: output_video_path = osp.join(output_dir, '{}.mp4'.format(seq)) cmd_str = 'ffmpeg -f image2 -i {}/%05d.jpg -c:v copy {}'.format(output_dir, output_video_path) os.system(cmd_str) timer_avgs = np.asarray(timer_avgs) timer_calls = np.asarray(timer_calls) all_time = np.dot(timer_avgs, timer_calls) avg_time = all_time / np.sum(timer_calls) logger.info('Time elapsed: {:.2f} seconds, FPS: {:.2f}'.format(all_time, 1.0 / avg_time)) # get summary metrics = mm.metrics.motchallenge_metrics mh = mm.metrics.create() summary = Evaluator.get_summary(accs, seqs, metrics) strsummary = mm.io.render_summary(