Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.pipelines
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
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.pipelines
Commits
4a3aac01
Commit
4a3aac01
authored
Nov 26, 2020
by
Tiago de Freitas Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Sample] Created a cached version of DelayedSampleSet
Fixed test case
parent
607bee73
Pipeline
#46115
passed with stage
in 3 minutes and 54 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
4 deletions
+33
-4
bob/pipelines/__init__.py
bob/pipelines/__init__.py
+1
-1
bob/pipelines/sample.py
bob/pipelines/sample.py
+15
-0
bob/pipelines/tests/test_samples.py
bob/pipelines/tests/test_samples.py
+14
-1
bob/pipelines/tests/test_wrappers.py
bob/pipelines/tests/test_wrappers.py
+3
-2
No files found.
bob/pipelines/__init__.py
View file @
4a3aac01
...
...
@@ -3,7 +3,7 @@ from . import transformers # noqa
from
.
import
utils
# noqa
from
.
import
xarray
as
xr
# noqa
from
.sample
import
DelayedSample
from
.sample
import
DelayedSampleSet
from
.sample
import
DelayedSampleSet
,
DelayedSampleSetCached
from
.sample
import
Sample
from
.sample
import
SampleSet
from
.sample
import
SampleBatch
...
...
bob/pipelines/sample.py
View file @
4a3aac01
...
...
@@ -187,6 +187,21 @@ class DelayedSampleSet(SampleSet):
return
self
.
_load
()
class
DelayedSampleSetCached
(
DelayedSampleSet
):
"""A cached version of DelayedSampleSet"""
def
__init__
(
self
,
load
,
parent
=
None
,
**
kwargs
):
super
().
__init__
(
load
,
parent
=
parent
,
kwargs
=
kwargs
)
self
.
_data
=
None
_copy_attributes
(
self
,
parent
,
kwargs
)
@
property
def
samples
(
self
):
if
self
.
_data
is
None
:
self
.
_data
=
self
.
_load
()
return
self
.
_data
class
SampleBatch
(
Sequence
,
_ReprMixin
):
"""A batch of samples that looks like [s.data for s in samples]
...
...
bob/pipelines/tests/test_samples.py
View file @
4a3aac01
...
...
@@ -8,7 +8,7 @@ import h5py
import
numpy
as
np
from
bob.pipelines
import
DelayedSample
from
bob.pipelines
import
DelayedSampleSet
from
bob.pipelines
import
DelayedSampleSet
,
DelayedSampleSetCached
from
bob.pipelines
import
Sample
from
bob.pipelines
import
SampleSet
from
bob.pipelines
import
hdf5_to_sample
...
...
@@ -56,6 +56,19 @@ def test_sampleset_collection():
assert
len
(
sampleset
)
==
n_samples
assert
sampleset
.
samples
==
samples
# Testing delayed sampleset cached
with
tempfile
.
TemporaryDirectory
()
as
dir_name
:
samples
=
[
Sample
(
data
,
key
=
str
(
i
))
for
i
,
data
in
enumerate
(
X
)]
filename
=
os
.
path
.
join
(
dir_name
,
"samples.pkl"
)
with
open
(
filename
,
"wb"
)
as
f
:
f
.
write
(
pickle
.
dumps
(
samples
))
sampleset
=
DelayedSampleSetCached
(
functools
.
partial
(
_load
,
filename
),
key
=
1
)
assert
len
(
sampleset
)
==
n_samples
assert
sampleset
.
samples
==
samples
def
test_sample_hdf5
():
n_samples
=
10
...
...
bob/pipelines/tests/test_wrappers.py
View file @
4a3aac01
...
...
@@ -189,8 +189,9 @@ def test_checkpoint_function_sample_transfomer():
)
features
=
transformer
.
transform
(
samples
)
# Checking if we have 8 chars in the second level
assert
len
(
features
[
0
].
_load
.
args
[
0
].
split
(
"/"
)[
-
2
])
==
8
# Checking if we can cast the has as integer
assert
isinstance
(
int
(
features
[
0
].
_load
.
args
[
0
].
split
(
"/"
)[
-
2
]),
int
)
_assert_all_close_numpy_array
(
oracle
,
[
s
.
data
for
s
in
features
])
...
...
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