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
211cf0bd
Commit
211cf0bd
authored
4 years ago
by
Yannick DAYER
Browse files
Options
Downloads
Patches
Plain Diff
Simplify CSV files by making multiple frames a row
parent
c7ad23c5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!106
Vulnerability framework - CSV datasets
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/bio/face/database/replaymobile_csv.py
+17
-19
17 additions, 19 deletions
bob/bio/face/database/replaymobile_csv.py
with
17 additions
and
19 deletions
bob/bio/face/database/replaymobile_csv.py
+
17
−
19
View file @
211cf0bd
...
@@ -5,11 +5,12 @@ from bob.bio.base.database import CSVDataset, CSVToSampleLoaderBiometrics
...
@@ -5,11 +5,12 @@ from bob.bio.base.database import CSVDataset, CSVToSampleLoaderBiometrics
from
bob.pipelines.datasets.sample_loaders
import
AnnotationsLoader
from
bob.pipelines.datasets.sample_loaders
import
AnnotationsLoader
from
bob.pipelines.sample
import
DelayedSample
from
bob.pipelines.sample
import
DelayedSample
from
bob.extension.download
import
get_file
from
bob.extension.download
import
get_file
from
sklearn.pipeline
import
make_pipeline
from
bob.io.video
import
reader
from
bob.io.video
import
reader
from
bob.extension
import
rc
from
bob.extension
import
rc
import
bob.core
import
bob.core
from
sklearn.base
import
TransformerMixin
,
BaseEstimator
from
sklearn.pipeline
import
make_pipeline
import
functools
import
functools
import
os.path
import
os.path
import
numpy
import
numpy
...
@@ -19,31 +20,26 @@ logger = bob.core.log.setup("bob.bio.face")
...
@@ -19,31 +20,26 @@ logger = bob.core.log.setup("bob.bio.face")
def
load_frame_from_file_replaymobile
(
file_name
,
frame
,
capturing_device
):
def
load_frame_from_file_replaymobile
(
file_name
,
frame
,
capturing_device
):
"""
Loads a single frame from a video file for replay-mobile.
"""
Loads a single frame from a video file for replay-mobile.
A particularity of the replay-mobile is the use of different devices for
This function uses bob
'
s video reader utility that does not load the full
capturing the videos (
'
mobile
'
and
'
tablet
'
). The orientation of the
resulting videos differs for each device and is encoded in the metadata,
but bob.io.video ignores it. This function correctly rotates the returned
image, given the captured device
'
s name.
This function uses the video reader utility that does not load the full
video in memory to just access one frame.
video in memory to just access one frame.
Parameters
Parameters
----------
----------
file_name: str
file_name: str
The video file to load the frame from
The video file to load the frame
s
from
frame: int
frame:
None or list of
int
The
frame index
to load.
The
index of the frame
to load.
capturing device: str
capturing device: str
'
mobile
'
devices
'
frames will be flipped vertically.
'
mobile
'
devices
'
frames will be flipped vertically.
Other devices
'
frames will not be flipped.
Returns
Returns
-------
-------
image: 3D numpy array
image
s
: 3D numpy array
The frame of the video in bob format (channel, height, width)
The frame of the video in bob format (channel, height, width)
"""
"""
logger
.
debug
(
f
"
Extracting frame
{
frame
}
from
'
{
file_name
}
'"
)
logger
.
debug
(
f
"
Extracting frame
{
frame
}
from
'
{
file_name
}
'"
)
...
@@ -95,7 +91,7 @@ def read_frame_annotation_file_replaymobile(file_name, frame):
...
@@ -95,7 +91,7 @@ def read_frame_annotation_file_replaymobile(file_name, frame):
positions
=
line
.
split
(
'
'
)
positions
=
line
.
split
(
'
'
)
if
len
(
positions
)
!=
4
:
if
len
(
positions
)
!=
4
:
raise
ValueError
(
f
"
The content of
'
{
file_name
}
'
was not correct for frame
{
frame
}
"
)
raise
ValueError
(
f
"
The content of
'
{
file_name
}
'
was not correct for frame
{
frame
}
(
{
positions
}
)
"
)
annotations
=
{
annotations
=
{
'
topleft
'
:
(
float
(
positions
[
1
]),
float
(
positions
[
0
])),
'
topleft
'
:
(
float
(
positions
[
1
]),
float
(
positions
[
0
])),
...
@@ -127,7 +123,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
...
@@ -127,7 +123,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
self
.
reference_id_equal_subject_id
=
reference_id_equal_subject_id
self
.
reference_id_equal_subject_id
=
reference_id_equal_subject_id
def
convert_row_to_sample
(
self
,
row
,
header
):
def
convert_row_to_sample
(
self
,
row
,
header
):
"""
Creates
one
sample given a row of the CSV protocol definition
file
.
"""
Creates
a set of
sample
s
given a row of the CSV protocol definition.
"""
"""
path
=
row
[
0
]
path
=
row
[
0
]
reference_id
=
row
[
1
]
reference_id
=
row
[
1
]
...
@@ -139,19 +135,21 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
...
@@ -139,19 +135,21 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
else
:
else
:
if
"
subject_id
"
not
in
kwargs
:
if
"
subject_id
"
not
in
kwargs
:
raise
ValueError
(
f
"
`subject_id` not available in
{
header
}
"
)
raise
ValueError
(
f
"
`subject_id` not available in
{
header
}
"
)
# One row leads to multiple samples (different frames)
return
DelayedSample
(
all_samples
=
[
DelayedSample
(
functools
.
partial
(
functools
.
partial
(
load_frame_from_file_replaymobile
,
load_frame_from_file_replaymobile
,
file_name
=
os
.
path
.
join
(
self
.
dataset_original_directory
,
path
+
self
.
extension
),
file_name
=
os
.
path
.
join
(
self
.
dataset_original_directory
,
path
+
self
.
extension
),
frame
=
int
(
kwargs
[
"
frame
"
])
,
frame
=
frame
,
capturing_device
=
kwargs
[
"
capturing_device
"
],
capturing_device
=
kwargs
[
"
capturing_device
"
],
),
),
key
=
id
,
key
=
f
"
{
id
}
_
{
frame
}
"
,
path
=
path
,
path
=
path
,
reference_id
=
reference_id
,
reference_id
=
reference_id
,
frame
=
frame
,
**
kwargs
,
**
kwargs
,
)
)
for
frame
in
range
(
12
,
251
,
24
)]
return
all_samples
class
FrameBoundingBoxAnnotationLoader
(
AnnotationsLoader
):
class
FrameBoundingBoxAnnotationLoader
(
AnnotationsLoader
):
...
...
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