前言
先看两篇文章:多目标跟踪评价指标介绍1,多目标跟踪评价指标介绍2,MOT数据集格式介绍。
MOT的格式,例如gt.txt:
1,0,1255,50,71,119,1,1,1
2,0,1254,51,71,119,1,1,1
3,0,1253,52,71,119,1,1,1
...
例如test.txt:
1,1,1240.0,40.0,120.0,96.0,0.999998,-1,-1,-1
2,1,1237.0,43.0,119.0,96.0,0.999998,-1,-1,-1
3,1,1237.0,44.0,117.0,95.0,0.999998,-1,-1,-1
...
代码介绍
项目地址,其中多个test衡量代码可以参考eval_motchallenge.py
以下介绍简便检测方法:
- 首先
pip install motemetrics
- 代码的大概流程是:使用
mm.io.loadtxt()
导入gt.txt和test.txt文件,然后使用mm.utils.compare_to_groundtruth()
创建一个accumulator,再使用mh.compute()
进行计算,最终通过mm.io.render_summary()
得到规范化格式的输出。
import motmetrics as mm
import numpy as np
import os
#评价指标
metrics = list(mm.metrics.motchallenge_metrics)
#导入gt和ts文件
gt_file="/path/to/gt/gt.txt"
ts_file="/path/to/test/0000.txt"
gt=mm.io.loadtxt(gt_file, fmt="mot15-2D", min_confidence=1)
ts=mm.io.loadtxt(ts_file, fmt="mot15-2D")
name=os.path.splitext(os.path.basename(ts_file))[0]
#计算单个acc
acc=mm.utils.compare_to_groundtruth(gt, ts, 'iou', distth=0.5)
mh = mm.metrics.create()
summary = mh.compute(acc, metrics=metrics, name=name)
print(mm.io.render_summary(summary, formatters=mh.formatters,namemap=mm.io.motchallenge_metric_names))
其中评价指标metrics
有:
['idf1', 'idp', 'idr', 'recall', 'precision', 'num_unique_objects', 'mostly_tracked', 'partially_tracked', 'mostly_lost', 'num_false_positives', 'num_misses', 'num_switches', 'num_fragmentations', 'mota', 'motp', 'num_transfer', 'num_ascend', 'num_migrate']
创建accumulator
:
- 单个:
acc=mm.utils.compare_to_groundtruth(gt, ts, 'iou', distth=0.5)
- 多个:
accs=[]
,然后循环ts append到acc里:accs.append(mm.utils.compare_to_groundtruth(gt, ts, 'iou', distth=0.5))
计算accumulator
,mh = mm.metrics.create()
:
- 单个:
summary = mh.compute(acc, metrics=metrics, name=name)
- 多个:
summary = mh.compute_many(accs, metrics=metrics, name=names)
通过mm.io.render_summary
得到对应格式的输出:
- 转化成短名称
namemap=mm.io.motchallenge_metric_names
:{'idf1': 'IDF1', 'idp': 'IDP', 'idr': 'IDR', 'recall': 'Rcll', 'precision': 'Prcn', 'num_unique_objects': 'GT', 'mostly_tracked': 'MT', 'partially_tracked': 'PT', 'mostly_lost': 'ML', 'num_false_positives': 'FP', 'num_misses': 'FN', 'num_switches': 'IDs', 'num_fragmentations': 'FM', 'mota': 'MOTA', 'motp': 'MOTP', 'num_transfer': 'IDt', 'num_ascend': 'IDa', 'num_migrate': 'IDm'}
- 转化精度格式:
formatters=mh.formatters
输出例子
单个输出例子:
如果直接print(summary),不规范化输出就会:
如果不加入formatters规范化就是:
多个输出例子: