feat: script
Browse files
cut-2d-masks-presentation-attack-detection.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
_CITATION = """\
|
5 |
+
@InProceedings{huggingface:dataset,
|
6 |
+
title = {2d-masks-presentation-attack-detection},
|
7 |
+
author = {TrainingDataPro},
|
8 |
+
year = {2023}
|
9 |
+
}
|
10 |
+
"""
|
11 |
+
|
12 |
+
_DESCRIPTION = """\
|
13 |
+
The dataset consists of videos of individuals wearing printed 2D masks or
|
14 |
+
printed 2D masks with cut-out eyes and directly looking at the camera.
|
15 |
+
Videos are filmed in different lightning conditions and in different places
|
16 |
+
(indoors, outdoors). Each video in the dataset has an approximate duration of 2
|
17 |
+
seconds.
|
18 |
+
"""
|
19 |
+
_NAME = '2d-masks-presentation-attack-detection'
|
20 |
+
|
21 |
+
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
22 |
+
|
23 |
+
_LICENSE = ""
|
24 |
+
|
25 |
+
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
|
26 |
+
|
27 |
+
|
28 |
+
class MasksPresentationAttackDetection(datasets.GeneratorBasedBuilder):
|
29 |
+
"""Small sample of image-text pairs"""
|
30 |
+
|
31 |
+
def _info(self):
|
32 |
+
return datasets.DatasetInfo(
|
33 |
+
description=_DESCRIPTION,
|
34 |
+
features=datasets.Features({
|
35 |
+
'user': datasets.Value('string'),
|
36 |
+
'real_1': datasets.Value('string'),
|
37 |
+
'real_2': datasets.Value('string'),
|
38 |
+
'real_3': datasets.Value('string'),
|
39 |
+
'real_4': datasets.Value('string'),
|
40 |
+
'mask_1': datasets.Value('string'),
|
41 |
+
'mask_2': datasets.Value('string'),
|
42 |
+
'mask_3': datasets.Value('string'),
|
43 |
+
'mask_4': datasets.Value('string'),
|
44 |
+
'cut_1': datasets.Value('string'),
|
45 |
+
'cut_2': datasets.Value('string'),
|
46 |
+
'cut_3': datasets.Value('string'),
|
47 |
+
'cut_4': datasets.Value('string')
|
48 |
+
}),
|
49 |
+
supervised_keys=None,
|
50 |
+
homepage=_HOMEPAGE,
|
51 |
+
citation=_CITATION,
|
52 |
+
)
|
53 |
+
|
54 |
+
def _split_generators(self, dl_manager):
|
55 |
+
files = dl_manager.download(f"{_DATA}files.tar.gz")
|
56 |
+
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
57 |
+
files = dl_manager.iter_archive(files)
|
58 |
+
return [
|
59 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
60 |
+
gen_kwargs={
|
61 |
+
"files": files,
|
62 |
+
'annotations': annotations
|
63 |
+
}),
|
64 |
+
]
|
65 |
+
|
66 |
+
def _generate_examples(self, files, annotations):
|
67 |
+
annotations_df = pd.read_csv(annotations, sep=';')
|
68 |
+
|
69 |
+
for idx, (file_path, file) in enumerate(files):
|
70 |
+
if 'real_1' in file_path.lower():
|
71 |
+
user = file_path.split('/')[-2]
|
72 |
+
yield idx, {
|
73 |
+
'user':
|
74 |
+
user,
|
75 |
+
'real_1':
|
76 |
+
annotations_df.loc[annotations_df['user'] == user]
|
77 |
+
['real_1'].values[0],
|
78 |
+
'real_2':
|
79 |
+
annotations_df.loc[annotations_df['user'] == user]
|
80 |
+
['real_2'].values[0],
|
81 |
+
'real_3':
|
82 |
+
annotations_df.loc[annotations_df['user'] == user]
|
83 |
+
['real_3'].values[0],
|
84 |
+
'real_4':
|
85 |
+
annotations_df.loc[annotations_df['user'] == user]
|
86 |
+
['real_4'].values[0],
|
87 |
+
'mask_1':
|
88 |
+
annotations_df.loc[annotations_df['user'] == user]
|
89 |
+
['mask_1'].values[0],
|
90 |
+
'mask_2':
|
91 |
+
annotations_df.loc[annotations_df['user'] == user]
|
92 |
+
['mask_2'].values[0],
|
93 |
+
'mask_3':
|
94 |
+
annotations_df.loc[annotations_df['user'] == user]
|
95 |
+
['mask_3'].values[0],
|
96 |
+
'mask_4':
|
97 |
+
annotations_df.loc[annotations_df['user'] == user]
|
98 |
+
['mask_4'].values[0],
|
99 |
+
'cut_1':
|
100 |
+
annotations_df.loc[annotations_df['user'] == user]
|
101 |
+
['cut_1'].values[0],
|
102 |
+
'cut_2':
|
103 |
+
annotations_df.loc[annotations_df['user'] == user]
|
104 |
+
['cut_2'].values[0],
|
105 |
+
'cut_3':
|
106 |
+
annotations_df.loc[annotations_df['user'] == user]
|
107 |
+
['cut_3'].values[0],
|
108 |
+
'cut_4':
|
109 |
+
annotations_df.loc[annotations_df['user'] == user]
|
110 |
+
['cut_4'].values[0],
|
111 |
+
}
|