Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
469eeea3
Commit
469eeea3
authored
Jan 20, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ROC estimation
in the same way as Dallar's matlab toolbox does
parent
4c4c878b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
56 deletions
+63
-56
roc_test.py
apps/sft/misk/roc_test.py
+24
-20
sft.py
apps/sft/misk/sft.py
+39
-36
No files found.
apps/sft/misk/roc_test.py
View file @
469eeea3
...
@@ -34,43 +34,47 @@ if __name__ == "__main__":
...
@@ -34,43 +34,47 @@ if __name__ == "__main__":
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# parse annotations
samples
=
call_parser
(
args
.
anttn_format
,
args
.
annotations
)
samples
=
call_parser
(
args
.
anttn_format
,
args
.
annotations
)
cascade
=
sft
.
cascade
(
args
.
min_scale
,
args
.
max_scale
,
args
.
nscales
,
args
.
cascade
)
# where we use nms cv::SCascade::DOLLAR == 2
cascade
=
cv2
.
SCascade
(
args
.
min_scale
,
args
.
max_scale
,
args
.
nscales
,
2
)
xml
=
cv2
.
FileStorage
(
args
.
cascade
,
0
)
dom
=
xml
.
getFirstTopLevelNode
()
assert
cascade
.
load
(
dom
)
pattern
=
args
.
input
pattern
=
args
.
input
camera
=
cv2
.
VideoCapture
(
pattern
)
camera
=
cv2
.
VideoCapture
(
pattern
)
frame
=
0
# for plotting over dataset
nannotated
=
0
nframes
=
0
confidenses
=
[]
tp
=
[]
while
True
:
while
True
:
ret
,
img
=
camera
.
read
()
ret
,
img
=
camera
.
read
()
if
not
ret
:
if
not
ret
:
break
;
break
;
name
=
pattern
%
(
frame
,)
name
=
pattern
%
(
nframes
,)
qq
=
pattern
.
format
(
frame
)
_
,
tail
=
os
.
path
.
split
(
name
)
_
,
tail
=
os
.
path
.
split
(
name
)
boxes
=
samples
[
tail
]
boxes
=
samples
[
tail
]
boxes
=
sft
.
norm_acpect_ratio
(
boxes
,
0.5
)
boxes
=
sft
.
norm_acpect_ratio
(
boxes
,
0.5
)
frame
=
frame
+
1
nannotated
=
nannotated
+
len
(
boxes
)
nframes
=
nframes
+
1
rects
,
confs
=
cascade
.
detect
(
img
,
rois
=
None
)
rects
,
confs
=
cascade
.
detect
(
img
,
rois
=
None
)
if
confs
is
None
:
continue
dts
=
sft
.
convert2detections
(
rects
,
confs
)
dts
=
sft
.
convert2detections
(
rects
,
confs
)
sft
.
draw_dt
(
img
,
dts
,
bgr
[
"green"
])
fp
,
fn
=
sft
.
match
(
boxes
,
dts
)
confs
=
confs
.
tolist
()[
0
]
print
"fp and fn"
,
fp
,
fn
confs
.
sort
(
lambda
x
,
y
:
-
1
if
(
x
-
y
)
>
0
else
1
)
confidenses
=
confidenses
+
confs
matched
=
sft
.
match
(
boxes
,
dts
)
tp
=
tp
+
matched
sft
.
draw_rects
(
img
,
boxes
,
bgr
[
"blue"
],
lambda
x
,
y
:
y
)
print
nframes
,
nannotated
cv2
.
imshow
(
"result"
,
img
);
if
(
cv2
.
waitKey
(
0
)
==
27
):
break
;
# sft.plot_curve()
fppi
,
miss_rate
=
sft
.
computeROC
(
confidenses
,
tp
,
nannotated
,
nframes
)
\ No newline at end of file
sft
.
plotLogLog
(
fppi
,
miss_rate
)
\ No newline at end of file
apps/sft/misk/sft.py
View file @
469eeea3
...
@@ -19,6 +19,34 @@ def convert2detections(rects, confs, crop_factor = 0.125):
...
@@ -19,6 +19,34 @@ def convert2detections(rects, confs, crop_factor = 0.125):
return
dts
return
dts
def
cascade
(
min_scale
,
max_scale
,
nscales
,
f
):
# where we use nms cv::SCascade::DOLLAR == 2
c
=
cv2
.
SCascade
(
min_scale
,
max_scale
,
nscales
,
2
)
xml
=
cv2
.
FileStorage
(
f
,
0
)
dom
=
xml
.
getFirstTopLevelNode
()
assert
c
.
load
(
dom
)
return
c
def
cumsum
(
n
):
cum
=
[]
y
=
0
for
i
in
n
:
y
+=
i
cum
.
append
(
y
)
return
cum
def
computeROC
(
confidenses
,
tp
,
nannotated
,
nframes
):
confidenses
,
tp
=
zip
(
*
sorted
(
zip
(
confidenses
,
tp
),
reverse
=
True
))
fp
=
[(
1
-
x
)
for
x
in
tp
]
fp
=
cumsum
(
fp
)
tp
=
cumsum
(
tp
)
miss_rate
=
[(
1
-
x
/
(
nannotated
+
0.000001
))
for
x
in
tp
]
fppi
=
[
x
/
float
(
nframes
)
for
x
in
fp
]
return
fppi
,
miss_rate
def
crop_rect
(
rect
,
factor
):
def
crop_rect
(
rect
,
factor
):
val_x
=
factor
*
float
(
rect
[
2
])
val_x
=
factor
*
float
(
rect
[
2
])
val_y
=
factor
*
float
(
rect
[
3
])
val_y
=
factor
*
float
(
rect
[
3
])
...
@@ -27,29 +55,28 @@ def crop_rect(rect, factor):
...
@@ -27,29 +55,28 @@ def crop_rect(rect, factor):
#
#
def
plot
_curve
(
):
def
plot
LogLog
(
fppi
,
miss_rate
):
fig
,
ax
=
plt
.
subplots
()
fig
,
ax
=
plt
.
subplots
()
fig
.
canvas
.
draw
()
fig
.
canvas
.
draw
()
x
=
np
.
linspace
(
pow
(
10
,
-
4
),
pow
(
10
,
1
),
101
)
y
=
1
-
x
plt
.
semilogy
(
x
,
y
,
color
=
'm'
,
linewidth
=
2
)
plt
.
xlabel
(
"fppi"
)
plt
.
xlabel
(
"fppi"
)
plt
.
ylabel
(
"miss rate"
)
plt
.
ylabel
(
"miss rate"
)
plt
.
title
(
"ROC curve Bahnhof"
)
plt
.
title
(
"ROC curve Bahnhof"
)
plt
.
yticks
(
[
0.05
,
0.10
,
0.20
,
0.30
,
0.40
,
0.50
,
0.64
,
0.80
])
#
plt.yticks( [0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.64, 0.80])
ylabels
=
[
item
.
get_text
()
for
item
in
ax
.
get_yticklabels
()]
#
ylabels = [item.get_text() for item in ax.get_yticklabels()]
ax
.
set_yticklabels
(
ylabels
)
#
ax.set_yticklabels( ylabels )
plt
.
grid
(
True
)
plt
.
grid
(
True
)
# plt.xticks( [pow(10, -4), pow(10, -3), pow(10, -2), pow(10, -1), pow(10, 0), pow(10,
0
)])
# plt.xticks( [pow(10, -4), pow(10, -3), pow(10, -2), pow(10, -1), pow(10, 0), pow(10,
1
)])
# xlabels = [item.get_text() for item in ax.get_xticklabels()]
# xlabels = [item.get_text() for item in ax.get_xticklabels()]
# ax.set_xticklabels( xlabels )
# ax.set_xticklabels( xlabels )
plt
.
xscale
(
'log'
)
plt
.
xscale
(
'log'
)
plt
.
yscale
(
'log'
)
plt
.
semilogy
(
fppi
,
miss_rate
,
color
=
'm'
,
linewidth
=
2
)
plt
.
show
()
plt
.
show
()
def
draw_rects
(
img
,
rects
,
color
,
l
=
lambda
x
,
y
:
x
+
y
):
def
draw_rects
(
img
,
rects
,
color
,
l
=
lambda
x
,
y
:
x
+
y
):
...
@@ -81,7 +108,6 @@ class Detection:
...
@@ -81,7 +108,6 @@ class Detection:
# we use rect-stype for dt and box style for gt. ToDo: fix it
# we use rect-stype for dt and box style for gt. ToDo: fix it
def
overlap
(
self
,
b
):
def
overlap
(
self
,
b
):
print
self
.
bb
,
"vs"
,
b
a
=
self
.
bb
a
=
self
.
bb
w
=
min
(
a
[
0
]
+
a
[
2
],
b
[
2
])
-
max
(
a
[
0
],
b
[
0
]);
w
=
min
(
a
[
0
]
+
a
[
2
],
b
[
2
])
-
max
(
a
[
0
],
b
[
0
]);
h
=
min
(
a
[
1
]
+
a
[
3
],
b
[
3
])
-
max
(
a
[
1
],
b
[
1
]);
h
=
min
(
a
[
1
]
+
a
[
3
],
b
[
3
])
-
max
(
a
[
1
],
b
[
1
]);
...
@@ -135,39 +161,16 @@ def norm_acpect_ratio(boxes, ratio):
...
@@ -135,39 +161,16 @@ def norm_acpect_ratio(boxes, ratio):
def
match
(
gts
,
dts
):
def
match
(
gts
,
dts
):
for
dt
in
dts
:
print
dt
.
bb
,
print
for
gt
in
gts
:
print
gt
# Cartesian product for each detection BB_dt with each BB_gt
# Cartesian product for each detection BB_dt with each BB_gt
overlaps
=
[[
dt
.
overlap
(
gt
)
for
gt
in
gts
]
for
dt
in
dts
]
overlaps
=
[[
dt
.
overlap
(
gt
)
for
gt
in
gts
]
for
dt
in
dts
]
print
overlaps
matches_gt
=
[
0
]
*
len
(
gts
)
matches_gt
=
[
0
]
*
len
(
gts
)
print
matches_gt
matches_dt
=
[
0
]
*
len
(
dts
)
matches_dt
=
[
0
]
*
len
(
dts
)
print
matches_dt
for
idx
,
row
in
enumerate
(
overlaps
):
for
idx
,
row
in
enumerate
(
overlaps
):
print
idx
,
row
imax
=
row
.
index
(
max
(
row
))
imax
=
row
.
index
(
max
(
row
))
if
(
matches_gt
[
imax
]
==
0
and
row
[
imax
]
>
0.5
):
if
(
matches_gt
[
imax
]
==
0
and
row
[
imax
]
>
0.5
):
matches_gt
[
imax
]
=
1
matches_gt
[
imax
]
=
1
matches_dt
[
idx
]
=
1
matches_dt
[
idx
]
=
1
return
matches_dt
print
matches_gt
\ No newline at end of file
print
matches_dt
fp
=
sum
(
1
for
x
in
matches_dt
if
x
==
0
)
fn
=
sum
(
1
for
x
in
matches_gt
if
x
==
0
)
return
fp
,
fn
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment