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.video
Commits
487b65cd
Commit
487b65cd
authored
Jun 19, 2015
by
Manuel Günther
Browse files
Introduced data type tests
parent
d41de6b0
Changes
5
Hide whitespace changes
Inline
Side-by-side
MANIFEST.in
View file @
487b65cd
include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt
include README.rst bootstrap-buildout.py buildout.cfg
develop.cfg
COPYING version.txt
requirements.txt
recursive-include doc *.py *.rst
recursive-include bob/bio/video/test/data *.hdf5 *.avi
bob/bio/video/algorithm/Algorithm.py
View file @
487b65cd
...
...
@@ -37,14 +37,19 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
self
.
compressed_io
=
compressed_io
def
_check_feature
(
self
,
frames
):
assert
isinstance
(
frames
,
utils
.
FrameContainer
)
# PROJECTION
def
train_projector
(
self
,
data_list
,
projector_file
):
"""Trains the projector using features from selected frames."""
if
self
.
split_training_features_by_client
:
training_features
=
[[
frame
[
1
]
for
frame_container
in
client_containers
for
frame
in
self
.
frame_selector
(
frame_container
)]
for
client_containers
in
data_list
]
[
self
.
_check_feature
(
frames
)
for
client_frames
in
data_list
for
frames
in
client_frames
]
training_features
=
[[
frame
[
1
]
for
frames
in
client_frames
for
frame
in
self
.
frame_selector
(
frames
)]
for
client_frames
in
data_list
]
else
:
training_features
=
[
frame
[
1
]
for
frame_container
in
data_list
for
frame
in
self
.
frame_selector
(
frame_container
)]
[
self
.
_check_feature
(
frames
)
for
frames
in
data_list
]
training_features
=
[
frame
[
1
]
for
frames
in
data_list
for
frame
in
self
.
frame_selector
(
frames
)]
self
.
algorithm
.
train_projector
(
training_features
,
projector_file
)
...
...
@@ -52,10 +57,11 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
return
self
.
algorithm
.
load_projector
(
projector_file
)
def
project
(
self
,
frame
_container
):
def
project
(
self
,
frame
s
):
"""Projects each frame and saves them in a frame container."""
self
.
_check_feature
(
frames
)
fc
=
utils
.
FrameContainer
()
for
index
,
frame
,
quality
in
self
.
frame_selector
(
frame
_container
):
for
index
,
frame
,
quality
in
self
.
frame_selector
(
frame
s
):
# extract features
projected
=
self
.
algorithm
.
project
(
frame
)
features
=
projected
if
isinstance
(
projected
,
(
list
,
tuple
))
else
projected
.
copy
()
...
...
@@ -64,11 +70,12 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
return
fc
def
save_feature
(
self
,
frames
,
projected_file
):
def
write_feature
(
self
,
frames
,
projected_file
):
self
.
_check_feature
(
frames
)
if
self
.
compressed_io
:
return
utils
.
save_compressed
(
frame
_container
,
projected_file
,
self
.
algorithm
.
write_feature
)
return
utils
.
save_compressed
(
frame
s
,
projected_file
,
self
.
algorithm
.
write_feature
)
else
:
frame
_container
.
save
(
bob
.
io
.
base
.
HDF5File
(
projected_file
,
'w'
),
self
.
algorithm
.
write_feature
)
frame
s
.
save
(
bob
.
io
.
base
.
HDF5File
(
projected_file
,
'w'
),
self
.
algorithm
.
write_feature
)
def
read_feature
(
self
,
projected_file
):
if
self
.
compressed_io
:
...
...
@@ -80,7 +87,8 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
# ENROLLMENT
def
train_enroller
(
self
,
training_frames
,
enroller_file
):
features
=
[[
frame
[
1
]
for
frame_container
in
client_frames
for
frame
in
self
.
enroll_frame_selector
(
frame_container
)]
for
client_frames
in
training_frames
]
[
self
.
_check_feature
(
frames
)
for
client_frames
in
training_frames
for
frames
in
client_frames
]
features
=
[[
frame
[
1
]
for
frames
in
client_frames
for
frame
in
self
.
enroll_frame_selector
(
frames
)]
for
client_frames
in
training_frames
]
self
.
algorithm
.
train_enroller
(
features
,
enroller_file
)
def
load_enroller
(
self
,
enroller_file
):
...
...
@@ -89,12 +97,13 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
def
enroll
(
self
,
enroll_frames
):
"""Enrolls the model from features of all images of all videos."""
features
=
[
frame
[
1
]
for
frame_container
in
enroll_frames
for
frame
in
self
.
enroll_frame_selector
(
frame_container
)]
[
self
.
_check_feature
(
frames
)
for
frames
in
enroll_frames
]
features
=
[
frame
[
1
]
for
frames
in
enroll_frames
for
frame
in
self
.
enroll_frame_selector
(
frames
)]
return
self
.
algorithm
.
enroll
(
features
)
def
sav
e_model
(
self
,
model
,
filename
):
def
writ
e_model
(
self
,
model
,
filename
):
"""Saves the model using the algorithm's save function."""
self
.
algorithm
.
sav
e_model
(
model
,
filename
)
self
.
algorithm
.
writ
e_model
(
model
,
filename
)
# SCORING
...
...
@@ -105,6 +114,7 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
def
read_probe
(
self
,
filename
):
"""Reads the model using the algorithm's read function."""
# TODO: check if it is really necessary that we read other types than FrameContainers here...
try
:
if
self
.
compressed_io
:
return
utils
.
load_compressed
(
filename
,
self
.
algorithm
.
read_probe
)
...
...
@@ -115,6 +125,7 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
def
score
(
self
,
model
,
probe
):
"""Computes the score between the given model and the probe, which is a list of frames."""
# TODO: check if it is really necessary that we treat other types than FrameContainers here...
if
isinstance
(
probe
,
utils
.
FrameContainer
):
features
=
[
frame
[
1
]
for
frame
in
probe
]
return
self
.
algorithm
.
score_for_multiple_probes
(
model
,
features
)
...
...
@@ -124,5 +135,6 @@ class Algorithm (bob.bio.base.algorithm.Algorithm):
def
score_for_multiple_probes
(
self
,
model
,
probes
):
"""Computes the score between the given model and the probes, where each probe is a list of frames."""
[
self
.
_check_feature
(
frames
)
for
frames
in
probes
]
probe
=
[
frame
[
1
]
for
frame
in
probe
for
probe
in
probes
]
return
self
.
algorithm
.
score_for_multiple_probes
(
model
,
probe
)
bob/bio/video/extractor/Extractor.py
View file @
487b65cd
...
...
@@ -22,14 +22,25 @@ class Extractor (bob.bio.base.extractor.Extractor):
self
.
frame_selector
=
frame_selector
self
.
compressed_io
=
compressed_io
# register extractor's details
bob
.
bio
.
base
.
extractor
.
Extractor
.
__init__
(
self
,
requires_training
=
self
.
extractor
.
requires_training
,
split_training_data_by_client
=
self
.
extractor
.
split_training_data_by_client
,
extractor
=
extractor
,
frame_selector
=
frame_selector
,
compressed_io
=
compressed_io
)
bob
.
bio
.
base
.
extractor
.
Extractor
.
__init__
(
self
,
requires_training
=
self
.
extractor
.
requires_training
,
split_training_data_by_client
=
self
.
extractor
.
split_training_data_by_client
,
extractor
=
extractor
,
frame_selector
=
frame_selector
,
compressed_io
=
compressed_io
)
def
_check_feature
(
self
,
frames
):
assert
isinstance
(
frames
,
utils
.
FrameContainer
)
def
__call__
(
self
,
frame_container
,
annotations
=
None
):
def
__call__
(
self
,
frames
,
annotations
=
None
):
"""Extracts the frames from the video and returns a frame container."""
# now, go through the frames and extract the features
self
.
_check_feature
(
frames
)
# go through the frames and extract the features
fc
=
utils
.
FrameContainer
()
for
index
,
frame
,
quality
in
self
.
frame_selector
(
frame
_container
):
for
index
,
frame
,
quality
in
self
.
frame_selector
(
frame
s
):
# extract features
extracted
=
self
.
extractor
(
frame
)
# add features to new frame container
...
...
@@ -43,19 +54,22 @@ class Extractor (bob.bio.base.extractor.Extractor):
else
:
return
utils
.
FrameContainer
(
bob
.
io
.
base
.
HDF5File
(
filename
),
self
.
extractor
.
read_feature
)
def
write_feature
(
self
,
frame_container
,
filename
):
def
write_feature
(
self
,
frames
,
filename
):
self
.
_check_feature
(
frames
)
if
self
.
compressed_io
:
return
utils
.
save_compressed
(
frame
_container
,
filename
,
self
.
extractor
.
write_feature
)
return
utils
.
save_compressed
(
frame
s
,
filename
,
self
.
extractor
.
write_feature
)
else
:
frame
_container
.
save
(
bob
.
io
.
base
.
HDF5File
(
filename
,
'w'
),
self
.
extractor
.
write_feature
)
frame
s
.
save
(
bob
.
io
.
base
.
HDF5File
(
filename
,
'w'
),
self
.
extractor
.
write_feature
)
def
train
(
self
,
data_list
,
extractor_file
):
"""Trains the feature extractor with the image data of the given frames."""
if
self
.
split_training_data_by_client
:
features
=
[[
frame
[
1
]
for
frame_container
in
client_containers
for
frame
in
self
.
frame_selector
(
frame_container
)]
for
client_containers
in
data_list
]
[
self
.
_check_feature
(
frames
)
for
client_frames
in
data_list
for
frames
in
client_frames
]
features
=
[[
frame
[
1
]
for
frames
in
client_frames
for
frame
in
self
.
frame_selector
(
frames
)]
for
client_frames
in
data_list
]
else
:
features
=
[
frame
[
1
]
for
frame_container
in
data_list
for
frame
in
self
.
frame_selector
(
frame_container
)]
[
self
.
_check_feature
(
frames
)
for
frames
in
data_list
]
features
=
[
frame
[
1
]
for
frames
in
data_list
for
frame
in
self
.
frame_selector
(
frames
)]
self
.
extractor
.
train
(
features
,
extractor_file
)
def
load
(
self
,
extractor_file
):
...
...
bob/bio/video/preprocessor/Preprocessor.py
View file @
487b65cd
...
...
@@ -24,14 +24,22 @@ class Preprocessor (bob.bio.base.preprocessor.Preprocessor):
else
:
raise
ValueError
(
"The given algorithm could not be interpreter"
)
bob
.
bio
.
base
.
preprocessor
.
Preprocessor
.
__init__
(
self
,
preprocessor
=
preprocessor
,
frame_selector
=
frame_selector
,
compressed_io
=
compressed_io
)
bob
.
bio
.
base
.
preprocessor
.
Preprocessor
.
__init__
(
self
,
preprocessor
=
preprocessor
,
frame_selector
=
frame_selector
,
compressed_io
=
compressed_io
)
self
.
frame_selector
=
frame_selector
self
.
quality_function
=
quality_function
self
.
compressed_io
=
compressed_io
def
_check_feature
(
self
,
frames
):
assert
isinstance
(
frames
,
utils
.
FrameContainer
)
def
__call__
(
self
,
frame_container
,
annotations
=
None
):
def
__call__
(
self
,
frames
,
annotations
=
None
):
"""Extracts the frames from the video and returns a frame container.
Faces are extracted for all frames in the given frame container, using the ``preprocessor`` specified in the contructor.
...
...
@@ -41,10 +49,13 @@ class Preprocessor (bob.bio.base.preprocessor.Preprocessor):
The value is another dictionary, building the relation between keypoint names and their location, e.g., {'leye' : (le_y, le_x), 'reye' : (re_y, re_x)}
The annotations for the according frames, if present, are passed to the preprocessor.
"""
self
.
_check_feature
(
frames
)
annots
=
None
fc
=
utils
.
FrameContainer
()
for
index
,
frame
,
_
in
frame
_container
:
for
index
,
frame
,
_
in
frame
s
:
# if annotations are given, we take them
if
annotations
is
not
None
:
annots
=
annotations
[
index
]
...
...
@@ -75,8 +86,10 @@ class Preprocessor (bob.bio.base.preprocessor.Preprocessor):
else
:
return
utils
.
FrameContainer
(
bob
.
io
.
base
.
HDF5File
(
filename
),
self
.
preprocessor
.
read_data
)
def
save_data
(
self
,
frame_container
,
filename
):
def
write_data
(
self
,
frames
,
filename
):
self
.
_check_feature
(
frames
)
if
self
.
compressed_io
:
return
utils
.
save_compressed
(
frame
_container
,
filename
,
self
.
preprocessor
.
write_data
)
return
utils
.
save_compressed
(
frame
s
,
filename
,
self
.
preprocessor
.
write_data
)
else
:
frame
_container
.
save
(
bob
.
io
.
base
.
HDF5File
(
filename
,
'w'
),
self
.
preprocessor
.
write_data
)
frame
s
.
save
(
bob
.
io
.
base
.
HDF5File
(
filename
,
'w'
),
self
.
preprocessor
.
write_data
)
buildout.cfg
View file @
487b65cd
...
...
@@ -18,7 +18,7 @@ develop = src/bob.bio.base
.
; options for bob.buildout
debug =
tru
e
debug =
fals
e
verbose = true
newest = false
...
...
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