Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.bio.base
Commits
d5d1d787
Commit
d5d1d787
authored
Jun 06, 2019
by
Amir MOHAMMADI
Browse files
Adds a sort command and small fixes
parent
d92d0fb9
Pipeline
#30731
passed with stage
in 41 minutes and 19 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/bio/base/annotator/FailSafe.py
View file @
d5d1d787
...
...
@@ -48,6 +48,8 @@ class FailSafe(Annotator):
if
not
annotations
:
logger
.
debug
(
"Annotator `%s' returned empty annotations."
,
annotator
)
else
:
logger
.
debug
(
"Annotator `%s' succeeded!"
,
annotator
)
kwargs
[
'annotations'
].
update
(
annotations
or
{})
# check if we have all the required annotations
if
all
(
key
in
kwargs
[
'annotations'
]
for
key
in
self
.
required_keys
):
...
...
bob/bio/base/grid.py
View file @
d5d1d787
...
...
@@ -8,13 +8,14 @@ PREDEFINED_QUEUES = {
'default'
:
{},
'2G'
:
{
'queue'
:
'all.q'
,
'memfree'
:
'2G'
},
'4G'
:
{
'queue'
:
'all.q'
,
'memfree'
:
'4G'
},
'4G-q1d'
:
{
'queue'
:
'q1d'
,
'memfree'
:
'4G'
},
'4G-io-big'
:
{
'queue'
:
'q1d'
,
'memfree'
:
'4G'
,
'io_big'
:
True
},
'8G'
:
{
'queue'
:
'q1d'
,
'memfree'
:
'8G'
},
'8G-io-big'
:
{
'queue'
:
'q1d'
,
'memfree'
:
'8G'
,
'io_big'
:
True
},
'16G'
:
{
'queue'
:
'q1dm'
,
'memfree'
:
'16G'
,
'pe_opt'
:
'pe_mth 2'
,
'hvmem'
:
'8G'
},
'16G-io-big'
:
{
'queue'
:
'q1dm'
,
'memfree'
:
'16G'
,
'pe_opt'
:
'pe_mth 2'
,
'hvmem'
:
'8G'
,
'io_big'
:
True
},
'32G'
:
{
'queue'
:
'q1dm'
,
'memfree'
:
'32G'
,
'pe_opt'
:
'pe_mth 4'
,
'hvmem'
:
'8G'
,
'io_big'
:
True
},
'64G'
:
{
'queue'
:
'q1dm'
,
'memfree'
:
'6
4
G'
,
'pe_opt'
:
'pe_mth 8'
,
'hvmem'
:
'
8
G'
,
'io_big'
:
True
},
'64G'
:
{
'queue'
:
'q1dm'
,
'memfree'
:
'
5
6G'
,
'pe_opt'
:
'pe_mth 8'
,
'hvmem'
:
'
7
G'
,
'io_big'
:
True
},
'Week'
:
{
'queue'
:
'q1wm'
,
'memfree'
:
'32G'
,
'pe_opt'
:
'pe_mth 4'
,
'hvmem'
:
'8G'
},
'GPU'
:
{
'queue'
:
'gpu'
}
}
...
...
bob/bio/base/script/sort.py
0 → 100644
View file @
d5d1d787
"""Sorts score files based on their score value
"""
import
click
import
logging
import
numpy
from
bob.bio.base.score.load
import
load_score
,
dump_score
from
bob.extension.scripts.click_helper
import
verbosity_option
,
log_parameters
logger
=
logging
.
getLogger
(
__name__
)
@
click
.
command
(
epilog
=
"""
\b
Examples:
$ bob bio sort -vvv /path/to/scores
"""
)
@
click
.
argument
(
"score_paths"
,
type
=
click
.
Path
(
exists
=
True
,
file_okay
=
True
,
dir_okay
=
False
,
writable
=
True
),
nargs
=-
1
,
)
@
verbosity_option
()
def
sort
(
score_paths
,
**
kwargs
):
"""Sorts score files based on their score values
The conversion happens in-place; backup your scores before using this script
"""
log_parameters
(
logger
)
for
path
in
score_paths
:
logger
.
info
(
"Sorting: %s"
,
path
)
scores
=
load_score
(
path
)
scores
=
scores
[
numpy
.
argsort
(
scores
[
"score"
])]
dump_score
(
path
,
scores
)
bob/bio/base/test/test_commands.py
View file @
d5d1d787
'''Tests for bob.measure scripts'''
import
sys
import
filecmp
import
click
from
click.testing
import
CliRunner
import
shutil
import
pkg_resources
from
..script
import
commands
import
numpy
import
nose
from
bob.extension.scripts.click_helper
import
assert_click_runner_result
from
..script
import
commands
,
sort
from
..score
import
scores
def
test_metrics
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
...
...
@@ -87,7 +89,6 @@ def test_metrics():
assert_click_runner_result
(
result
)
def
test_roc
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/dev-4col.txt'
)
...
...
@@ -138,7 +139,6 @@ def test_roc():
assert_click_runner_result
(
result
)
def
test_det
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/dev-4col.txt'
)
...
...
@@ -170,7 +170,6 @@ def test_det():
click
.
echo
(
result
.
output
)
assert_click_runner_result
(
result
)
dev_nonorm
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/scores-nonorm-dev'
)
dev_ztnorm
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
...
...
@@ -225,7 +224,6 @@ def test_epc():
assert_click_runner_result
(
result
)
def
test_hist
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/dev-4col.txt'
)
...
...
@@ -260,7 +258,6 @@ def test_hist():
assert_click_runner_result
(
result
)
def
test_cmc
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/scores-cmc-5col.txt'
)
...
...
@@ -296,8 +293,6 @@ def test_cmc():
assert_click_runner_result
(
result
)
def
test_dir
():
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/scores-nonorm-openset-dev'
)
...
...
@@ -317,3 +312,34 @@ def test_dir():
if
result
.
output
:
click
.
echo
(
result
.
output
)
assert_click_runner_result
(
result
)
def
test_sort
():
def
sorted_scores
(
score_lines
):
lines
=
[]
floats
=
[]
for
line
in
score_lines
:
lines
.
append
(
line
)
floats
.
append
(
line
[
-
1
])
sort_idx
=
numpy
.
argsort
(
floats
)
lines
=
[
lines
[
i
]
for
i
in
sort_idx
]
return
lines
dev1
=
pkg_resources
.
resource_filename
(
'bob.bio.base.test'
,
'data/scores-nonorm-dev'
)
runner
=
CliRunner
()
with
runner
.
isolated_filesystem
():
# create a temporary sort file and sort it and check if it is sorted!
path
=
"scores.txt"
shutil
.
copy
(
dev1
,
path
)
result
=
runner
.
invoke
(
sort
.
sort
,
[
path
])
assert_click_runner_result
(
result
,
exit_code
=
0
)
# load dev1 and sort it and compare to path
dev1_sorted
=
sorted_scores
(
scores
(
dev1
))
path_scores
=
list
(
scores
(
path
))
nose
.
tools
.
assert_list_equal
(
dev1_sorted
,
path_scores
)
bob/bio/base/utils/io.py
View file @
d5d1d787
...
...
@@ -306,7 +306,10 @@ def vstack_features(reader, paths, same_size=False, allow_missing_files=False):
raise
ValueError
(
"Both same_size and allow_missing_files cannot be True at"
" the same time."
)
iterable
=
_generate_features
(
reader
,
paths
,
same_size
,
allow_missing_files
)
dtype
,
shape
=
next
(
iterable
)
try
:
dtype
,
shape
=
next
(
iterable
)
except
StopIteration
:
return
numpy
.
array
([])
if
same_size
:
total_size
=
int
(
len
(
paths
)
*
numpy
.
prod
(
shape
))
all_features
=
numpy
.
fromiter
(
iterable
,
dtype
,
total_size
)
...
...
conda/meta.yaml
View file @
d5d1d787
...
...
@@ -75,6 +75,7 @@ test:
-
bob bio dir --help
-
bob bio gen --help
-
bob bio evaluate --help
-
bob bio sort --help
-
nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
-
sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
-
sphinx-build -aEb doctest {{ project_dir }}/doc sphinx
...
...
setup.py
View file @
d5d1d787
...
...
@@ -149,6 +149,7 @@ setup(
'gen = bob.bio.base.script.gen:gen'
,
'evaluate = bob.bio.base.script.commands:evaluate'
,
'baseline = bob.bio.base.script.baseline:baseline'
,
'sort = bob.bio.base.script.sort:sort'
,
],
# annotators
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment