Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.measure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.measure
Commits
5e707069
Commit
5e707069
authored
9 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Solved issue
#6
parent
3c84d87b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/measure/__init__.py
+3
-14
3 additions, 14 deletions
bob/measure/__init__.py
bob/measure/load.py
+19
-44
19 additions, 44 deletions
bob/measure/load.py
bob/measure/test_error.py
+21
-11
21 additions, 11 deletions
bob/measure/test_error.py
with
43 additions
and
69 deletions
bob/measure/__init__.py
+
3
−
14
View file @
5e707069
...
@@ -130,22 +130,11 @@ def recognition_rate(cmc_scores, threshold=None):
...
@@ -130,22 +130,11 @@ def recognition_rate(cmc_scores, threshold=None):
correct
+=
1.
correct
+=
1.
else
:
else
:
#If threshold is NOT None, we have an openset identification
#If threshold is NOT None, we have an openset identification
if
(
len
(
pos
)
>
0
):
# if we have positive scores the comparison is considered correct
# if the positive score is higher than the threshold AND all negative scores
max_pos
=
numpy
.
max
(
pos
)
max_pos
=
numpy
.
max
(
pos
)
if
((
threshold
<
max_pos
)
and
(
neg
<
max_pos
).
all
()):
if
((
threshold
<
max_pos
)
and
(
neg
<
max_pos
).
all
()):
correct
+=
1.
correct
+=
1.
else
:
#If we don't have a positive score we only will consider
#a correct classification if ALL the negative scores are smaller than the threshold
if
(
neg
<
threshold
).
all
():
correct
+=
1.
# return relative number of correctly matched scores
# return relative number of correctly matched scores
return
correct
/
float
(
len
(
cmc_scores
))
return
correct
/
float
(
len
(
cmc_scores
))
...
...
This diff is collapsed.
Click to expand it.
bob/measure/load.py
+
19
−
44
View file @
5e707069
...
@@ -128,7 +128,7 @@ def split_four_column(filename):
...
@@ -128,7 +128,7 @@ def split_four_column(filename):
return
(
numpy
.
array
(
neg
,
numpy
.
float64
),
numpy
.
array
(
pos
,
numpy
.
float64
))
return
(
numpy
.
array
(
neg
,
numpy
.
float64
),
numpy
.
array
(
pos
,
numpy
.
float64
))
def
cmc_four_column
(
filename
,
load_only_negatives
=
False
):
def
cmc_four_column
(
filename
):
"""
"""
cmc_four_column(filename) -> cmc_scores
cmc_four_column(filename) -> cmc_scores
...
@@ -148,9 +148,6 @@ def cmc_four_column(filename, load_only_negatives=False):
...
@@ -148,9 +148,6 @@ def cmc_four_column(filename, load_only_negatives=False):
``filename`` : str or file-like
``filename`` : str or file-like
The file that will be opened with :py:func:`open_file` containing the scores.
The file that will be opened with :py:func:`open_file` containing the scores.
``load_only_negatives`` : boolean
Set this argument to **True** if you want also to load the probes that has negative scores **only** (used for open-set recognition).
**Returns:**
**Returns:**
...
@@ -182,7 +179,6 @@ def cmc_four_column(filename, load_only_negatives=False):
...
@@ -182,7 +179,6 @@ def cmc_four_column(filename, load_only_negatives=False):
retval
=
[]
retval
=
[]
import
logging
import
logging
logger
=
logging
.
getLogger
(
'
bob
'
)
logger
=
logging
.
getLogger
(
'
bob
'
)
if
(
not
load_only_negatives
):
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
if
probe_name
in
neg_dict
:
if
probe_name
in
neg_dict
:
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
(
pos_dict
[
probe_name
],
numpy
.
float64
)))
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
(
pos_dict
[
probe_name
],
numpy
.
float64
)))
...
@@ -194,13 +190,6 @@ def cmc_four_column(filename, load_only_negatives=False):
...
@@ -194,13 +190,6 @@ def cmc_four_column(filename, load_only_negatives=False):
if
not
probe_name
in
pos_dict
.
keys
():
if
not
probe_name
in
pos_dict
.
keys
():
logger
.
warn
(
'
For probe name
"
%s
"
there are only negative scores. This probe name is ignored.
'
%
probe_name
)
logger
.
warn
(
'
For probe name
"
%s
"
there are only negative scores. This probe name is ignored.
'
%
probe_name
)
else
:
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
(
pos_dict
[
probe_name
],
numpy
.
float64
)))
for
probe_name
in
sorted
(
neg_dict
.
keys
()):
if
not
probe_name
in
pos_dict
.
keys
():
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
([],
numpy
.
float64
)))
return
retval
return
retval
...
@@ -288,7 +277,7 @@ def split_five_column(filename):
...
@@ -288,7 +277,7 @@ def split_five_column(filename):
return
(
numpy
.
array
(
neg
,
numpy
.
float64
),
numpy
.
array
(
pos
,
numpy
.
float64
))
return
(
numpy
.
array
(
neg
,
numpy
.
float64
),
numpy
.
array
(
pos
,
numpy
.
float64
))
def
cmc_five_column
(
filename
,
load_only_negatives
=
False
):
def
cmc_five_column
(
filename
):
"""
"""
cmc_four_column(filename) -> cmc_scores
cmc_four_column(filename) -> cmc_scores
...
@@ -306,10 +295,6 @@ def cmc_five_column(filename, load_only_negatives=False):
...
@@ -306,10 +295,6 @@ def cmc_five_column(filename, load_only_negatives=False):
``filename`` : str or file-like
``filename`` : str or file-like
The file that will be opened with :py:func:`open_file` containing the scores.
The file that will be opened with :py:func:`open_file` containing the scores.
``load_only_negatives`` : boolean
Set this argument to **True** if you want also to load the probes that has negative scores **only** (used for open-set recognition).
**Returns:**
**Returns:**
``cmc_scores`` : [(array_like(1D, float), array_like(1D, float))]
``cmc_scores`` : [(array_like(1D, float), array_like(1D, float))]
...
@@ -336,7 +321,6 @@ def cmc_five_column(filename, load_only_negatives=False):
...
@@ -336,7 +321,6 @@ def cmc_five_column(filename, load_only_negatives=False):
retval
=
[]
retval
=
[]
import
logging
import
logging
logger
=
logging
.
getLogger
(
'
bob
'
)
logger
=
logging
.
getLogger
(
'
bob
'
)
if
(
not
load_only_negatives
):
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
if
probe_name
in
neg_dict
:
if
probe_name
in
neg_dict
:
...
@@ -347,14 +331,5 @@ def cmc_five_column(filename, load_only_negatives=False):
...
@@ -347,14 +331,5 @@ def cmc_five_column(filename, load_only_negatives=False):
for
probe_name
in
sorted
(
neg_dict
.
keys
()):
for
probe_name
in
sorted
(
neg_dict
.
keys
()):
if
not
probe_name
in
pos_dict
.
keys
():
if
not
probe_name
in
pos_dict
.
keys
():
logger
.
warn
(
'
For probe name
"
%s
"
there are only negative scores. This probe name is ignored.
'
%
probe_name
)
logger
.
warn
(
'
For probe name
"
%s
"
there are only negative scores. This probe name is ignored.
'
%
probe_name
)
else
:
for
probe_name
in
sorted
(
pos_dict
.
keys
()):
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
(
pos_dict
[
probe_name
],
numpy
.
float64
)))
for
probe_name
in
sorted
(
neg_dict
.
keys
()):
if
not
probe_name
in
pos_dict
.
keys
():
retval
.
append
((
numpy
.
array
(
neg_dict
[
probe_name
],
numpy
.
float64
),
numpy
.
array
([],
numpy
.
float64
)))
return
retval
return
retval
This diff is collapsed.
Click to expand it.
bob/measure/test_error.py
+
21
−
11
View file @
5e707069
...
@@ -326,20 +326,30 @@ def test_calibration():
...
@@ -326,20 +326,30 @@ def test_calibration():
def
test_open_set_recognition_rate
():
def
test_open_set_recognition_rate
():
far_value
=
0.01
#No error files
#No error files
scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
),
load_only_negatives
=
True
)
cmc_scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
0.5
),
1.0
normal_scores
=
bob
.
measure
.
load
.
split_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
10.
),
0.222222222222
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
),
1.0
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
0.5
),
1.0
t
=
bob
.
measure
.
far_threshold
(
normal_scores
[
0
],
normal_scores
[
1
],
far_value
)
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
t
),
1.0
#One error
#One error
scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set-one-error.txt
"
),
cmc_scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
load_only_negatives
=
True
)
normal_scores
=
bob
.
measure
.
load
.
split_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
0.5
),
0.888888888889
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
),
0.857142857143
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
10.
),
0.222222222222
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
0.5
),
0.857142857143
t
=
bob
.
measure
.
far_threshold
(
normal_scores
[
0
],
normal_scores
[
1
],
far_value
)
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
t
),
0.857142857143
#Two errors
#Two errors
scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set-two-errors.txt
"
),
cmc_scores
=
bob
.
measure
.
load
.
cmc_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
load_only_negatives
=
True
)
normal_scores
=
bob
.
measure
.
load
.
split_four_column
(
F
(
"
scores-cmc-4col-open-set.txt
"
))
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
0.5
),
0.777777777778
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
),
0.857142857143
assert
bob
.
measure
.
recognition_rate
(
scores
,
threshold
=
10.
),
0.111111111111
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
0.5
),
0.857142857143
t
=
bob
.
measure
.
far_threshold
(
normal_scores
[
0
],
normal_scores
[
1
],
far_value
)
assert
bob
.
measure
.
recognition_rate
(
cmc_scores
,
threshold
=
t
),
0.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment