|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {2d-printed_masks_attacks}, |
|
author = {TrainingDataPro}, |
|
year = {2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The dataset consists of 40,000 videos and selfies with unique people. 15,000 |
|
attack replays from 4,000 unique devices. 10,000 attacks with A4 printouts and |
|
10,000 attacks with cut-out printouts. |
|
""" |
|
_NAME = '2d-printed_masks_attacks' |
|
|
|
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}" |
|
|
|
_LICENSE = "cc-by-nc-nd-4.0" |
|
|
|
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/" |
|
|
|
|
|
class PrintedMasksAttacks(datasets.GeneratorBasedBuilder): |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo(description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
'2d_mask': datasets.Value('string'), |
|
'live_selfie': datasets.Image(), |
|
'live_video': datasets.Value('string'), |
|
'phone_model': datasets.Value('string') |
|
}), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
license=_LICENSE) |
|
|
|
def _split_generators(self, dl_manager): |
|
masks = dl_manager.download(f"{_DATA}attack.tar.gz") |
|
live_selfies = dl_manager.download(f"{_DATA}live_selfie.tar.gz") |
|
live_videos = dl_manager.download(f"{_DATA}live_video.tar.gz") |
|
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv") |
|
masks = dl_manager.iter_archive(masks) |
|
live_selfies = dl_manager.iter_archive(live_selfies) |
|
live_videos = dl_manager.iter_archive(live_videos) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
'attacks': masks, |
|
"live_selfies": live_selfies, |
|
'live_videos': live_videos, |
|
'annotations': annotations |
|
}), |
|
] |
|
|
|
def _generate_examples(self, masks, live_selfies, live_videos, |
|
annotations): |
|
for idx, ((mask_path, mask), (live_selfie_path, live_selfie), |
|
(live_video_path, live_video)) in enumerate( |
|
zip(masks, live_selfies, live_videos)): |
|
annotations_df = pd.read_csv(annotations) |
|
yield idx, { |
|
'2d_mask': |
|
mask_path, |
|
'live_selfie': { |
|
'path': live_selfie_path, |
|
'bytes': live_selfie.read() |
|
}, |
|
'live_video': |
|
live_video_path, |
|
'phone_model': |
|
annotations_df.loc[ |
|
annotations_df['live_selfie'] == live_selfie_path] |
|
['phone_model'].values[0] |
|
} |
|
|