Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.base
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.bio.base
Commits
68412583
There was a problem fetching the pipeline summary.
Commit
68412583
authored
7 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
Propagated the option to the
parent
54be3074
No related branches found
No related tags found
1 merge request
!103
Propagated the option --allow-missing-files .....
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/base/utils/io.py
+16
-4
16 additions, 4 deletions
bob/bio/base/utils/io.py
with
16 additions
and
4 deletions
bob/bio/base/utils/io.py
+
16
−
4
View file @
68412583
...
@@ -175,7 +175,7 @@ def save_compressed(data, filename, compression_type='bz2', create_link=False):
...
@@ -175,7 +175,7 @@ def save_compressed(data, filename, compression_type='bz2', create_link=False):
close_compressed
(
filename
,
hdf5
,
compression_type
,
create_link
)
close_compressed
(
filename
,
hdf5
,
compression_type
,
create_link
)
def
_generate_features
(
reader
,
paths
):
def
_generate_features
(
reader
,
paths
,
allow_missing_files
=
False
):
"""
Load and stack features a memory efficient way. This function is meant to
"""
Load and stack features a memory efficient way. This function is meant to
be used inside :py:func:`vstack_features`.
be used inside :py:func:`vstack_features`.
...
@@ -185,6 +185,8 @@ def _generate_features(reader, paths):
...
@@ -185,6 +185,8 @@ def _generate_features(reader, paths):
See the documentation of :py:func:`vstack_features`.
See the documentation of :py:func:`vstack_features`.
paths : ``collections.Iterable``
paths : ``collections.Iterable``
See the documentation of :py:func:`vstack_features`.
See the documentation of :py:func:`vstack_features`.
allow_missing_files : :obj:`bool`, optional
If ``True``, it ignores files that doesn
'
t exists
Yields
Yields
------
------
...
@@ -193,10 +195,17 @@ def _generate_features(reader, paths):
...
@@ -193,10 +195,17 @@ def _generate_features(reader, paths):
features and the shape of the first feature. The rest of objects are
features and the shape of the first feature. The rest of objects are
the actual values in features. The features are returned in C order.
the actual values in features. The features are returned in C order.
"""
"""
shape_check
=
False
for
i
,
path
in
enumerate
(
paths
):
for
i
,
path
in
enumerate
(
paths
):
if
allow_missing_files
and
not
os
.
path
.
isfile
(
path
):
logger
.
debug
(
"
... The file {0}, that does not exist, has been ignored .
"
.
format
(
path
))
continue
feature
=
numpy
.
atleast_2d
(
reader
(
path
))
feature
=
numpy
.
atleast_2d
(
reader
(
path
))
feature
=
numpy
.
ascontiguousarray
(
feature
)
feature
=
numpy
.
ascontiguousarray
(
feature
)
if
i
==
0
:
if
not
shape_check
:
shape_check
=
True
dtype
=
feature
.
dtype
dtype
=
feature
.
dtype
shape
=
list
(
feature
.
shape
)
shape
=
list
(
feature
.
shape
)
yield
(
dtype
,
shape
)
yield
(
dtype
,
shape
)
...
@@ -209,7 +218,7 @@ def _generate_features(reader, paths):
...
@@ -209,7 +218,7 @@ def _generate_features(reader, paths):
yield
value
yield
value
def
vstack_features
(
reader
,
paths
,
same_size
=
False
):
def
vstack_features
(
reader
,
paths
,
same_size
=
False
,
allow_missing_files
=
False
):
"""
Stacks all features in a memory efficient way.
"""
Stacks all features in a memory efficient way.
Parameters
Parameters
...
@@ -228,6 +237,9 @@ def vstack_features(reader, paths, same_size=False):
...
@@ -228,6 +237,9 @@ def vstack_features(reader, paths, same_size=False):
If ``True``, it assumes that arrays inside all the paths are the same
If ``True``, it assumes that arrays inside all the paths are the same
shape. If you know the features are the same size in all paths, set this
shape. If you know the features are the same size in all paths, set this
to ``True`` to improve the performance.
to ``True`` to improve the performance.
allow_missing_files : :obj:`bool`, optional
If ``True``, it ignores files that doesn
'
t exists
Returns
Returns
-------
-------
...
@@ -277,7 +289,7 @@ def vstack_features(reader, paths, same_size=False):
...
@@ -277,7 +289,7 @@ def vstack_features(reader, paths, same_size=False):
[
6
,
7
],
[
6
,
7
],
[
8
,
9
]])
[
8
,
9
]])
"""
"""
iterable
=
_generate_features
(
reader
,
paths
)
iterable
=
_generate_features
(
reader
,
paths
,
allow_missing_files
=
allow_missing_files
)
dtype
,
shape
=
next
(
iterable
)
dtype
,
shape
=
next
(
iterable
)
if
same_size
:
if
same_size
:
total_size
=
int
(
len
(
paths
)
*
numpy
.
prod
(
shape
))
total_size
=
int
(
len
(
paths
)
*
numpy
.
prod
(
shape
))
...
...
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