Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
36b8f4a8
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
36b8f4a8
编写于
6月 11, 2021
作者:
G
George Ni
提交者:
GitHub
6月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MOT] remove mot metric (#3360)
* remove mot metric * lazy import motmetrics
上级
bfc439ce
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
182 addition
and
321 deletion
+182
-321
ppdet/engine/__init__.py
ppdet/engine/__init__.py
+4
-3
ppdet/engine/trainer.py
ppdet/engine/trainer.py
+0
-5
ppdet/metrics/__init__.py
ppdet/metrics/__init__.py
+5
-3
ppdet/metrics/mot_eval_utils.py
ppdet/metrics/mot_eval_utils.py
+0
-191
ppdet/metrics/mot_metrics.py
ppdet/metrics/mot_metrics.py
+173
-119
未找到文件。
ppdet/engine/__init__.py
浏览文件 @
36b8f4a8
...
@@ -14,8 +14,6 @@
...
@@ -14,8 +14,6 @@
from
.
import
trainer
from
.
import
trainer
from
.trainer
import
*
from
.trainer
import
*
from
.
import
tracker
from
.tracker
import
*
from
.
import
callbacks
from
.
import
callbacks
from
.callbacks
import
*
from
.callbacks
import
*
...
@@ -24,6 +22,9 @@ from . import env
...
@@ -24,6 +22,9 @@ from . import env
from
.env
import
*
from
.env
import
*
__all__
=
trainer
.
__all__
\
__all__
=
trainer
.
__all__
\
+
tracker
.
__all__
\
+
callbacks
.
__all__
\
+
callbacks
.
__all__
\
+
env
.
__all__
+
env
.
__all__
from
.
import
tracker
from
.tracker
import
*
__all__
=
__all__
+
tracker
.
__all__
\
ppdet/engine/trainer.py
浏览文件 @
36b8f4a8
...
@@ -34,7 +34,6 @@ from ppdet.optimizer import ModelEMA
...
@@ -34,7 +34,6 @@ from ppdet.optimizer import ModelEMA
from
ppdet.core.workspace
import
create
from
ppdet.core.workspace
import
create
from
ppdet.utils.checkpoint
import
load_weight
,
load_pretrain_weight
from
ppdet.utils.checkpoint
import
load_weight
,
load_pretrain_weight
from
ppdet.utils.visualizer
import
visualize_results
,
save_result
from
ppdet.utils.visualizer
import
visualize_results
,
save_result
from
ppdet.metrics
import
JDEDetMetric
,
JDEReIDMetric
from
ppdet.metrics
import
Metric
,
COCOMetric
,
VOCMetric
,
WiderFaceMetric
,
get_infer_results
,
KeyPointTopDownCOCOEval
from
ppdet.metrics
import
Metric
,
COCOMetric
,
VOCMetric
,
WiderFaceMetric
,
get_infer_results
,
KeyPointTopDownCOCOEval
from
ppdet.data.source.category
import
get_categories
from
ppdet.data.source.category
import
get_categories
import
ppdet.utils.stats
as
stats
import
ppdet.utils.stats
as
stats
...
@@ -204,10 +203,6 @@ class Trainer(object):
...
@@ -204,10 +203,6 @@ class Trainer(object):
len
(
eval_dataset
),
self
.
cfg
.
num_joints
,
len
(
eval_dataset
),
self
.
cfg
.
num_joints
,
self
.
cfg
.
save_dir
)
self
.
cfg
.
save_dir
)
]
]
elif
self
.
cfg
.
metric
==
'MOTDet'
:
self
.
_metrics
=
[
JDEDetMetric
(),
]
elif
self
.
cfg
.
metric
==
'ReID'
:
self
.
_metrics
=
[
JDEReIDMetric
(),
]
else
:
else
:
logger
.
warn
(
"Metric not support for metric type {}"
.
format
(
logger
.
warn
(
"Metric not support for metric type {}"
.
format
(
self
.
cfg
.
metric
))
self
.
cfg
.
metric
))
...
...
ppdet/metrics/__init__.py
浏览文件 @
36b8f4a8
...
@@ -14,10 +14,12 @@
...
@@ -14,10 +14,12 @@
from
.
import
metrics
from
.
import
metrics
from
.
import
keypoint_metrics
from
.
import
keypoint_metrics
from
.
import
mot_metrics
from
.metrics
import
*
from
.metrics
import
*
from
.mot_metrics
import
*
from
.keypoint_metrics
import
*
from
.keypoint_metrics
import
*
__all__
=
metrics
.
__all__
+
keypoint_metrics
.
__all__
+
mot_metrics
.
__all__
__all__
=
metrics
.
__all__
+
keypoint_metrics
.
__all__
from
.
import
mot_metrics
from
.mot_metrics
import
*
__all__
=
__all__
+
mot_metrics
.
__all__
ppdet/metrics/mot_eval_utils.py
已删除
100644 → 0
浏览文件 @
bfc439ce
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
os
import
numpy
as
np
import
copy
import
motmetrics
as
mm
mm
.
lap
.
default_solver
=
'lap'
__all__
=
[
'read_mot_results'
,
'unzip_objs'
,
'MOTEvaluator'
,
]
def
read_mot_results
(
filename
,
is_gt
=
False
,
is_ignore
=
False
):
valid_labels
=
{
1
}
ignore_labels
=
{
2
,
7
,
8
,
12
}
results_dict
=
dict
()
if
os
.
path
.
isfile
(
filename
):
with
open
(
filename
,
'r'
)
as
f
:
for
line
in
f
.
readlines
():
linelist
=
line
.
split
(
','
)
if
len
(
linelist
)
<
7
:
continue
fid
=
int
(
linelist
[
0
])
if
fid
<
1
:
continue
results_dict
.
setdefault
(
fid
,
list
())
box_size
=
float
(
linelist
[
4
])
*
float
(
linelist
[
5
])
if
is_gt
:
if
'MOT16-'
in
filename
or
'MOT17-'
in
filename
:
label
=
int
(
float
(
linelist
[
7
]))
mark
=
int
(
float
(
linelist
[
6
]))
if
mark
==
0
or
label
not
in
valid_labels
:
continue
score
=
1
elif
is_ignore
:
if
'MOT16-'
in
filename
or
'MOT17-'
in
filename
:
label
=
int
(
float
(
linelist
[
7
]))
vis_ratio
=
float
(
linelist
[
8
])
if
label
not
in
ignore_labels
and
vis_ratio
>=
0
:
continue
else
:
continue
score
=
1
else
:
score
=
float
(
linelist
[
6
])
tlwh
=
tuple
(
map
(
float
,
linelist
[
2
:
6
]))
target_id
=
int
(
linelist
[
1
])
results_dict
[
fid
].
append
((
tlwh
,
target_id
,
score
))
return
results_dict
"""
labels={'ped', ... % 1
'person_on_vhcl', ... % 2
'car', ... % 3
'bicycle', ... % 4
'mbike', ... % 5
'non_mot_vhcl', ... % 6
'static_person', ... % 7
'distractor', ... % 8
'occluder', ... % 9
'occluder_on_grnd', ... % 10
'occluder_full', ... % 11
'reflection', ... % 12
'crowd' ... % 13
};
"""
def
unzip_objs
(
objs
):
if
len
(
objs
)
>
0
:
tlwhs
,
ids
,
scores
=
zip
(
*
objs
)
else
:
tlwhs
,
ids
,
scores
=
[],
[],
[]
tlwhs
=
np
.
asarray
(
tlwhs
,
dtype
=
float
).
reshape
(
-
1
,
4
)
return
tlwhs
,
ids
,
scores
class
MOTEvaluator
(
object
):
def
__init__
(
self
,
data_root
,
seq_name
,
data_type
):
self
.
data_root
=
data_root
self
.
seq_name
=
seq_name
self
.
data_type
=
data_type
self
.
load_annotations
()
self
.
reset_accumulator
()
def
load_annotations
(
self
):
assert
self
.
data_type
==
'mot'
gt_filename
=
os
.
path
.
join
(
self
.
data_root
,
self
.
seq_name
,
'gt'
,
'gt.txt'
)
self
.
gt_frame_dict
=
read_mot_results
(
gt_filename
,
is_gt
=
True
)
self
.
gt_ignore_frame_dict
=
read_mot_results
(
gt_filename
,
is_ignore
=
True
)
def
reset_accumulator
(
self
):
self
.
acc
=
mm
.
MOTAccumulator
(
auto_id
=
True
)
def
eval_frame
(
self
,
frame_id
,
trk_tlwhs
,
trk_ids
,
rtn_events
=
False
):
# results
trk_tlwhs
=
np
.
copy
(
trk_tlwhs
)
trk_ids
=
np
.
copy
(
trk_ids
)
# gts
gt_objs
=
self
.
gt_frame_dict
.
get
(
frame_id
,
[])
gt_tlwhs
,
gt_ids
=
unzip_objs
(
gt_objs
)[:
2
]
# ignore boxes
ignore_objs
=
self
.
gt_ignore_frame_dict
.
get
(
frame_id
,
[])
ignore_tlwhs
=
unzip_objs
(
ignore_objs
)[
0
]
# remove ignored results
keep
=
np
.
ones
(
len
(
trk_tlwhs
),
dtype
=
bool
)
iou_distance
=
mm
.
distances
.
iou_matrix
(
ignore_tlwhs
,
trk_tlwhs
,
max_iou
=
0.5
)
if
len
(
iou_distance
)
>
0
:
match_is
,
match_js
=
mm
.
lap
.
linear_sum_assignment
(
iou_distance
)
match_is
,
match_js
=
map
(
lambda
a
:
np
.
asarray
(
a
,
dtype
=
int
),
[
match_is
,
match_js
])
match_ious
=
iou_distance
[
match_is
,
match_js
]
match_js
=
np
.
asarray
(
match_js
,
dtype
=
int
)
match_js
=
match_js
[
np
.
logical_not
(
np
.
isnan
(
match_ious
))]
keep
[
match_js
]
=
False
trk_tlwhs
=
trk_tlwhs
[
keep
]
trk_ids
=
trk_ids
[
keep
]
# get distance matrix
iou_distance
=
mm
.
distances
.
iou_matrix
(
gt_tlwhs
,
trk_tlwhs
,
max_iou
=
0.5
)
# acc
self
.
acc
.
update
(
gt_ids
,
trk_ids
,
iou_distance
)
if
rtn_events
and
iou_distance
.
size
>
0
and
hasattr
(
self
.
acc
,
'last_mot_events'
):
events
=
self
.
acc
.
last_mot_events
# only supported by https://github.com/longcw/py-motmetrics
else
:
events
=
None
return
events
def
eval_file
(
self
,
filename
):
self
.
reset_accumulator
()
result_frame_dict
=
read_mot_results
(
filename
,
is_gt
=
False
)
frames
=
sorted
(
list
(
set
(
result_frame_dict
.
keys
())))
for
frame_id
in
frames
:
trk_objs
=
result_frame_dict
.
get
(
frame_id
,
[])
trk_tlwhs
,
trk_ids
=
unzip_objs
(
trk_objs
)[:
2
]
self
.
eval_frame
(
frame_id
,
trk_tlwhs
,
trk_ids
,
rtn_events
=
False
)
return
self
.
acc
@
staticmethod
def
get_summary
(
accs
,
names
,
metrics
=
(
'mota'
,
'num_switches'
,
'idp'
,
'idr'
,
'idf1'
,
'precision'
,
'recall'
)):
names
=
copy
.
deepcopy
(
names
)
if
metrics
is
None
:
metrics
=
mm
.
metrics
.
motchallenge_metrics
metrics
=
copy
.
deepcopy
(
metrics
)
mh
=
mm
.
metrics
.
create
()
summary
=
mh
.
compute_many
(
accs
,
metrics
=
metrics
,
names
=
names
,
generate_overall
=
True
)
return
summary
@
staticmethod
def
save_summary
(
summary
,
filename
):
import
pandas
as
pd
writer
=
pd
.
ExcelWriter
(
filename
)
summary
.
to_excel
(
writer
)
writer
.
save
()
ppdet/metrics/mot_metrics.py
浏览文件 @
36b8f4a8
...
@@ -16,134 +16,188 @@ from __future__ import division
...
@@ -16,134 +16,188 @@ from __future__ import division
from
__future__
import
print_function
from
__future__
import
print_function
import
os
import
os
import
paddle
import
copy
import
numpy
as
np
import
numpy
as
np
from
scipy
import
interpolat
e
import
paddl
e
import
paddle.nn.functional
as
F
import
paddle.nn.functional
as
F
from
.map_utils
import
ap_per_class
from
ppdet.modeling.bbox_utils
import
bbox_iou_np_expand
from
.mot_eval_utils
import
MOTEvaluator
from
.metrics
import
Metric
from
.metrics
import
Metric
from
ppdet.utils.logger
import
setup_logger
from
ppdet.utils.logger
import
setup_logger
logger
=
setup_logger
(
__name__
)
logger
=
setup_logger
(
__name__
)
__all__
=
[
'JDEDetMetric'
,
'JDEReIDMetric'
,
'MOTMetric'
]
__all__
=
[
'MOTEvaluator'
,
'MOTMetric'
]
class
JDEDetMetric
(
Metric
):
def
read_mot_results
(
filename
,
is_gt
=
False
,
is_ignore
=
False
):
def
__init__
(
self
,
overlap_thresh
=
0.5
):
valid_labels
=
{
1
}
self
.
overlap_thresh
=
overlap_thresh
ignore_labels
=
{
2
,
7
,
8
,
12
}
self
.
reset
()
results_dict
=
dict
()
if
os
.
path
.
isfile
(
filename
):
def
reset
(
self
):
with
open
(
filename
,
'r'
)
as
f
:
self
.
AP_accum
=
np
.
zeros
(
1
)
for
line
in
f
.
readlines
():
self
.
AP_accum_count
=
np
.
zeros
(
1
)
linelist
=
line
.
split
(
','
)
if
len
(
linelist
)
<
7
:
def
update
(
self
,
inputs
,
outputs
):
continue
bboxes
=
outputs
[
'bbox'
][:,
2
:].
numpy
()
fid
=
int
(
linelist
[
0
])
scores
=
outputs
[
'bbox'
][:,
1
].
numpy
()
if
fid
<
1
:
labels
=
outputs
[
'bbox'
][:,
0
].
numpy
()
continue
bbox_lengths
=
outputs
[
'bbox_num'
].
numpy
()
results_dict
.
setdefault
(
fid
,
list
())
if
bboxes
.
shape
[
0
]
==
1
and
bboxes
.
sum
()
==
0.0
:
return
box_size
=
float
(
linelist
[
4
])
*
float
(
linelist
[
5
])
gt_boxes
=
inputs
[
'gt_bbox'
].
numpy
()[
0
]
if
is_gt
:
gt_labels
=
inputs
[
'gt_class'
].
numpy
()[
0
]
if
'MOT16-'
in
filename
or
'MOT17-'
in
filename
:
if
gt_labels
.
shape
[
0
]
==
0
:
label
=
int
(
float
(
linelist
[
7
]))
return
mark
=
int
(
float
(
linelist
[
6
]))
if
mark
==
0
or
label
not
in
valid_labels
:
correct
=
[]
continue
detected
=
[]
score
=
1
for
i
in
range
(
bboxes
.
shape
[
0
]):
elif
is_ignore
:
obj_pred
=
0
if
'MOT16-'
in
filename
or
'MOT17-'
in
filename
:
pred_bbox
=
bboxes
[
i
].
reshape
(
1
,
4
)
label
=
int
(
float
(
linelist
[
7
]))
# Compute iou with target boxes
vis_ratio
=
float
(
linelist
[
8
])
iou
=
bbox_iou_np_expand
(
pred_bbox
,
gt_boxes
,
x1y1x2y2
=
True
)[
0
]
if
label
not
in
ignore_labels
and
vis_ratio
>=
0
:
# Extract index of largest overlap
continue
best_i
=
np
.
argmax
(
iou
)
else
:
# If overlap exceeds threshold and classification is correct mark as correct
continue
if
iou
[
best_i
]
>
self
.
overlap_thresh
and
obj_pred
==
gt_labels
[
score
=
1
best_i
]
and
best_i
not
in
detected
:
else
:
correct
.
append
(
1
)
score
=
float
(
linelist
[
6
])
detected
.
append
(
best_i
)
else
:
tlwh
=
tuple
(
map
(
float
,
linelist
[
2
:
6
]))
correct
.
append
(
0
)
target_id
=
int
(
linelist
[
1
])
# Compute Average Precision (AP) per class
results_dict
[
fid
].
append
((
tlwh
,
target_id
,
score
))
target_cls
=
list
(
gt_labels
.
T
[
0
])
return
results_dict
AP
,
AP_class
,
R
,
P
=
ap_per_class
(
tp
=
correct
,
conf
=
scores
,
"""
pred_cls
=
np
.
zeros_like
(
scores
),
labels={'ped', ... % 1
target_cls
=
target_cls
)
'person_on_vhcl', ... % 2
self
.
AP_accum_count
+=
np
.
bincount
(
AP_class
,
minlength
=
1
)
'car', ... % 3
self
.
AP_accum
+=
np
.
bincount
(
AP_class
,
minlength
=
1
,
weights
=
AP
)
'bicycle', ... % 4
'mbike', ... % 5
def
accumulate
(
self
):
'non_mot_vhcl', ... % 6
logger
.
info
(
"Accumulating evaluatation results..."
)
'static_person', ... % 7
self
.
map_stat
=
self
.
AP_accum
[
0
]
/
(
self
.
AP_accum_count
[
0
]
+
1E-16
)
'distractor', ... % 8
'occluder', ... % 9
def
log
(
self
):
'occluder_on_grnd', ... % 10
map_stat
=
100.
*
self
.
map_stat
'occluder_full', ... % 11
logger
.
info
(
"mAP({:.2f}) = {:.2f}%"
.
format
(
self
.
overlap_thresh
,
'reflection', ... % 12
map_stat
))
'crowd' ... % 13
};
def
get_results
(
self
):
"""
return
self
.
map_stat
def
unzip_objs
(
objs
):
class
JDEReIDMetric
(
Metric
):
if
len
(
objs
)
>
0
:
def
__init__
(
self
,
far_levels
=
[
1e-6
,
1e-5
,
1e-4
,
1e-3
,
1e-2
,
1e-1
]):
tlwhs
,
ids
,
scores
=
zip
(
*
objs
)
self
.
far_levels
=
far_levels
else
:
self
.
reset
()
tlwhs
,
ids
,
scores
=
[],
[],
[]
tlwhs
=
np
.
asarray
(
tlwhs
,
dtype
=
float
).
reshape
(
-
1
,
4
)
def
reset
(
self
):
return
tlwhs
,
ids
,
scores
self
.
embedding
=
[]
self
.
id_labels
=
[]
self
.
eval_results
=
{}
class
MOTEvaluator
(
object
):
def
__init__
(
self
,
data_root
,
seq_name
,
data_type
):
def
update
(
self
,
inputs
,
outputs
):
self
.
data_root
=
data_root
for
out
in
outputs
:
self
.
seq_name
=
seq_name
feat
,
label
=
out
[:
-
1
].
clone
().
detach
(),
int
(
out
[
-
1
])
self
.
data_type
=
data_type
if
label
!=
-
1
:
self
.
embedding
.
append
(
feat
)
self
.
load_annotations
()
self
.
id_labels
.
append
(
label
)
self
.
reset_accumulator
()
def
accumulate
(
self
):
def
load_annotations
(
self
):
logger
.
info
(
"Computing pairwise similairity..."
)
assert
self
.
data_type
==
'mot'
assert
len
(
self
.
embedding
)
==
len
(
self
.
id_labels
)
gt_filename
=
os
.
path
.
join
(
self
.
data_root
,
self
.
seq_name
,
'gt'
,
if
len
(
self
.
embedding
)
<
1
:
'gt.txt'
)
return
None
self
.
gt_frame_dict
=
read_mot_results
(
gt_filename
,
is_gt
=
True
)
embedding
=
paddle
.
stack
(
self
.
embedding
,
axis
=
0
)
self
.
gt_ignore_frame_dict
=
read_mot_results
(
emb
=
F
.
normalize
(
embedding
,
axis
=
1
).
numpy
()
gt_filename
,
is_ignore
=
True
)
pdist
=
np
.
matmul
(
emb
,
emb
.
T
)
def
reset_accumulator
(
self
):
id_labels
=
np
.
array
(
self
.
id_labels
,
dtype
=
'int32'
).
reshape
(
-
1
,
1
)
import
motmetrics
as
mm
n
=
len
(
id_labels
)
mm
.
lap
.
default_solver
=
'lap'
id_lbl
=
np
.
tile
(
id_labels
,
n
).
T
self
.
acc
=
mm
.
MOTAccumulator
(
auto_id
=
True
)
gt
=
id_lbl
==
id_lbl
.
T
up_triangle
=
np
.
where
(
np
.
triu
(
pdist
)
-
np
.
eye
(
n
)
*
pdist
!=
0
)
pdist
=
pdist
[
up_triangle
]
gt
=
gt
[
up_triangle
]
# lazy import metrics here
from
sklearn
import
metrics
far
,
tar
,
threshold
=
metrics
.
roc_curve
(
gt
,
pdist
)
interp
=
interpolate
.
interp1d
(
far
,
tar
)
tar_at_far
=
[
interp
(
x
)
for
x
in
self
.
far_levels
]
for
f
,
fa
in
enumerate
(
self
.
far_levels
):
self
.
eval_results
[
'TPR@FAR={:.7f}'
.
format
(
fa
)]
=
' {:.4f}'
.
format
(
tar_at_far
[
f
])
def
log
(
self
):
def
eval_frame
(
self
,
frame_id
,
trk_tlwhs
,
trk_ids
,
rtn_events
=
False
):
for
k
,
v
in
self
.
eval_results
.
items
():
import
motmetrics
as
mm
logger
.
info
(
'{}: {}'
.
format
(
k
,
v
))
mm
.
lap
.
default_solver
=
'lap'
# results
trk_tlwhs
=
np
.
copy
(
trk_tlwhs
)
trk_ids
=
np
.
copy
(
trk_ids
)
# gts
gt_objs
=
self
.
gt_frame_dict
.
get
(
frame_id
,
[])
gt_tlwhs
,
gt_ids
=
unzip_objs
(
gt_objs
)[:
2
]
# ignore boxes
ignore_objs
=
self
.
gt_ignore_frame_dict
.
get
(
frame_id
,
[])
ignore_tlwhs
=
unzip_objs
(
ignore_objs
)[
0
]
# remove ignored results
keep
=
np
.
ones
(
len
(
trk_tlwhs
),
dtype
=
bool
)
iou_distance
=
mm
.
distances
.
iou_matrix
(
ignore_tlwhs
,
trk_tlwhs
,
max_iou
=
0.5
)
if
len
(
iou_distance
)
>
0
:
match_is
,
match_js
=
mm
.
lap
.
linear_sum_assignment
(
iou_distance
)
match_is
,
match_js
=
map
(
lambda
a
:
np
.
asarray
(
a
,
dtype
=
int
),
[
match_is
,
match_js
])
match_ious
=
iou_distance
[
match_is
,
match_js
]
match_js
=
np
.
asarray
(
match_js
,
dtype
=
int
)
match_js
=
match_js
[
np
.
logical_not
(
np
.
isnan
(
match_ious
))]
keep
[
match_js
]
=
False
trk_tlwhs
=
trk_tlwhs
[
keep
]
trk_ids
=
trk_ids
[
keep
]
# get distance matrix
iou_distance
=
mm
.
distances
.
iou_matrix
(
gt_tlwhs
,
trk_tlwhs
,
max_iou
=
0.5
)
# acc
self
.
acc
.
update
(
gt_ids
,
trk_ids
,
iou_distance
)
if
rtn_events
and
iou_distance
.
size
>
0
and
hasattr
(
self
.
acc
,
'last_mot_events'
):
events
=
self
.
acc
.
last_mot_events
# only supported by https://github.com/longcw/py-motmetrics
else
:
events
=
None
return
events
def
eval_file
(
self
,
filename
):
self
.
reset_accumulator
()
result_frame_dict
=
read_mot_results
(
filename
,
is_gt
=
False
)
frames
=
sorted
(
list
(
set
(
result_frame_dict
.
keys
())))
for
frame_id
in
frames
:
trk_objs
=
result_frame_dict
.
get
(
frame_id
,
[])
trk_tlwhs
,
trk_ids
=
unzip_objs
(
trk_objs
)[:
2
]
self
.
eval_frame
(
frame_id
,
trk_tlwhs
,
trk_ids
,
rtn_events
=
False
)
return
self
.
acc
@
staticmethod
def
get_summary
(
accs
,
names
,
metrics
=
(
'mota'
,
'num_switches'
,
'idp'
,
'idr'
,
'idf1'
,
'precision'
,
'recall'
)):
import
motmetrics
as
mm
mm
.
lap
.
default_solver
=
'lap'
names
=
copy
.
deepcopy
(
names
)
if
metrics
is
None
:
metrics
=
mm
.
metrics
.
motchallenge_metrics
metrics
=
copy
.
deepcopy
(
metrics
)
def
get_results
(
self
):
mh
=
mm
.
metrics
.
create
()
return
self
.
eval_results
summary
=
mh
.
compute_many
(
accs
,
metrics
=
metrics
,
names
=
names
,
generate_overall
=
True
)
return
summary
@
staticmethod
def
save_summary
(
summary
,
filename
):
import
pandas
as
pd
writer
=
pd
.
ExcelWriter
(
filename
)
summary
.
to_excel
(
writer
)
writer
.
save
()
class
MOTMetric
(
Metric
):
class
MOTMetric
(
Metric
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录