fix: update script
Browse files
2d-masks-presentation-attack-detection.py
CHANGED
@@ -3,20 +3,20 @@ import pandas as pd
|
|
3 |
|
4 |
_CITATION = """\
|
5 |
@InProceedings{huggingface:dataset,
|
6 |
-
title = {
|
7 |
author = {TrainingDataPro},
|
8 |
year = {2023}
|
9 |
}
|
10 |
"""
|
11 |
|
12 |
_DESCRIPTION = """\
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
-
_NAME = '
|
20 |
|
21 |
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
22 |
|
@@ -25,26 +25,26 @@ _LICENSE = ""
|
|
25 |
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
|
26 |
|
27 |
|
28 |
-
class
|
29 |
"""Small sample of image-text pairs"""
|
30 |
|
31 |
def _info(self):
|
32 |
return datasets.DatasetInfo(
|
33 |
description=_DESCRIPTION,
|
34 |
features=datasets.Features({
|
35 |
-
'
|
36 |
-
'
|
37 |
-
'
|
38 |
-
'
|
39 |
-
'
|
40 |
-
'
|
41 |
-
'
|
42 |
-
'
|
43 |
-
'
|
44 |
-
'
|
45 |
-
'
|
46 |
-
'
|
47 |
-
'
|
48 |
}),
|
49 |
supervised_keys=None,
|
50 |
homepage=_HOMEPAGE,
|
@@ -52,58 +52,60 @@ class SelfieAndVideo(datasets.GeneratorBasedBuilder):
|
|
52 |
)
|
53 |
|
54 |
def _split_generators(self, dl_manager):
|
55 |
-
|
56 |
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
57 |
-
|
58 |
return [
|
59 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
60 |
gen_kwargs={
|
61 |
-
"
|
62 |
'annotations': annotations
|
63 |
}),
|
64 |
]
|
65 |
|
66 |
-
def _generate_examples(self,
|
67 |
annotations_df = pd.read_csv(annotations, sep=';')
|
68 |
-
images_data = pd.DataFrame(columns=['Link', 'Bytes'])
|
69 |
-
for idx, (image_path, image) in enumerate(images):
|
70 |
-
if image_path.lower().endswith('.jpg'):
|
71 |
-
images_data.loc[idx] = {
|
72 |
-
'Link': image_path,
|
73 |
-
'Bytes': image.read()
|
74 |
-
}
|
75 |
-
|
76 |
-
annotations_df = pd.merge(annotations_df,
|
77 |
-
images_data,
|
78 |
-
on=['Link'],
|
79 |
-
how='left')
|
80 |
-
|
81 |
-
for idx, worker_id in enumerate(pd.unique(annotations_df['WorkerId'])):
|
82 |
-
annotation = annotations_df.loc[annotations_df['WorkerId'] ==
|
83 |
-
worker_id]
|
84 |
-
annotation = annotation.sort_values(['Link'])
|
85 |
-
data = {
|
86 |
-
(f'photo_{row[7][37]}' if row[7].lower().endswith('.jpg') else f'video_{row[7][37]}'):
|
87 |
-
({
|
88 |
-
'path': row[7],
|
89 |
-
'bytes': row[8]
|
90 |
-
} if row[7].lower().endswith('.jpg') else row[7])
|
91 |
-
for row in annotation.itertuples()
|
92 |
-
}
|
93 |
-
|
94 |
-
age = annotation.loc[annotation['Link'].str.lower().str.endswith(
|
95 |
-
'1.jpg')]['Age'].values[0]
|
96 |
-
country = annotation.loc[annotation['Link'].str.lower().str.
|
97 |
-
endswith('1.jpg')]['Country'].values[0]
|
98 |
-
gender = annotation.loc[annotation['Link'].str.lower().str.
|
99 |
-
endswith('1.jpg')]['Gender'].values[0]
|
100 |
-
set_id = annotation.loc[annotation['Link'].str.lower().str.
|
101 |
-
endswith('1.jpg')]['SetId'].values[0]
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
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,
|
|
|
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 |
+
}
|