Skip to content
Snippets Groups Projects

Batl loo protocols

Merged Anjith GEORGE requested to merge batl_LOO_protocols into master
Files
3
@@ -202,6 +202,14 @@ class BatlPadDatabase(PadDatabase):
infrared data only, use 50 frames, join train and dev sets forming
a single large training set.
"grandtest-infrared-50-LOO_<unseen_attack>", for example "grandtest-infrared-50-LOO_fakehead"
- Leave One Out (LOO) protocol with fakehead attacks present only in the `test` set. The original partitioning
in the `grandtest` protocol is queried first and subselects the file list such
that the specified `unknown_attack` is removed from both `train` and `dev` sets.
The `test` set will consist of only the selected `unknown_attack` and `bonafide` files.
This protocol is used to evaluate the robustness against attacks unseen in training.
.
"grandtest-color*infrared-50" - baseline protocol,
load both "color" and "infrared" channels,
use 50 frames.
@@ -286,6 +294,15 @@ class BatlPadDatabase(PadDatabase):
self.append_color_face_roi_annot = append_color_face_roi_annot
#map file to identify attack grouping
map_file = pkg_resources.resource_filename('bob.pad.face', 'lists/batl/idiap_converter_v2.json')
with open(map_file, 'r') as fp:
map_dict=json.load(fp)
self.map_dict=map_dict
@property
def original_directory(self):
return self.db.original_directory
@@ -295,6 +312,52 @@ class BatlPadDatabase(PadDatabase):
def original_directory(self, value):
self.db.original_directory = value
def unseen_attack_list_maker(self,files,unknown_attack,train=True):
"""
Selects and returns a list of files for Leave One Out (LOO) protocols.
This utilizes the original partitioning in the `grandtest` protocol and subselects
the file list such that the specified `unknown_attack` is removed from both `train` and `dev` sets.
The `test` set will consist of only the selected `unknown_attack` and `bonafide` files.
**Parameters:**
``files`` : pyclass::list
A list of files, db.objects()
``unknown_attack`` : str
The unknown attack protocol name example:'rigidmask' .
``train`` : bool
Denotes whether files are from training or development partition
**Returns:**
``mod_files`` : pyclass::list
A list of files selected for the protocol
"""
mod_files=[]
for file in files:
attack_category=self.map_dict["_"+"_".join(os.path.split(file.path)[-1].split("_")[-2:])].split("_")[-1]
if train:
if attack_category==unknown_attack:
pass
else:
mod_files.append(file) # everything except the attack specified is there
if not train:
if attack_category==unknown_attack or attack_category=='bonafide':
mod_files.append(file) # only the attack mentioned and bonafides in testing
else:
pass
return mod_files
def parse_protocol(self, protocol):
"""
@@ -329,7 +392,7 @@ class BatlPadDatabase(PadDatabase):
forming a single training set.
"""
possible_extras = ['join_train_dev']
possible_extras = ['join_train_dev','LOO_fakehead','LOO_flexiblemask','LOO_glasses','LOO_papermask','LOO_prints','LOO_replay','LOO_rigidmask','LOO_makeup']
components = protocol.split("-")
@@ -490,10 +553,11 @@ class BatlPadDatabase(PadDatabase):
protocol = 'nowig' if protocol == 'grandtest' else protocol
# Convert group names to low-level group names here.
groups = self.convert_names_to_lowlevel(
groups, self.low_level_group_names, self.high_level_group_names)
groups = self.convert_names_to_lowlevel(groups, self.low_level_group_names, self.high_level_group_names)
if not isinstance(groups, list) and groups is not None: # if a single group is given make it a list
if not isinstance(groups, list) and groups is not None and not isinstance(groups,str): # if a single group is given make it a list
groups = list(groups)
if extra is not None and "join_train_dev" in extra:
@@ -515,6 +579,48 @@ class BatlPadDatabase(PadDatabase):
groups=['test'],
purposes=purposes, **kwargs)
# for the LOO protocols
elif extra is not None and "LOO_" in extra:
batl_files=[]
unknown_attack=extra.split("_")[-1]
if 'train' in groups:
tbatl_files = self.db.objects(protocol=protocol,
groups=['train'],
purposes=purposes, **kwargs)
tbatl_files=self.unseen_attack_list_maker(tbatl_files,unknown_attack,train=True)
batl_files=batl_files+tbatl_files
if 'validation' in groups:
tbatl_files = self.db.objects(protocol=protocol,
groups=['validation'],
purposes=purposes, **kwargs)
tbatl_files=self.unseen_attack_list_maker(tbatl_files,unknown_attack,train=True)
batl_files=batl_files+tbatl_files
if 'test' in groups:
tbatl_files = self.db.objects(protocol=protocol,
groups=['test'],
purposes=purposes, **kwargs)
tbatl_files=self.unseen_attack_list_maker(tbatl_files,unknown_attack,train=False)
batl_files=batl_files+tbatl_files
files=batl_files
else:
# files = self._fix_funny_eyes_in_objects(protocol=protocol,
# groups=groups,
Loading