Commit a096a142 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Fix imports

parent d9870e3f
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bob.bio.video import FrameSelector
from bob.extension import rc
from bob.io.video import reader
from bob.pad.base.database import PadDatabase
......@@ -126,28 +125,6 @@ class CasiaFasdPadFile(VideoPadFile):
annotations[str(i)].update(expected_eye_positions(bounding_box))
return annotations
def load(self, directory=None, extension='.avi',
frame_selector=FrameSelector(selection_style='all')):
"""Loads the video file and returns in a
:any:`bob.bio.video.FrameContainer`.
Parameters
----------
directory : :obj:`str`, optional
The directory to load the data from.
extension : :obj:`str`, optional
The extension of the file to load.
frame_selector : :any:`bob.bio.video.FrameSelector`, optional
Which frames to select.
Returns
-------
:any:`bob.bio.video.FrameContainer`
The loaded frames inside a frame container.
"""
directory = directory or self.original_directory
return frame_selector(self.make_path(directory, extension))
class CasiaFasdPadDatabase(PadDatabase):
"""
......
......@@ -5,8 +5,7 @@
import os
import numpy as np
import bob.io.video
from bob.bio.video import FrameSelector, FrameContainer
from bob.pad.face.database import VideoPadFile
from bob.pad.face.database import VideoPadFile
from bob.pad.base.database import PadDatabase
from bob.extension import rc
......@@ -23,7 +22,7 @@ class CasiaSurfPadFile(VideoPadFile):
f : :py:class:`object`
An instance of the Sample class defined in the low level db interface
of the CASIA-SURF database, in the bob.db.casiasurf.models.py file.
"""
def __init__(self, s, stream_type):
......@@ -52,33 +51,33 @@ class CasiaSurfPadFile(VideoPadFile):
file_id=s.id,
attack_type=attack_type,
path=s.id)
def load(self, directory=rc['bob.db.casiasurf.directory'], extension='.jpg', frame_selector=FrameSelector(selection_style='all')):
def load(self, directory=rc['bob.db.casiasurf.directory'], extension='.jpg'):
"""Overloaded version of the load method defined in ``VideoPadFile``.
Parameters
----------
directory : :py:class:`str`
String containing the path to the CASIA-SURF database
String containing the path to the CASIA-SURF database
extension : :py:class:`str`
Extension of the image files
Extension of the image files
frame_selector : :py:class:`bob.bio.video.FrameSelector`
The frame selector to use.
Returns
-------
dict:
image data for multiple streams stored in the dictionary.
image data for multiple streams stored in the dictionary.
The structure of the dictionary: ``data={"stream1_name" : numpy array, "stream2_name" : numpy array}``
Names of the streams are defined in ``self.stream_type``.
"""
return self.s.load(directory, extension, modality=self.stream_type)
class CasiaSurfPadDatabase(PadDatabase):
class CasiaSurfPadDatabase(PadDatabase):
"""High level implementation of the Database class for the 3DMAD database.
Note that at the moment, this database only contains a training and validation set.
The protocol specifies the modality(ies) to load.
......@@ -93,7 +92,7 @@ class CasiaSurfPadDatabase(PadDatabase):
the group names in the high-level interface (train, dev, eval)
"""
def __init__(self, protocol='all', original_directory=rc['bob.db.casiasurf.directory'], original_extension='.jpg', **kwargs):
"""Init function
......@@ -105,13 +104,13 @@ class CasiaSurfPadDatabase(PadDatabase):
The directory where the original data of the database are stored.
original_extension : :py:class:`str`
The file name extension of the original data.
"""
from bob.db.casiasurf import Database as LowLevelDatabase
self.db = LowLevelDatabase()
self.low_level_group_names = ('train', 'validation', 'test')
self.low_level_group_names = ('train', 'validation', 'test')
self.high_level_group_names = ('train', 'dev', 'eval')
super(CasiaSurfPadDatabase, self).__init__(
......@@ -160,31 +159,31 @@ class CasiaSurfPadDatabase(PadDatabase):
groups = self.convert_names_to_lowlevel(groups, self.low_level_group_names, self.high_level_group_names)
if groups is not None:
# for training
lowlevel_purposes = []
if 'train' in groups and 'real' in purposes:
lowlevel_purposes.append('real')
lowlevel_purposes.append('real')
if 'train' in groups and 'attack' in purposes:
lowlevel_purposes.append('attack')
lowlevel_purposes.append('attack')
# for dev
if 'validation' in groups and 'real' in purposes:
lowlevel_purposes.append('real')
lowlevel_purposes.append('real')
if 'validation' in groups and 'attack' in purposes:
lowlevel_purposes.append('attack')
lowlevel_purposes.append('attack')
# for eval
if 'test' in groups and 'real' in purposes:
lowlevel_purposes.append('real')
lowlevel_purposes.append('real')
if 'test' in groups and 'attack' in purposes:
lowlevel_purposes.append('attack')
lowlevel_purposes.append('attack')
samples = self.db.objects(groups=groups, purposes=lowlevel_purposes, **kwargs)
samples = [CasiaSurfPadFile(s, stream_type=protocol) for s in samples]
return samples
def annotations(self, file):
"""No annotations are provided with this DB
"""
......
......@@ -25,8 +25,7 @@ class CELEBAPadFile(PadFile):
super(CELEBAPadFile, self).__init__(client_id, path, attack_type, file_id)
# ==========================================================================
def load(self, directory=None, extension=None,
frame_selector=bob.bio.video.FrameSelector(selection_style='all')):
def load(self):
"""
Overridden version of the load method defined in the ``PadFile``.
......@@ -104,4 +103,4 @@ class CELEBAPadDatabase(FileListPadDatabase):
annotations = {} # dictionary to return
return annotations
\ No newline at end of file
return annotations
......@@ -20,6 +20,9 @@ class VideoPadFile(PadFile):
annotation_directory=None,
annotation_extension=None,
annotation_type=None,
selection_style=None,
max_number_of_frames=None,
step_size=None,
):
super().__init__(
attack_type=attack_type,
......@@ -32,10 +35,12 @@ class VideoPadFile(PadFile):
annotation_extension=annotation_extension,
annotation_type=annotation_type,
)
self.selection_style = selection_style or "all"
self.max_number_of_frames = max_number_of_frames
self.step_size = step_size
def load(
self,
frame_selector=bob.bio.video.FrameSelector(selection_style="all"),
):
"""Loads the video file and returns in a `bob.bio.video.FrameContainer`.
......@@ -49,9 +54,7 @@ class VideoPadFile(PadFile):
:any:`bob.bio.video.FrameContainer`
The loaded frames inside a frame container.
"""
path = self.make_path(
self.original_directory, self.original_extension
)
path = self.make_path(self.original_directory, self.original_extension)
video = bob.bio.video.VideoAsArray(
path,
selection_style=frame_selector.selection_style,
......
......@@ -4,7 +4,6 @@
import os
import numpy as np
import bob.io.video
from bob.bio.video import FrameSelector, FrameContainer
from bob.pad.face.database import VideoPadFile
from bob.pad.base.database import PadDatabase
......@@ -42,30 +41,6 @@ class MaskAttackPadFile(VideoPadFile):
attack_type=attack_type,
file_id=f.id)
def load(self, directory=None, extension='.avi', frame_selector=FrameSelector(selection_style='all')):
"""Overridden version of the load method defined in ``VideoPadFile``.
Parameters
----------
directory : :py:class:`str`
String containing the path to the 3DMAD database
(generated sequences from original data).
extension : :py:class:`str`
Extension of the video files
frame_selector : :py:class:`bob.bio.video.FrameSelector`
The frame selector to use.
Returns
-------
video_data : :py:class:`bob.bio.video.utils.FrameContainer`
video data stored in a FrameContainer
"""
vfilename = self.make_path(directory, extension)
video = bob.io.video.reader(vfilename)
video_data_array = video.load()
return frame_selector(video_data_array)
class MaskAttackPadDatabase(PadDatabase):
"""High level implementation of the Database class for the 3DMAD database.
......
......@@ -6,7 +6,6 @@
#==============================================================================
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector, FrameContainer
import bob.io.base
import numpy as np
......@@ -27,7 +26,7 @@ class MIFSPadFile(VideoPadFile):
file_id)
#==========================================================================
def load(self, directory=None, extension=None, frame_selector=FrameSelector(selection_style='all')):
def load():
"""
Overridden version of the load method defined in the ``VideoPadFile``.
......
......@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Used in ReplayMobilePadFile class
from bob.bio.video import FrameSelector
from bob.pad.base.database import PadDatabase
from bob.pad.face.database import VideoPadFile
from bob.pad.face.utils import number_of_frames
......@@ -51,8 +50,7 @@ class ReplayMobilePadFile(VideoPadFile):
attack_type=attack_type,
file_id=f.id)
def load(self, directory=None, extension='.mov',
frame_selector=FrameSelector(selection_style='all')):
def load(self):
"""
Overridden version of the load method defined in the ``VideoPadFile``.
......
from ..utils import extract_patches
from bob.bio.base.preprocessor import Preprocessor
from bob.bio.video import FrameContainer
from bob.bio.video.preprocessor import Wrapper
from bob.bio.video.transformer import VideoWrapper
from collections import OrderedDict
......@@ -32,7 +31,7 @@ class ImagePatches(Preprocessor):
return fc
class VideoPatches(Wrapper):
class VideoPatches(VideoWrapper):
"""Extracts patches of images from video containers and returns it in a
FrameContainer.
"""
......
from bob.bio.base.test.utils import atnt_database_directory
from bob.bio.video.utils import FrameContainer
import bob.io.base
import os
from bob.pad.face.database import VideoPadFile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment