|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {2d-masks-presentation-attack-detection}, |
|
author = {TrainingDataPro}, |
|
year = {2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The dataset consists of videos of individuals wearing printed 2D masks or |
|
printed 2D masks with cut-out eyes and directly looking at the camera. |
|
Videos are filmed in different lightning conditions and in different places |
|
(indoors, outdoors). Each video in the dataset has an approximate duration of 2 |
|
seconds. |
|
""" |
|
_NAME = '2d-masks-presentation-attack-detection' |
|
|
|
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}" |
|
|
|
_LICENSE = "" |
|
|
|
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/" |
|
|
|
|
|
class MasksPresentationAttackDetection(datasets.GeneratorBasedBuilder): |
|
"""Small sample of image-text pairs""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
'user': datasets.Value('string'), |
|
'real_1': datasets.Value('string'), |
|
'real_2': datasets.Value('string'), |
|
'real_3': datasets.Value('string'), |
|
'real_4': datasets.Value('string'), |
|
'mask_1': datasets.Value('string'), |
|
'mask_2': datasets.Value('string'), |
|
'mask_3': datasets.Value('string'), |
|
'mask_4': datasets.Value('string'), |
|
'cut_1': datasets.Value('string'), |
|
'cut_2': datasets.Value('string'), |
|
'cut_3': datasets.Value('string'), |
|
'cut_4': datasets.Value('string') |
|
}), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
files = dl_manager.download(f"{_DATA}files.tar.gz") |
|
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv") |
|
files = dl_manager.iter_archive(files) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"files": files, |
|
'annotations': annotations |
|
}), |
|
] |
|
|
|
def _generate_examples(self, files, annotations): |
|
annotations_df = pd.read_csv(annotations, sep=';') |
|
|
|
for idx, (file_path, file) in enumerate(files): |
|
if 'real_1' in file_path.lower(): |
|
user = file_path.split('/')[-2] |
|
yield idx, { |
|
'user': |
|
user, |
|
'real_1': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['real_1'].values[0], |
|
'real_2': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['real_2'].values[0], |
|
'real_3': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['real_3'].values[0], |
|
'real_4': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['real_4'].values[0], |
|
'mask_1': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['mask_1'].values[0], |
|
'mask_2': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['mask_2'].values[0], |
|
'mask_3': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['mask_3'].values[0], |
|
'mask_4': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['mask_4'].values[0], |
|
'cut_1': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['cut_1'].values[0], |
|
'cut_2': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['cut_2'].values[0], |
|
'cut_3': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['cut_3'].values[0], |
|
'cut_4': |
|
annotations_df.loc[annotations_df['user'] == user] |
|
['cut_4'].values[0], |
|
} |
|
|