Skip to content
Snippets Groups Projects
Commit 9a08b32a authored by Yannick DAYER's avatar Yannick DAYER
Browse files

One frame is one sample

parent f1d3573d
No related branches found
No related tags found
1 merge request!106Vulnerability framework - CSV datasets
...@@ -8,14 +8,14 @@ from bob.db.base.annotations import read_annotation_file ...@@ -8,14 +8,14 @@ from bob.db.base.annotations import read_annotation_file
from bob.extension.download import get_file from bob.extension.download import get_file
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
from sklearn.pipeline import make_pipeline from sklearn.pipeline import make_pipeline
import functools import functools
import os.path import os.path
import logging
import numpy import numpy
logger = bob.core.log.setup("bob.bio.face") logger = logging.getLogger(__name__)
def load_frame_from_file_replaymobile(file_name, frame, should_flip): def load_frame_from_file_replaymobile(file_name, frame, should_flip):
"""Loads a single frame from a video file for replay-mobile. """Loads a single frame from a video file for replay-mobile.
...@@ -42,7 +42,7 @@ def load_frame_from_file_replaymobile(file_name, frame, should_flip): ...@@ -42,7 +42,7 @@ def load_frame_from_file_replaymobile(file_name, frame, should_flip):
images: 3D numpy array images: 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"Reading frame {frame} from '{file_name}'")
video_reader = reader(file_name) video_reader = reader(file_name)
image = video_reader[frame] image = video_reader[frame]
# Image captured by the 'mobile' device are flipped vertically. # Image captured by the 'mobile' device are flipped vertically.
...@@ -58,7 +58,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics): ...@@ -58,7 +58,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
"""A loader transformer returning a specific frame of a video file. """A loader transformer returning a specific frame of a video file.
This is specifically tailored for replay-mobile. It uses a specific loader This is specifically tailored for replay-mobile. It uses a specific loader
that takes the capturing device as input. that processes the `should_flip` metadata to correctly orient the frames.
""" """
def __init__( def __init__(
self, self,
...@@ -75,7 +75,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics): ...@@ -75,7 +75,7 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
self.references_list = [] self.references_list = []
def convert_row_to_sample(self, row, header): def convert_row_to_sample(self, row, header):
"""Creates a set of samples given a row of the CSV protocol definition. """Creates a sample given a row of the CSV protocol definition.
""" """
fields = dict([[str(h).lower(), r] for h, r in zip(header, row)]) fields = dict([[str(h).lower(), r] for h, r in zip(header, row)])
...@@ -102,18 +102,16 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics): ...@@ -102,18 +102,16 @@ class ReplayMobileCSVFrameSampleLoader(CSVToSampleLoaderBiometrics):
else: else:
kwargs["references"] = self.references_list kwargs["references"] = self.references_list
# One row leads to multiple samples (different frames) # One row leads to multiple samples (different frames)
all_samples = [DelayedSample( return DelayedSample(
functools.partial( functools.partial(
load_frame_from_file_replaymobile, load_frame_from_file_replaymobile,
file_name=os.path.join(self.dataset_original_directory, fields["path"] + self.extension), file_name=os.path.join(self.dataset_original_directory, fields["path"] + self.extension),
frame=frame, frame=int(fields["frame"]),
should_flip=fields["should_flip"]=="TRUE", should_flip=fields["should_flip"]=="TRUE",
), ),
key=f"{fields['id']}_{frame}", key=fields['id'],
frame=frame,
**kwargs, **kwargs,
) for frame in range(12,251,24)] )
return all_samples
def read_frame_annotation_file_replaymobile(file_name, frame, annotations_type="json"): def read_frame_annotation_file_replaymobile(file_name, frame, annotations_type="json"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment