File size: 4,488 Bytes
63b863f
 
 
 
 
b01d8a9
63b863f
 
 
 
 
 
b01d8a9
 
 
 
 
63b863f
b01d8a9
63b863f
 
 
 
 
 
 
 
b01d8a9
63b863f
 
 
 
 
 
b01d8a9
 
 
 
 
 
 
 
 
 
 
 
 
63b863f
 
 
 
 
 
 
b01d8a9
63b863f
b01d8a9
63b863f
 
 
b01d8a9
63b863f
 
 
 
b01d8a9
63b863f
 
b01d8a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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],
                }