Delete selfies_and_id.py
#1
by
rikco
- opened
- selfies_and_id.py +0 -118
selfies_and_id.py
DELETED
@@ -1,118 +0,0 @@
|
|
1 |
-
import io
|
2 |
-
|
3 |
-
import datasets
|
4 |
-
import pandas as pd
|
5 |
-
|
6 |
-
_CITATION = """\
|
7 |
-
@InProceedings{huggingface:dataset,
|
8 |
-
title = {selfies_and_id},
|
9 |
-
author = {TrainingDataPro},
|
10 |
-
year = {2023}
|
11 |
-
}
|
12 |
-
"""
|
13 |
-
|
14 |
-
_DESCRIPTION = """\
|
15 |
-
4083 sets, which includes 2 photos of a person from his documents and
|
16 |
-
13 selfies. 571 sets of Hispanics and 3512 sets of Caucasians.
|
17 |
-
Photo documents contains only a photo of a person.
|
18 |
-
All personal information from the document is hidden.
|
19 |
-
"""
|
20 |
-
_NAME = 'selfies_and_id'
|
21 |
-
|
22 |
-
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
23 |
-
|
24 |
-
_LICENSE = ""
|
25 |
-
|
26 |
-
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
|
27 |
-
|
28 |
-
|
29 |
-
class SelfiesAndId(datasets.GeneratorBasedBuilder):
|
30 |
-
"""Small sample of image-text pairs"""
|
31 |
-
|
32 |
-
def _info(self):
|
33 |
-
return datasets.DatasetInfo(
|
34 |
-
description=_DESCRIPTION,
|
35 |
-
features=datasets.Features({
|
36 |
-
'id_1': datasets.Image(),
|
37 |
-
'id_2': datasets.Image(),
|
38 |
-
'selfie_1': datasets.Image(),
|
39 |
-
'selfie_2': datasets.Image(),
|
40 |
-
'selfie_3': datasets.Image(),
|
41 |
-
'selfie_4': datasets.Image(),
|
42 |
-
'selfie_5': datasets.Image(),
|
43 |
-
'selfie_6': datasets.Image(),
|
44 |
-
'selfie_7': datasets.Image(),
|
45 |
-
'selfie_8': datasets.Image(),
|
46 |
-
'selfie_9': datasets.Image(),
|
47 |
-
'selfie_10': datasets.Image(),
|
48 |
-
'selfie_11': datasets.Image(),
|
49 |
-
'selfie_12': datasets.Image(),
|
50 |
-
'selfie_13': datasets.Image(),
|
51 |
-
'user_id': datasets.Value('string'),
|
52 |
-
'set_id': datasets.Value('string'),
|
53 |
-
'user_race': datasets.Value('string'),
|
54 |
-
'name': datasets.Value('string'),
|
55 |
-
'age': datasets.Value('int8'),
|
56 |
-
'country': datasets.Value('string'),
|
57 |
-
'gender': datasets.Value('string')
|
58 |
-
}),
|
59 |
-
supervised_keys=None,
|
60 |
-
homepage=_HOMEPAGE,
|
61 |
-
citation=_CITATION,
|
62 |
-
)
|
63 |
-
|
64 |
-
def _split_generators(self, dl_manager):
|
65 |
-
images = dl_manager.download(f"{_DATA}images.tar.gz")
|
66 |
-
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
67 |
-
images = dl_manager.iter_archive(images)
|
68 |
-
return [
|
69 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
70 |
-
gen_kwargs={
|
71 |
-
"images": images,
|
72 |
-
'annotations': annotations
|
73 |
-
}),
|
74 |
-
]
|
75 |
-
|
76 |
-
def _generate_examples(self, images, annotations):
|
77 |
-
annotations_df = pd.read_csv(annotations, sep=';')
|
78 |
-
images_data = pd.DataFrame(columns=['URL', 'Bytes'])
|
79 |
-
for idx, (image_path, image) in enumerate(images):
|
80 |
-
images_data.loc[idx] = {'URL': image_path, 'Bytes': image.read()}
|
81 |
-
|
82 |
-
annotations_df = pd.merge(annotations_df,
|
83 |
-
images_data,
|
84 |
-
how='left',
|
85 |
-
on=['URL'])
|
86 |
-
for idx, worker_id in enumerate(pd.unique(annotations_df['UserId'])):
|
87 |
-
annotation = annotations_df.loc[annotations_df['UserId'] ==
|
88 |
-
worker_id]
|
89 |
-
annotation = annotation.sort_values(['FName'])
|
90 |
-
data = {
|
91 |
-
row[5].lower(): {
|
92 |
-
'path': row[6],
|
93 |
-
'bytes': row[10]
|
94 |
-
} for row in annotation.itertuples()
|
95 |
-
}
|
96 |
-
|
97 |
-
age = annotation.loc[annotation['FName'] ==
|
98 |
-
'ID_1']['Age'].values[0]
|
99 |
-
country = annotation.loc[annotation['FName'] ==
|
100 |
-
'ID_1']['Country'].values[0]
|
101 |
-
gender = annotation.loc[annotation['FName'] ==
|
102 |
-
'ID_1']['Gender'].values[0]
|
103 |
-
set_id = annotation.loc[annotation['FName'] ==
|
104 |
-
'ID_1']['SetId'].values[0]
|
105 |
-
user_race = annotation.loc[annotation['FName'] ==
|
106 |
-
'ID_1']['UserRace'].values[0]
|
107 |
-
name = annotation.loc[annotation['FName'] ==
|
108 |
-
'ID_1']['Name'].values[0]
|
109 |
-
|
110 |
-
data['user_id'] = worker_id
|
111 |
-
data['age'] = age
|
112 |
-
data['country'] = country
|
113 |
-
data['gender'] = gender
|
114 |
-
data['set_id'] = set_id
|
115 |
-
data['user_race'] = user_race
|
116 |
-
data['name'] = name
|
117 |
-
|
118 |
-
yield idx, data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|