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
ac1c9afc
There was a problem fetching the pipeline summary.
Commit
ac1c9afc
authored
7 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
implement some tests too
parent
278917a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!112
SequentialExtractor: Apply extractor on training data always when apply=True
Pipeline
#
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/bio/base/extractor/stacks.py
+10
-4
10 additions, 4 deletions
bob/bio/base/extractor/stacks.py
bob/bio/base/test/dummy/extractor.py
+3
-3
3 additions, 3 deletions
bob/bio/base/test/dummy/extractor.py
bob/bio/base/test/test_stacks.py
+12
-0
12 additions, 0 deletions
bob/bio/base/test/test_stacks.py
with
25 additions
and
7 deletions
bob/bio/base/extractor/stacks.py
+
10
−
4
View file @
ac1c9afc
...
...
@@ -33,7 +33,7 @@ class MultipleExtractor(Extractor):
training_data
=
[
e
(
d
)
for
d
in
training_data
]
# if any of the extractors require splitting the data, the
# split_training_data_by_client is True.
if
e
.
split_training_data_by_client
:
el
if
e
.
split_training_data_by_client
:
e
.
train
(
training_data
,
extractor_file
)
if
not
apply
:
return
...
...
@@ -62,7 +62,8 @@ class MultipleExtractor(Extractor):
groups
=
self
.
get_extractor_groups
()
for
e
,
group
in
zip
(
self
.
processors
,
groups
):
f
.
cd
(
group
)
e
.
load
(
f
)
if
e
.
requires_training
:
e
.
load
(
f
)
f
.
cd
(
'
..
'
)
...
...
@@ -110,10 +111,15 @@ class SequentialExtractor(SequentialProcessor, MultipleExtractor):
def
train
(
self
,
training_data
,
extractor_file
):
with
HDF5File
(
extractor_file
,
'
w
'
)
as
f
:
groups
=
self
.
get_extractor_groups
()
for
e
,
group
in
zip
(
self
.
processors
,
groups
):
for
i
,
(
e
,
group
)
in
enumerate
(
zip
(
self
.
processors
,
groups
)):
if
i
==
len
(
self
.
processors
)
-
1
:
apply
=
False
else
:
apply
=
True
f
.
create_group
(
group
)
f
.
cd
(
group
)
training_data
=
self
.
train_one
(
e
,
training_data
,
f
,
apply
=
True
)
training_data
=
self
.
train_one
(
e
,
training_data
,
f
,
apply
=
apply
)
f
.
cd
(
'
..
'
)
def
read_feature
(
self
,
feature_file
):
...
...
This diff is collapsed.
Click to expand it.
bob/bio/base/test/dummy/extractor.py
+
3
−
3
View file @
ac1c9afc
import
numpy
import
bob.io.base
import
bob.
b
io.base
from
bob.bio.base.extractor
import
Extractor
...
...
@@ -12,10 +12,10 @@ class DummyExtractor (Extractor):
def
train
(
self
,
train_data
,
extractor_file
):
assert
isinstance
(
train_data
,
list
)
bob
.
io
.
base
.
save
(
_data
,
extractor_file
)
bob
.
b
io
.
base
.
save
(
_data
,
extractor_file
)
def
load
(
self
,
extractor_file
):
data
=
bob
.
io
.
base
.
load
(
extractor_file
)
data
=
bob
.
b
io
.
base
.
load
(
extractor_file
)
assert
(
_data
==
data
).
all
()
self
.
model
=
True
...
...
This diff is collapsed.
Click to expand it.
bob/bio/base/test/test_stacks.py
+
12
−
0
View file @
ac1c9afc
from
functools
import
partial
import
numpy
as
np
import
tempfile
from
bob.bio.base.utils.processors
import
(
SequentialProcessor
,
ParallelProcessor
)
from
bob.bio.base.preprocessor
import
(
SequentialPreprocessor
,
ParallelPreprocessor
,
CallablePreprocessor
)
from
bob.bio.base.extractor
import
(
SequentialExtractor
,
ParallelExtractor
,
CallableExtractor
)
from
bob.bio.base.test.dummy.extractor
import
extractor
as
dummy_extractor
DATA
=
[
0
,
1
,
2
,
3
,
4
]
PROCESSORS
=
[
partial
(
np
.
power
,
2
),
np
.
mean
]
...
...
@@ -43,3 +45,13 @@ def test_extractors():
proc
=
ParallelExtractor
(
processors
)
data
=
proc
(
DATA
)
assert
all
(
np
.
allclose
(
x1
,
x2
)
for
x1
,
x2
in
zip
(
data
,
PAR_DATA
))
def
test_trainable_extractors
():
processors
=
[
CallableExtractor
(
p
)
for
p
in
PROCESSORS
]
+
[
dummy_extractor
]
proc
=
SequentialExtractor
(
processors
)
with
tempfile
.
NamedTemporaryFile
(
suffix
=
'
.hdf5
'
)
as
f
:
proc
.
train
(
DATA
,
f
.
name
)
proc
.
load
(
f
.
name
)
data
=
proc
(
DATA
)
assert
np
.
allclose
(
data
,
SEQ_DATA
)
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