Vadzim Kashko commited on
Commit
08205d5
1 Parent(s): 1d32a0b

feat: script

Browse files
Files changed (1) hide show
  1. selfie-and-video-on-back-camera.py +84 -0
selfie-and-video-on-back-camera.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import pandas as pd
3
+
4
+ _CITATION = """\
5
+ @InProceedings{huggingface:dataset,
6
+ title = {selfie-and-video-on-back-camera},
7
+ author = {TrainingDataPro},
8
+ year = {2023}
9
+ }
10
+ """
11
+
12
+ _DESCRIPTION = """\
13
+ The dataset consists of selfies and video of real people made on a back camera
14
+ of the smartphone. The dataset solves tasks in the field of anti-spoofing and
15
+ it is useful for buisness and safety systems.
16
+ """
17
+ _NAME = 'selfie-and-video-on-back-camera'
18
+
19
+ _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
20
+
21
+ _LICENSE = ""
22
+
23
+ _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
24
+
25
+
26
+ class SelfieAndVideoOnBackCamera(datasets.GeneratorBasedBuilder):
27
+ """Small sample of image-text pairs"""
28
+
29
+ def _info(self):
30
+ return datasets.DatasetInfo(
31
+ description=_DESCRIPTION,
32
+ features=datasets.Features({
33
+ 'photo': datasets.Image(),
34
+ 'video': datasets.Value('string'),
35
+ 'phone': datasets.Value('string'),
36
+ 'gender': datasets.Value('string'),
37
+ 'age': datasets.Value('int8'),
38
+ 'country': datasets.Value('string'),
39
+ }),
40
+ supervised_keys=None,
41
+ homepage=_HOMEPAGE,
42
+ citation=_CITATION,
43
+ )
44
+
45
+ def _split_generators(self, dl_manager):
46
+ images = dl_manager.download(f"{_DATA}photo.tar.gz")
47
+ videos = dl_manager.download(f"{_DATA}video.tar.gz")
48
+ annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
49
+ images = dl_manager.iter_archive(images)
50
+ videos = dl_manager.iter_archive(videos)
51
+ return [
52
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
53
+ gen_kwargs={
54
+ "images": images,
55
+ 'videos': videos,
56
+ 'annotations': annotations
57
+ }),
58
+ ]
59
+
60
+ def _generate_examples(self, images, videos, annotations):
61
+ annotations_df = pd.read_csv(annotations, sep=';')
62
+
63
+ for idx, ((image_path, image),
64
+ (video_path, video)) in enumerate(zip(images, videos)):
65
+ yield idx, {
66
+ "photo": {
67
+ "path": image_path,
68
+ "bytes": image.read()
69
+ },
70
+ "video":
71
+ video_path,
72
+ 'phone':
73
+ annotations_df.loc[annotations_df['photo'].str.startswith(
74
+ str(idx))]['phone'].values[0],
75
+ 'gender':
76
+ annotations_df.loc[annotations_df['photo'].str.startswith(
77
+ str(idx))]['gender'].values[0],
78
+ 'age':
79
+ annotations_df.loc[annotations_df['photo'].str.startswith(
80
+ str(idx))]['age'].values[0],
81
+ 'country':
82
+ annotations_df.loc[annotations_df['photo'].str.startswith(
83
+ str(idx))]['country'].values[0],
84
+ }