File size: 3,196 Bytes
03c14aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e7d083
03c14aa
 
 
 
 
 
 
 
 
9e7d083
03c14aa
 
 
 
 
 
 
 
 
 
 
9e7d083
03c14aa
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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}2d_masks.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={
                                        'masks': 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, sep=';')
            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]
            }