Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.bio.face
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
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.bio.face
Commits
bd592d5a
Commit
bd592d5a
authored
Dec 01, 2020
by
Tiago de Freitas Pereira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[db] implementing MEDS database in the new interface
parent
a8a26357
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
233 additions
and
168 deletions
+233
-168
bob/bio/face/database/__init__.py
bob/bio/face/database/__init__.py
+17
-16
bob/bio/face/database/meds.py
bob/bio/face/database/meds.py
+35
-0
bob/bio/face/database/sample_loaders.py
bob/bio/face/database/sample_loaders.py
+15
-79
bob/bio/face/test/test_databases.py
bob/bio/face/test/test_databases.py
+166
-73
No files found.
bob/bio/face/database/__init__.py
View file @
bd592d5a
...
...
@@ -12,13 +12,13 @@ from .multipie import MultipieBioDatabase
from
.ijbc
import
IJBCBioDatabase
from
.replaymobile
import
ReplayMobileBioDatabase
from
.fargo
import
FargoBioDatabase
from
.meds
import
MEDSDatabase
# gets sphinx autodoc done right - don't remove it
def
__appropriate__
(
*
args
):
"""Says object was actually declared here, and not in the import module.
"""Says object was actually declared here, and not in the import module.
Fixing sphinx warnings of not being able to find classes, when path is shortened.
Parameters:
...
...
@@ -28,20 +28,21 @@ def __appropriate__(*args):
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for
obj
in
args
:
obj
.
__module__
=
__name__
for
obj
in
args
:
obj
.
__module__
=
__name__
__appropriate__
(
FaceBioFile
,
MobioBioDatabase
,
ReplayBioDatabase
,
AtntBioDatabase
,
GBUBioDatabase
,
ARFaceBioDatabase
,
LFWBioDatabase
,
MultipieBioDatabase
,
IJBCBioDatabase
,
ReplayMobileBioDatabase
,
FargoBioDatabase
FaceBioFile
,
MobioBioDatabase
,
ReplayBioDatabase
,
AtntBioDatabase
,
GBUBioDatabase
,
ARFaceBioDatabase
,
LFWBioDatabase
,
MultipieBioDatabase
,
IJBCBioDatabase
,
ReplayMobileBioDatabase
,
FargoBioDatabase
,
)
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
'_'
)]
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
"_"
)]
bob/bio/face/database/meds.py
0 → 100644
View file @
bd592d5a
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
"""
MEDS database implementation
"""
from
bob.bio.base.database
import
CSVDatasetDevEval
,
CSVToSampleLoader
from
bob.extension
import
rc
import
bob.io.base
from
bob.bio.face.database.sample_loaders
import
EyesAnnotationsLoader
# TODO: POINT TO THE `.bob/meds``
dataset_protocol_path
=
"/idiap/user/tpereira/gitlab/bob/bob.nightlies/meds"
class
MEDSDatabase
(
CSVDatasetDevEval
):
def
__init__
(
self
,
protocol
,
dataset_protocol_path
=
dataset_protocol_path
,
csv_to_sample_loader
=
CSVToSampleLoader
(
data_loader
=
bob
.
io
.
base
.
load
,
metadata_loader
=
EyesAnnotationsLoader
(),
dataset_original_directory
=
rc
[
"bob.db.meds.directory"
],
extension
=
".jpg"
,
),
):
# TODO: IMPLEMENT THE DOWNLOAD MECHANISM
super
().
__init__
(
dataset_protocol_path
,
protocol
,
csv_to_sample_loader
)
bob/bio/face/database/sample_loaders.py
View file @
bd592d5a
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
""" Sample loader"""
""" Sample
and Metatada
loader"""
from
bob.bio.base.database
import
CSVToSampleLoader
from
bob.pipelines
import
Sample
,
DelayedSample
,
SampleSet
import
functools
import
os
class
CSVToSampleLoaderEyesAnnotations
(
CSVToSampleLoader
):
class
EyesAnnotationsLoader
:
"""
Convert CSV files in the format below to either a list of
:any:`bob.pipelines.DelayedSample` or :any:`bob.pipelines.SampleSet`
Convert leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
"""
def
convert_row_to_sample
(
self
,
row
,
header
):
path
=
row
[
0
]
subject
=
row
[
1
]
kwargs
=
dict
([[
h
,
r
]
for
h
,
r
in
zip
(
header
[
2
:],
row
[
2
:])])
annotations
=
{
"leye"
:
(
kwargs
[
"leye_x"
],
kwargs
[
"leye_y"
]),
"reye"
:
(
kwargs
[
"reye_x"
],
kwargs
[
"reye_y"
]),
def
__call__
(
self
,
row
,
header
=
None
):
def
find_attribute
(
attribute
):
for
i
,
a
in
enumerate
(
header
):
if
a
==
attribute
:
return
i
else
:
ValueError
(
f"Attribute not found in the dataset:
{
a
}
"
)
eyes
=
{
"leye"
:
(
row
[
find_attribute
(
"leye_x"
)],
row
[
find_attribute
(
"leye_y"
)]),
"reye"
:
(
row
[
find_attribute
(
"reye_x"
)],
row
[
find_attribute
(
"reye_y"
)]),
}
kwargs
.
pop
(
"leye_x"
)
kwargs
.
pop
(
"leye_y"
)
kwargs
.
pop
(
"reye_x"
)
kwargs
.
pop
(
"reye_y"
)
return
DelayedSample
(
functools
.
partial
(
self
.
data_loader
,
os
.
path
.
join
(
self
.
dataset_original_directory
,
path
+
self
.
extension
),
),
key
=
path
,
subject
=
subject
,
annotations
=
annotations
,
**
kwargs
,
)
"""
class CSVToSampleLoaderEyesAnnotations(CSVToSampleLoader):
def __call__(self, filename):
import ipdb
ipdb.set_trace()
samples = super(CSVToSampleLoaderEyesAnnotations, self).__call__(filename)
def generate_annotations(sample):
Convert leye_x, leye_y, reye_x, reye_y attributes to
`annotations = (leye, reye)`
check_keys = [
a in (sample.__dict__.keys())
for a in ["leye_x", "leye_y", "reye_x", "reye_y"]
]
if not check_keys:
raise ValueError(
"Sample needs to contain the following annotations: 'leye_x', 'leye_y', 'reye_x', 'reye_y'"
)
annotations = {
"leye": (sample.leye_x, sample.leye_y),
"reye": (sample.reye_x, sample.reye_y),
}
# Changing the state of samples for efficiency
# We might have a gigantic amount of datasets
sample.__dict__.pop("leye_x")
sample.__dict__.pop("leye_y")
sample.__dict__.pop("reye_x")
sample.__dict__.pop("reye_y")
sample.annotations = annotations
for sample in samples:
generate_annotations(sample)
annotation
=
{
"annotations"
:
eyes
}
return samples
"""
return
annotation
bob/bio/face/test/test_databases.py
View file @
bd592d5a
This diff is collapsed.
Click to expand it.
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