selfie-and-video-on-back-camera / selfie-and-video-on-back-camera.py
vkashko's picture
feat: script
08205d5
import datasets
import pandas as pd
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {selfie-and-video-on-back-camera},
author = {TrainingDataPro},
year = {2023}
}
"""
_DESCRIPTION = """\
The dataset consists of selfies and video of real people made on a back camera
of the smartphone. The dataset solves tasks in the field of anti-spoofing and
it is useful for buisness and safety systems.
"""
_NAME = 'selfie-and-video-on-back-camera'
_HOMEPAGE = f"https://huggingface.co./datasets/TrainingDataPro/{_NAME}"
_LICENSE = ""
_DATA = f"https://huggingface.co./datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
class SelfieAndVideoOnBackCamera(datasets.GeneratorBasedBuilder):
"""Small sample of image-text pairs"""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
'photo': datasets.Image(),
'video': datasets.Value('string'),
'phone': datasets.Value('string'),
'gender': datasets.Value('string'),
'age': datasets.Value('int8'),
'country': datasets.Value('string'),
}),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
images = dl_manager.download(f"{_DATA}photo.tar.gz")
videos = dl_manager.download(f"{_DATA}video.tar.gz")
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
images = dl_manager.iter_archive(images)
videos = dl_manager.iter_archive(videos)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN,
gen_kwargs={
"images": images,
'videos': videos,
'annotations': annotations
}),
]
def _generate_examples(self, images, videos, annotations):
annotations_df = pd.read_csv(annotations, sep=';')
for idx, ((image_path, image),
(video_path, video)) in enumerate(zip(images, videos)):
yield idx, {
"photo": {
"path": image_path,
"bytes": image.read()
},
"video":
video_path,
'phone':
annotations_df.loc[annotations_df['photo'].str.startswith(
str(idx))]['phone'].values[0],
'gender':
annotations_df.loc[annotations_df['photo'].str.startswith(
str(idx))]['gender'].values[0],
'age':
annotations_df.loc[annotations_df['photo'].str.startswith(
str(idx))]['age'].values[0],
'country':
annotations_df.loc[annotations_df['photo'].str.startswith(
str(idx))]['country'].values[0],
}