本文主要是介绍MOT python版本填坑,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
多目标跟踪数据集
MOT:https://motchallenge.net/
多目标跟踪数据集
检测文件标注格式:
<frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <conf>, <x>, <y>, <z>
1. 1, -1, 794.2, 47.5, 71.2, 174.8, 67.5, -1, -1
2. 1, -1, 164.1, 19.6, 66.5, 163.2, 29.4, -1, -1
标注格式:第一个数字表示帧号,第二个-1表示还没有分配ID,后面四个数字表示左上角x,y,w,h,接着的一个数字表示检测器得到的置信度,最后两个-1对检测文件来说是忽略的.
GroundTrue标注格式
<frame>, <id>, <bb_left>, <bb_top>, <bb_width>, <bb_height>, <0/1忽略>, <cls>, <>1, 1, 794.2, 47.5, 71.2, 174.8, 1, 1, 0.8第7个数字表示这个实体是否被评估,0=忽略,1=评估;第8个数字表示类别
Label ID
Pedestrian 1
Person on vehicle 2
Car 3
Bicycle 4
Motorbike 5
Non motorized vehicle 6
Static person 7
Distractor 8
Occluder 9
Occluder on the ground 10 Occluder full 11
Reflection 12
MOT 评估 Python版
https://github.com/cheind/py-motmetrics
demo: py-motmetrics-master\motmetrics\apps\eval_motchallenge.py
import argparse #定义:argparse是python标准库里面用来处理命令行参数的库
import glob
import os
import logging
import motmetrics as mm
import pandas as pd
from collections import OrderedDict
from pathlib import Pathdef parse_args():#parser = argparse.ArgumentParser() 创建一个解析对象# #formatter_class=argparse.HelpFormatter, - 自定义帮助信息的格式parser = argparse.ArgumentParser(description="""
Compute metrics for trackers using MOTChallenge ground-truth data.Files
-----
All file content, ground truth and test files, have to comply with the
format described in Milan, Anton, et al.
"Mot16: A benchmark for multi-object tracking."
arXiv preprint arXiv:1603.00831 (2016).
https://motchallenge.net/Structure
---------Layout for ground truth data<GT_ROOT>/<SEQUENCE_1>/gt/gt.txt<GT_ROOT>/<SEQUENCE_2>/gt/gt.txt...Layout for test data<TEST_ROOT>/<SEQUENCE_1>.txt<TEST_ROOT>/<SEQUENCE_2>.txt...Sequences of ground truth and test will be matched according to the `<SEQUENCE_X>`
string.""", formatter_class=argparse.RawTextHelpFormatter)# parser.add_argument()向该对象中添加你要关注的命令行参数和选项parser.add_argument('groundtruths', type=str, help='Directory containing ground truth files.') parser.add_argument('tests', type=str, help='Directory containing tracker result files')parser.add_argument('--loglevel', type=str, help='Log level', default='info')parser.add_argument('--fmt', type=str, help='Data format', default='mot15-2D')parser.add_argument('--solver', type=str, help='LAP solver to use')# parser.parse_args()进行解析return parser.parse_args()def compare_dataframes(gts, ts):accs = []names = []for k, tsacc in ts.items():if k in gts: logging.info('Comparing {}...'.format(k))accs.append(mm.utils.compare_to_groundtruth(gts[k], tsacc, 'iou', distth=0.5))names.append(k)else:logging.warning('No ground truth for {}, skipping.'.format(k))return accs, namesif __name__ == '__main__':args = parse_args() # parse_args()从指定的选项中返回一些数据# getattr()函数用于返回一个对象属性值。loglevel = getattr(logging, args.loglevel.upper(), None)if not isinstance(loglevel, int):raise ValueError('Invalid log level: {} '.format(args.loglevel)) logging.basicConfig(level=loglevel, format='%(asctime)s %(levelname)s - %(message)s', datefmt='%I:%M:%S')'''logging.basicConfig函数各参数:filename:指定日志文件名;filemode:和file函数意义相同,指定日志文件的打开模式,'w'或者'a';format:指定输出的格式和内容,format可以输出很多有用的信息,'''if args.solver:mm.lap.default_solver = args.solver# 方法就是glob,该方法返回所有匹配的文件路径列表(list)# os.path.join(a,b) 路径拼接gtfiles = glob.glob(os.path.join(args.groundtruths, 'gt.txt'))# 返回path最后的文件名。如果path以/或\结尾,那么就会返回空值。即os.path.split(path)的第二个元素# string.startsWith() 方法用于检测字符串是否以指定的前缀开始。tsfiles = [f for f in glob.glob(os.path.join(args.tests, '*.txt')) if not os.path.basename(f).startswith('eval')]# print(os.path.join(args.groundtruths, 'gt.txt'))# print(os.path.join(args.tests, '*.txt'))logging.info('Found {} groundtruths and {} test files.'.format(len(gtfiles), len(tsfiles)))logging.info('Available LAP solvers {}'.format(mm.lap.available_solvers))logging.info('Default LAP solver \'{}\''.format(mm.lap.default_solver))logging.info('Loading files.')gt = OrderedDict([(Path(f).parts[-3], mm.io.loadtxt(f, fmt=args.fmt, min_confidence=1)) for f in gtfiles])ts = OrderedDict([(os.path.splitext(Path(f).parts[-1])[0], mm.io.loadtxt(f, fmt=args.fmt)) for f in tsfiles])# 有顺序列表 test 会有很多 det只有一个#gt = OrderedDict([('TUD-Campus', mm.io.loadtxt('D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/gt.txt'))])#ts = OrderedDict([('TUD-Campus', mm.io.loadtxt('D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/test.txt'))])mh = mm.metrics.create() # 清除对比列表accs, names = compare_dataframes(gt, ts)logging.info('Running metrics')summary = mh.compute_many(accs, names=names, metrics=mm.metrics.motchallenge_metrics, generate_overall=True)print(mm.io.render_summary(summary, formatters=mh.formatters, namemap=mm.io.motchallenge_metric_names))logging.info('Completed')
原文是在运行开始输入参数(gt,test文件目录):
输入参数方法
快捷键 按快捷键:alt+shift+F10调出运行窗口 点击选择Edit Configurations或者按0
或者右上角
输入 D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/ D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/
(此方法 输入路径有问题没法运行出来结果 还在研究)
可出结果方法
gt = OrderedDict([('TUD-Campus', mm.io.loadtxt('D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/gt.txt'))])ts = OrderedDict([('TUD-Campus', mm.io.loadtxt('D:/vot-challenge/py-motmetrics-master/py-motmetrics-master/motmetrics/data/TUD-Campus/test.txt'))])
修改gt,test 可出结果
这篇关于MOT python版本填坑的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!