import datasets import pandas as pd _CITATION = """\ @InProceedings{huggingface:dataset, title = {anti-spoofing_replay}, author = {TrainingDataPro}, year = {2023} } """ _DESCRIPTION = """\ The dataset consists of 40,000 videos and selfies with unique people. 15,000 attack replays from 4,000 unique devices. 10,000 attacks with A4 printouts and 10,000 attacks with cut-out printouts. """ _NAME = 'anti-spoofing_replay' _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 AntiSpoofingReplay(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features({ 'live_video_id': datasets.Value('string'), 'phone': datasets.Value('string'), 'video_file': datasets.Value('string'), 'phone_video_playback': datasets.Value('string'), 'worker_id': 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, (video_path, video) in enumerate(videos): file_name = '/'.join(video_path.split('/')[-2:]) yield idx, { 'live_video_id': annotations_df.loc[annotations_df['link'] == file_name] ['live_video_id'].values[0], 'phone': annotations_df.loc[annotations_df['link'] == file_name] ['phone'].values[0], 'video_file': video_path, 'phone_video_playback': annotations_df.loc[annotations_df['link'] == file_name] ['phone_video_playback'].values[0], 'worker_id': annotations_df.loc[annotations_df['link'] == file_name] ['worker_id'].values[0] }