vkashko commited on
Commit
aef0d61
1 Parent(s): 8c1a20c

feat: script refactor: csv

Browse files
.gitattributes CHANGED
@@ -77,3 +77,4 @@ attacks/6.MOV filter=lfs diff=lfs merge=lfs -text
77
  attacks/7.MOV filter=lfs diff=lfs merge=lfs -text
78
  attacks/8.MOV filter=lfs diff=lfs merge=lfs -text
79
  attacks/9.MOV filter=lfs diff=lfs merge=lfs -text
 
 
77
  attacks/7.MOV filter=lfs diff=lfs merge=lfs -text
78
  attacks/8.MOV filter=lfs diff=lfs merge=lfs -text
79
  attacks/9.MOV filter=lfs diff=lfs merge=lfs -text
80
+ data filter=lfs diff=lfs merge=lfs -text
MacBook-Attacks-Dataset.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pandas as pd
3
+
4
+ _CITATION = """\
5
+ @InProceedings{huggingface:dataset,
6
+ title = {MacBook-Attacks-Dataset},
7
+ author = {TrainingDataPro},
8
+ year = {2023}
9
+ }
10
+ """
11
+
12
+ _DESCRIPTION = """\
13
+ The dataset consists of 40,000 videos and selfies with unique people. 15,000
14
+ attack replays from 4,000 unique devices. 10,000 attacks with A4 printouts and
15
+ 10,000 attacks with cut-out printouts.
16
+ """
17
+ _NAME = 'MacBook-Attacks-Dataset'
18
+
19
+ _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
20
+
21
+ _LICENSE = "cc-by-nc-nd-4.0"
22
+
23
+ _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
24
+
25
+
26
+ class MacBookAttacksDataset(datasets.GeneratorBasedBuilder):
27
+
28
+ def _info(self):
29
+ return datasets.DatasetInfo(description=_DESCRIPTION,
30
+ features=datasets.Features({
31
+ 'file': datasets.Value('string'),
32
+ 'phone': datasets.Value('string'),
33
+ 'computer': datasets.Value('string'),
34
+ 'gender': datasets.Value('string'),
35
+ 'age': datasets.Value('int16'),
36
+ 'country': datasets.Value('string'),
37
+ }),
38
+ supervised_keys=None,
39
+ homepage=_HOMEPAGE,
40
+ citation=_CITATION,
41
+ license=_LICENSE)
42
+
43
+ def _split_generators(self, dl_manager):
44
+ attacks = dl_manager.download(f"{_DATA}attacks.tar.gz")
45
+ annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
46
+ attacks = dl_manager.iter_archive(attacks)
47
+ return [
48
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
49
+ gen_kwargs={
50
+ "attacks": attacks,
51
+ 'annotations': annotations
52
+ }),
53
+ ]
54
+
55
+ def _generate_examples(self, attacks, annotations):
56
+ annotations_df = pd.read_csv(annotations, sep=';')
57
+ for idx, (video_path, video) in enumerate(attacks):
58
+ file_name = '/'.join(video_path.split('/')[-2:])
59
+
60
+ yield idx, {
61
+ 'file':
62
+ file_name,
63
+ 'phone':
64
+ annotations_df.loc[
65
+ annotations_df['file'].str.lower() == file_name]
66
+ ['phone'].values[0],
67
+ 'computer':
68
+ annotations_df.loc[
69
+ annotations_df['file'].str.lower() == file_name]
70
+ ['computer'].values[0],
71
+ 'gender':
72
+ annotations_df.loc[
73
+ annotations_df['file'].str.lower() == file_name]
74
+ ['gender'].values[0],
75
+ 'age':
76
+ annotations_df.loc[
77
+ annotations_df['file'].str.lower() == file_name]
78
+ ['age'].values[0],
79
+ 'country':
80
+ annotations_df.loc[
81
+ annotations_df['file'].str.lower() == file_name]
82
+ ['country'].values[0]
83
+ }
mac_attacks.csv → data/MacBook-Attacks-Dataset.csv RENAMED
File without changes