本文整理匯總了Python中motmetrics.MOTAccumulator方法的典型用法代碼示例。如果您正苦於以下問題:Python motmetrics.MOTAccumulator方法的具體用法?Python motmetrics.MOTAccumulator怎麽用?Python motmetrics.MOTAccumulator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類motmetrics
的用法示例。
在下文中一共展示了motmetrics.MOTAccumulator方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def __init__(self, auto_id=False, max_switch_time=float('inf')):
"""Create a MOTAccumulator.
Params
------
auto_id : bool, optional
Whether or not frame indices are auto-incremented or provided upon
updating. Defaults to false. Not specifying a frame-id when this value
is true results in an error. Specifying a frame-id when this value is
false also results in an error.
max_switch_time : scalar, optional
Allows specifying an upper bound on the timespan an unobserved but
tracked object is allowed to generate track switch events. Useful if groundtruth
objects leaving the field of view keep their ID when they reappear,
but your tracker is not capable of recognizing this (resulting in
track switch events). The default is that there is no upper bound
on the timespan. In units of frame timestamps. When using auto_id
in units of count.
"""
self.auto_id = auto_id
self.max_switch_time = max_switch_time
self.reset()
示例2: __init__
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def __init__(self, obstacle_tracking_stream, ground_obstacles_stream,
flags):
obstacle_tracking_stream.add_callback(self.on_tracker_obstacles)
ground_obstacles_stream.add_callback(self.on_ground_obstacles)
erdos.add_watermark_callback(
[obstacle_tracking_stream, ground_obstacles_stream], [],
self.on_watermark)
self._flags = flags
self._logger = erdos.utils.setup_logging(self.config.name,
self.config.log_file_name)
self._csv_logger = erdos.utils.setup_csv_logging(
self.config.name + '-csv', self.config.csv_log_file_name)
self._last_notification = None
# Buffer of detected obstacles.
self._tracked_obstacles = []
# Buffer of ground obstacles.
self._ground_obstacles = []
# Heap storing pairs of (ground/output time, game time).
self._tracker_start_end_times = []
self._sim_interval = None
self._accumulator = mm.MOTAccumulator(auto_id=True)
self._metrics_host = mm.metrics.create()
示例3: test_correct_average
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_correct_average():
# Tests what is being depicted in figure 3 of 'Evaluating MOT Performance'
acc = mm.MOTAccumulator(auto_id=True)
# No track
acc.update([1, 2, 3, 4], [], [])
acc.update([1, 2, 3, 4], [], [])
acc.update([1, 2, 3, 4], [], [])
acc.update([1, 2, 3, 4], [], [])
# Track single
acc.update([4], [4], [0])
acc.update([4], [4], [0])
acc.update([4], [4], [0])
acc.update([4], [4], [0])
mh = mm.metrics.create()
metr = mh.compute(acc, metrics='mota', return_dataframe=False)
assert metr['mota'] == approx(0.2)
示例4: reset
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def reset(self):
"""Reset the accumulator to empty state."""
self.events = MOTAccumulator.new_event_dataframe()
self.m = {} # Pairings up to current timestamp
self.last_occurrence = {} # Tracks most recent occurance of object
示例5: test_events
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_events():
acc = mm.MOTAccumulator()
# All FP
acc.update([], ['a', 'b'], [], frameid=0)
# All miss
acc.update([1, 2], [], [], frameid=1)
# Match
acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=2)
# Switch
acc.update([1, 2], ['a', 'b'], [[0.2, np.nan], [np.nan, 0.1]], frameid=3)
# Match. Better new match is available but should prefer history
acc.update([1, 2], ['a', 'b'], [[5, 1], [1, 5]], frameid=4)
# No data
acc.update([], [], [], frameid=5)
expect = mm.MOTAccumulator.new_event_dataframe()
expect.loc[(0, 0), :] = ['FP', np.nan, 'a', np.nan]
expect.loc[(0, 1), :] = ['FP', np.nan, 'b', np.nan]
expect.loc[(1, 0), :] = ['MISS', 1, np.nan, np.nan]
expect.loc[(1, 1), :] = ['MISS', 2, np.nan, np.nan]
expect.loc[(2, 0), :] = ['MATCH', 1, 'b', 0.5]
expect.loc[(2, 1), :] = ['MATCH', 2, 'a', 0.3]
expect.loc[(3, 0), :] = ['SWITCH', 1, 'a', 0.2]
expect.loc[(3, 1), :] = ['SWITCH', 2, 'b', 0.1]
expect.loc[(4, 0), :] = ['MATCH', 1, 'a', 5.]
expect.loc[(4, 1), :] = ['MATCH', 2, 'b', 5.]
# frame 5 generates no events
assert pd.DataFrame.equals(acc.events, expect)
mh = mm.metrics.create()
metr = mh.compute(acc, metrics=['motp', 'mota'], return_dataframe=False)
#print(metr)
#print(approx((1.0 - (((2 + 2) + 2) / 8))))
assert metr['motp'] == approx(11.1 / 6)
assert metr['mota'] == approx(1. - (2 + 2 + 2) / 8.)
示例6: test_max_switch_time
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_max_switch_time():
acc = mm.MOTAccumulator(max_switch_time=1)
df = acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=1) # 1->a, 2->b
df = acc.update([1, 2], ['a', 'b'], [[0.5, np.nan], [np.nan, 0.5]], frameid=2) # 1->b, 2->a
assert (df.Type == 'SWITCH').all()
acc = mm.MOTAccumulator(max_switch_time=1)
df = acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=1) # 1->a, 2->b
df = acc.update([1, 2], ['a', 'b'], [[0.5, np.nan], [np.nan, 0.5]], frameid=5) # Later frame 1->b, 2->a
assert (df.Type == 'MATCH').all()
示例7: test_auto_id
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_auto_id():
acc = mm.MOTAccumulator(auto_id=True)
acc.update([1, 2, 3, 4], [], [])
acc.update([1, 2, 3, 4], [], [])
assert acc.events.index.levels[0][-1] == 1
acc.update([1, 2, 3, 4], [], [])
assert acc.events.index.levels[0][-1] == 2
with pytest.raises(AssertionError):
acc.update([1, 2, 3, 4], [], [], frameid=5)
acc = mm.MOTAccumulator(auto_id=False)
with pytest.raises(AssertionError):
acc.update([1, 2, 3, 4], [], [])
示例8: reset_accumulator
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def reset_accumulator(self):
self.acc = mm.MOTAccumulator(auto_id=True)
示例9: test_events
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_events():
acc = mm.MOTAccumulator()
# All FP
acc.update([], ['a', 'b'], [], frameid=0)
# All miss
acc.update([1, 2], [], [], frameid=1)
# Match
acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=2)
# Switch
acc.update([1, 2], ['a', 'b'], [[0.2, np.nan], [np.nan, 0.1]], frameid=3)
# Match. Better new match is available but should prefer history
acc.update([1, 2], ['a', 'b'], [[5, 1], [1, 5]], frameid=4)
# No data
acc.update([], [], [], frameid=5)
expect = mm.MOTAccumulator.new_event_dataframe()
expect.loc[(0, 0), :] = ['FP', np.nan, 'a', np.nan]
expect.loc[(0, 1), :] = ['FP', np.nan, 'b', np.nan]
expect.loc[(1, 0), :] = ['MISS', 1, np.nan, np.nan]
expect.loc[(1, 1), :] = ['MISS', 2, np.nan, np.nan]
expect.loc[(2, 0), :] = ['MATCH', 1, 'b', 0.5]
expect.loc[(2, 1), :] = ['MATCH', 2, 'a', 0.3]
expect.loc[(3, 0), :] = ['SWITCH', 1, 'a', 0.2]
expect.loc[(3, 1), :] = ['SWITCH', 2, 'b', 0.1]
expect.loc[(4, 0), :] = ['MATCH', 1, 'a', 5.]
expect.loc[(4, 1), :] = ['MATCH', 2, 'b', 5.]
# frame 5 generates no events
assert pd.DataFrame.equals(acc.events, expect)
mh = mm.metrics.create()
metr = mh.compute(acc, metrics=['motp', 'mota'], return_dataframe=False)
assert metr['motp'] == approx(11.1 / 6)
assert metr['mota'] == approx(1. - (2 + 2 + 2) / 8)
示例10: test_max_switch_time
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def test_max_switch_time():
acc = mm.MOTAccumulator(max_switch_time=1)
df = acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=1) # 1->a, 2->b
df = acc.update([1, 2], ['a', 'b'], [[0.5, np.nan], [np.nan, 0.5]], frameid=2) # 1->b, 2->a
assert (df.Type == 'SWITCH').all()
acc = mm.MOTAccumulator(max_switch_time=1)
df = acc.update([1, 2], ['a', 'b'], [[1, 0.5], [0.3, 1]], frameid=1) # 1->a, 2->b
df = acc.update([1, 2], ['a', 'b'], [[0.5, np.nan], [np.nan, 0.5]], frameid=5) # Later frame 1->b, 2->a
assert (df.Type == 'MATCH').all()
示例11: get_mot_accum
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def get_mot_accum(results, seq):
mot_accum = mm.MOTAccumulator(auto_id=True)
for i, data in enumerate(seq):
gt = data['gt']
gt_ids = []
if gt:
gt_boxes = []
for gt_id, box in gt.items():
gt_ids.append(gt_id)
gt_boxes.append(box)
gt_boxes = np.stack(gt_boxes, axis=0)
# x1, y1, x2, y2 --> x1, y1, width, height
gt_boxes = np.stack((gt_boxes[:, 0],
gt_boxes[:, 1],
gt_boxes[:, 2] - gt_boxes[:, 0],
gt_boxes[:, 3] - gt_boxes[:, 1]),
axis=1)
else:
gt_boxes = np.array([])
track_ids = []
track_boxes = []
for track_id, frames in results.items():
if i in frames:
track_ids.append(track_id)
# frames = x1, y1, x2, y2, score
track_boxes.append(frames[i][:4])
if track_ids:
track_boxes = np.stack(track_boxes, axis=0)
# x1, y1, x2, y2 --> x1, y1, width, height
track_boxes = np.stack((track_boxes[:, 0],
track_boxes[:, 1],
track_boxes[:, 2] - track_boxes[:, 0],
track_boxes[:, 3] - track_boxes[:, 1]),
axis=1)
else:
track_boxes = np.array([])
distance = mm.distances.iou_matrix(gt_boxes, track_boxes, max_iou=0.5)
mot_accum.update(
gt_ids,
track_ids,
distance)
return mot_accum
示例12: process_frame
# 需要導入模塊: import motmetrics [as 別名]
# 或者: from motmetrics import MOTAccumulator [as 別名]
def process_frame(si, nJoints, seqidxs, seqidxsUniq, motAll, metricsMidNames):
# create metrics
mh = mm.metrics.create()
print("seqidx: %d" % (si+1))
# init per-joint metrics accumulator
accAll = {}
for i in range(nJoints):
accAll[i] = mm.MOTAccumulator(auto_id=True)
# extract frames IDs for the sequence
imgidxs = np.argwhere(seqidxs == seqidxsUniq[si])
# DEBUG: remove the last frame of each sequence from evaluation due to buggy annotations
print("DEBUG: remove last frame from eval until annotations are fixed")
imgidxs = imgidxs[:-1].copy()
# create an accumulator that will be updated during each frame
# iterate over frames
for j in range(len(imgidxs)):
imgidx = imgidxs[j,0]
# iterate over joints
for i in range(nJoints):
# GT tracking ID
trackidxGT = motAll[imgidx][i]["trackidxGT"]
# prediction tracking ID
trackidxPr = motAll[imgidx][i]["trackidxPr"]
# distance GT <-> pred part to compute MOT metrics
# 'NaN' means force no match
dist = motAll[imgidx][i]["dist"]
# Call update once per frame
accAll[i].update(
trackidxGT, # Ground truth objects in this frame
trackidxPr, # Detector hypotheses in this frame
dist # Distances from objects to hypotheses
)
# compute intermediate metrics per joint per sequence
all_metricsMid = []
for i in range(nJoints):
all_metricsMid.append(
mh.compute(accAll[i], metrics=metricsMidNames,
return_dataframe=False, name='acc'))
return all_metricsMid, accAll