File size: 3,215 Bytes
15ca8b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import datasets
import pandas as pd

_CITATION = """\
@InProceedings{huggingface:dataset,
title = {low_quality_webcam_video_attacks},
author = {TrainingDataPro},
year = {2023}
}
"""

_DESCRIPTION = """\
The dataset includes live-recorded Anti-Spoofing videos from around the world,
captured via low-quality webcams with resolutions like QVGA, QQVGA and QCIF.
"""
_NAME = 'low_quality_webcam_video_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 LowQualityWebcamVideoAttacks(datasets.GeneratorBasedBuilder):

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                'video_file': datasets.Value('string'),
                'assignment_id': datasets.Value('string'),
                'worker_id': datasets.Value('string'),
                'gender': datasets.Value('string'),
                'age': datasets.Value('uint8'),
                'country': datasets.Value('string'),
                'resolution': datasets.Value('string')
            }),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE)

    def _split_generators(self, dl_manager):
        videos = dl_manager.download(f"{_DATA}videos.tar.gz")
        annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
        videos = dl_manager.iter_archive(videos)
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN,
                                    gen_kwargs={
                                        "videos": videos,
                                        'annotations': annotations
                                    }),
        ]

    def _generate_examples(self, videos, annotations):
        annotations_df = pd.read_csv(annotations, sep=';')
        for idx, (image_path, video) in enumerate(videos):
            file_name = image_path.split('/')[-1]
            assignment_id = file_name.split('.')[0]

            yield idx, {
                "video_file":
                    file_name,
                'assignment_id':
                    assignment_id,
                'worker_id':
                    annotations_df.loc[
                        annotations_df['assignment_id'] == assignment_id]
                    ['worker_id'].values[0],
                'gender':
                    annotations_df.loc[
                        annotations_df['assignment_id'] == assignment_id]
                    ['gender'].values[0],
                'age':
                    annotations_df.loc[
                        annotations_df['assignment_id'] == assignment_id]
                    ['age'].values[0],
                'country':
                    annotations_df.loc[
                        annotations_df['assignment_id'] == assignment_id]
                    ['country'].values[0],
                'resolution':
                    annotations_df.loc[
                        annotations_df['assignment_id'] == assignment_id]
                    ['resolution'].values[0]
            }