Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bob.paper.makeup_aim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.paper.makeup_aim
Commits
080cb1c0
Commit
080cb1c0
authored
Oct 14, 2019
by
Zohreh MOSTAANI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[vuln] added script to prepare box-plot and histogram for vulnaribility analysis
parent
851b1c18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
63 deletions
+105
-63
bob/paper/makeup_aim/script/plot_vuln.py
bob/paper/makeup_aim/script/plot_vuln.py
+104
-63
setup.py
setup.py
+1
-0
No files found.
bob/paper/makeup_aim/script/plot_vuln.py
View file @
080cb1c0
#!/usr/bin/env python
"""
Plots box-plot and histogram for similarity scores for face recognition system.
Usage:
plot_vuln.py [options] <scores>
plot_vuln.py --help
Options:
-h --help Show this screen.
-o <path>, --output=<path> The path to which the plots will be saved [default: ]
"""
import
os
from
docopt
import
docopt
import
bob.measure
import
matplotlib.pyplot
as
plt
import
numpy
import
numpy
as
np
from
bob.bio.base.score.load
import
load_score
from
bob.pad.base.script.vuln_figure
import
_iapmr_plot
from
matplotlib
import
gridspec
np
=
numpy
#--------------------------------------------------------------------
# Here are the global names used for the plots
def
return_scores
(
scores
):
print
(
"in function return_scores"
)
gen
=
scores
[
scores
[
'real_id'
]
==
scores
[
'claimed_id'
]][
'score'
]
makeup
=
scores
[
scores
[
'real_id'
]
==
'makeup'
][
'score'
]
plot_title
=
"LightCNN FR"
genuine_label
=
'Genuine'
makeup_label
=
'Makeup'
return
np
.
ascontiguousarray
(
gen
),
np
.
ascontiguousarray
(
makeup
)
# box-plot
box_plot_filename
=
'box-plot'
box_plot_ylabel
=
'Similarity Scores'
# histogram plot
historgram_filename
=
'hist-plot'
line_label
=
'FNMR threshold'
hist_plot_xlabel
=
'Similarity Scores'
hist_plot_ylabel
=
'Normalized Count'
def
main
():
#--------------------------------------------------------------------
# separating genuine and makeup scores
# import ipdb; ipdb.set_trace()
def
return_similarity_scores
(
scores
):
'''
Separates the necessary scores from the score list for genuine and makeup.
'''
directory
=
'/idiap/user/zmostaani/experiments/batl/aim_result/'
method
=
'aim_vuln/grandtest/nonorm/'
filename
=
'scores-dev'
gen
=
scores
[
scores
[
'real_id'
]
==
scores
[
'claimed_id'
]][
'score'
]
makeup
=
scores
[
scores
[
'real_id'
]
==
'makeup'
][
'score'
]
scores
=
load_score
(
os
.
path
.
join
(
directory
,
method
,
filename
))
gen_sim
=
1
+
np
.
ascontiguousarray
(
gen
)
makeup_sim
=
1
+
np
.
ascontiguousarray
(
makeup
)
return
gen_sim
,
makeup_sim
#--------------------------------------------------------------------
# plotting the box-plot
def
plot_box_plot
(
gen_scores
,
makeup_scores
,
output
):
'''
The box plots to show the effect of makeup on FR system
gen
,
makeup
=
return_scores
(
scores
)
print
(
"deviding scores"
)
- gen_scores: the scores for genuine faces without makeup
- makeup_scores: the scores for faces with makeup
- output: The file to which the plot will be saved.
'''
plt
.
style
.
use
(
'default'
)
...
...
@@ -41,21 +72,15 @@ def main():
fig
=
plt
.
figure
()
gs
=
gridspec
.
GridSpec
(
9
,
1
,
figure
=
fig
)
ax
=
plt
.
gcf
().
add_subplot
(
gs
[
1
:
9
])
ax
=
plt
.
gcf
().
add_subplot
(
gs
[
1
:
8
])
gen_sim
=
1
+
gen
makeup_sim
=
1
+
makeup
line_props
=
dict
(
color
=
"r"
,
alpha
=
0.3
)
bbox_props
=
dict
(
color
=
"b"
,
alpha
=
0.9
)
flier_props
=
dict
(
marker
=
"+"
,
markersize
=
4
,
markeredgecolor
=
"g"
)
whis_props
=
[
5
,
95
]
whisker_props
=
dict
(
linestyle
=
'--'
,
dashes
=
(
5
,
5
))
median_props
=
dict
(
color
=
"r"
)
bp
=
ax
.
boxplot
([
gen_s
im
,
makeup_sim
],
labels
=
[
'Genuine'
,
'Makeup'
],
bp
=
ax
.
boxplot
([
gen_s
cores
,
makeup_scores
],
labels
=
[
genuine_label
,
makeup_label
],
patch_artist
=
False
,
autorange
=
True
,
flierprops
=
flier_props
,
boxprops
=
bbox_props
,
whiskerprops
=
whisker_props
,
...
...
@@ -64,7 +89,6 @@ def main():
widths
=
0.25
,
)
top
=
1
bottom
=
0
ax
.
set_ylim
(
bottom
,
top
)
...
...
@@ -76,78 +100,95 @@ def main():
# overlay median value
ax
.
annotate
(
f"
{
y
:.
2
f
}
"
,
(
x
,
y
))
plt
.
ylabel
(
"Similarity Scores"
)
# plt.xlabel("")
plt
.
title
(
"LightCNN FR"
)
plt
.
savefig
(
os
.
path
.
join
(
directory
,
'boxplot-bob-new.png'
))
plt
.
ylabel
(
box_plot_ylabel
)
print
(
"plotting boxplot"
)
# plt.xlabel("Normalized count")
plt
.
title
(
plot_title
)
plt
.
savefig
(
output
)
plt
.
close
()
plt
.
style
.
use
(
'default'
)
#--------------------------------------------------------------------
# plotting the histogram
def
plot_histogram
(
gen_scores
,
makeup_scores
,
output
):
'''
The histogram to show the effect of makeup on FR system
- gen_scores: the scores for genuine faces without makeup
- makeup_scores: the scores for faces with makeup
- output: The file to which the plot will be saved.
'''
plt
.
style
.
use
(
'default'
)
plt
.
rcParams
[
'figure.figsize'
]
=
(
4
,
3
)
plt
.
rcParams
[
'figure.constrained_layout.use'
]
=
True
fig
=
plt
.
figure
()
gs
=
gridspec
.
GridSpec
(
9
,
1
,
figure
=
fig
)
gs
=
gridspec
.
GridSpec
(
9
,
1
,
figure
=
fig
)
ax
=
plt
.
gcf
().
add_subplot
(
gs
[
1
:
9
])
title
=
"LightCNN FR"
spoof_label
=
"Makeup"
th
=
bob
.
measure
.
frr_threshold
([],
gen_scores
,
0.1
)
# fig, ax = plt.subplots()
# ax = plt.gcf().add_subplot()
th
=
bob
.
measure
.
frr_threshold
([],
gen_sim
,
0.1
)
color_scheme
=
{
'genuine'
:
'#2ca02c'
,
'impostors'
:
'#1f77b4'
,
color_scheme
=
{
'genuine'
:
'#2ca02c'
,
'line'
:
'#d4257b'
,
'makeup'
:
'#ff7f0e'
}
alpha_scheme
=
{
'genuine'
:
0.9
,
'impostors'
:
0.8
,
'spoofs'
:
0.6
}
hatch_scheme
=
{
'genuine'
:
'//'
,
'impostors'
:
None
,
'spoofs'
:
None
}
alpha_scheme
=
{
'genuine'
:
0.9
,
'makeup'
:
0.6
}
hatch_scheme
=
{
'genuine'
:
'//'
,
'makeup'
:
None
}
lines
=
[]
line
=
plt
.
hist
(
gen_s
im
,
bins
=
10
,
color
=
color_scheme
[
'genuine'
],
line
=
plt
.
hist
(
gen_s
cores
,
bins
=
10
,
color
=
color_scheme
[
'genuine'
],
alpha
=
alpha_scheme
[
'genuine'
],
hatch
=
hatch_scheme
[
'genuine'
],
label
=
"Genuine"
,
density
=
True
)
label
=
genuine_label
,
density
=
True
)
lines
.
append
(
line
[
-
1
][
0
])
line
=
plt
.
axvline
(
x
=
th
,
ymin
=
0
,
ymax
=
1
,
linewidth
=
2
,
color
=
color_scheme
[
'line'
],
linestyle
=
'--'
,
label
=
"FNMR threshold"
)
label
=
line_label
)
lines
.
append
(
line
)
line
=
plt
.
hist
(
makeup_s
im
,
bins
=
10
,
color
=
color_scheme
[
'makeup'
],
alpha
=
alpha_scheme
[
'
spoofs
'
],
hatch
=
hatch_scheme
[
'
spoofs
'
],
density
=
True
,
label
=
spoof
_label
)
line
=
plt
.
hist
(
makeup_s
cores
,
bins
=
10
,
color
=
color_scheme
[
'makeup'
],
alpha
=
alpha_scheme
[
'
makeup
'
],
hatch
=
hatch_scheme
[
'
makeup
'
],
density
=
True
,
label
=
makeup
_label
)
lines
.
append
(
line
[
-
1
][
0
])
# ax.grid(True)
hs
,
ls
=
plt
.
gca
().
get_legend_handles_labels
()
# plt.sca(ax)
ax
.
grid
(
True
)
# ax.legend(handletextpad=0.9)
plt
.
xlabel
(
"Similarity Scores"
)
plt
.
ylabel
(
"Normalized Count"
)
plt
.
title
(
title
)
plt
.
xlabel
(
hist_plot_xlabel
)
plt
.
ylabel
(
hist_plot_ylabel
)
plt
.
title
(
plot_
title
)
# plt.tight_layout()
# plt.subplots_adjust(top=0.80)
by_label
=
dict
(
zip
(
ls
,
hs
))
fig
.
legend
(
by_label
.
values
(),
by_label
.
keys
(),
loc
=
'upper center'
,
ncol
=
3
,
framealpha
=
0.5
)
plt
.
savefig
(
os
.
path
.
join
(
directory
,
'makeup-FRR-bob-new.png'
))
plt
.
savefig
(
output
)
plt
.
close
()
def
main
():
args
=
docopt
(
__doc__
)
score_directory
=
args
[
'<scores>'
]
plots_directory
=
args
[
'--output'
]
scores
=
load_score
(
score_directory
)
gen_sim
,
makeup_sim
=
return_similarity_scores
(
scores
)
output1
=
os
.
path
.
join
(
plots_directory
,
box_plot_filename
)
plot_box_plot
(
gen_scores
=
gen_sim
,
makeup_scores
=
makeup_sim
,
output
=
output1
)
output2
=
os
.
path
.
join
(
plots_directory
,
historgram_filename
)
plot_histogram
(
gen_scores
=
gen_sim
,
makeup_scores
=
makeup_sim
,
output
=
output2
)
print
(
"The plots are saved in {} and {}"
.
format
(
output1
,
output2
))
print
(
"ploting histogram"
)
if
__name__
==
"__main__"
:
...
...
setup.py
View file @
080cb1c0
...
...
@@ -89,6 +89,7 @@ setup(
# scripts should be declared using this entry:
'console_scripts'
:
[
'annotate_db.py = bob.paper.makeup_aim.script.annotate_db:main'
,
'plot_vuln.py = bob.paper.makeup_aim.script.plot_vuln:main'
],
'bob.bio.config'
:
[
'ymu = bob.paper.makeup_aim.config.ymu'
,
...
...
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