Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.face
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.face
Commits
a8a26357
Commit
a8a26357
authored
4 years ago
by
Tiago de Freitas Pereira
Browse files
Options
Downloads
Patches
Plain Diff
[py][db] Created a sample loader able to process eyes annotations
parent
0b34b777
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!81
Sample Loaders able to handle certain type of annotations...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/face/database/sample_loaders.py
+91
-0
91 additions, 0 deletions
bob/bio/face/database/sample_loaders.py
with
91 additions
and
0 deletions
bob/bio/face/database/sample_loaders.py
0 → 100644
+
91
−
0
View file @
a8a26357
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""
Sample loader
"""
from
bob.bio.base.database
import
CSVToSampleLoader
from
bob.pipelines
import
Sample
,
DelayedSample
,
SampleSet
import
functools
import
os
class
CSVToSampleLoaderEyesAnnotations
(
CSVToSampleLoader
):
"""
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
"
]),
}
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)
return samples
"""
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