feat: script
Browse files
facial-emotion-recognition-dataset.py
CHANGED
@@ -9,32 +9,24 @@ import PIL.ImageOps
|
|
9 |
|
10 |
_CITATION = """\
|
11 |
@InProceedings{huggingface:dataset,
|
12 |
-
title = {
|
13 |
author = {TrainingDataPro},
|
14 |
year = {2023}
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
-
The dataset consists of
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
lighting and angles that showcase their body proportions accurately.
|
29 |
-
|
30 |
-
The dataset serves various purposes, including:
|
31 |
-
- research projects
|
32 |
-
- body measurement analysis
|
33 |
-
- fashion or apparel industry applications
|
34 |
-
- fitness and wellness studies
|
35 |
-
- anthropometric studies for ergonomic design in various fields
|
36 |
"""
|
37 |
-
_NAME = '
|
38 |
|
39 |
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
40 |
|
@@ -43,141 +35,73 @@ _LICENSE = "cc-by-nc-nd-4.0"
|
|
43 |
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
|
44 |
|
45 |
|
46 |
-
class
|
47 |
|
48 |
def _info(self):
|
49 |
-
return datasets.DatasetInfo(
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
"pelvis_circumference_cm": datasets.Value('string'),
|
69 |
-
"shoulder_length_cm": datasets.Value('string'),
|
70 |
-
"shoulder_width_cm": datasets.Value('string'),
|
71 |
-
"thigh_circumference_cm": datasets.Value('string'),
|
72 |
-
"under_chest_circumference_cm": datasets.Value('string'),
|
73 |
-
"upper_arm_length_cm": datasets.Value('string'),
|
74 |
-
"waist_circumference_cm": datasets.Value('string'),
|
75 |
-
"height": datasets.Value('string'),
|
76 |
-
"weight": datasets.Value('string'),
|
77 |
-
"age": datasets.Value('string'),
|
78 |
-
"gender": datasets.Value('string'),
|
79 |
-
"race": datasets.Value('string'),
|
80 |
-
"profession": datasets.Value('string'),
|
81 |
-
"arm_circumference": datasets.Image(),
|
82 |
-
"arm_length": datasets.Image(),
|
83 |
-
"back_build": datasets.Image(),
|
84 |
-
"calf_circumference": datasets.Image(),
|
85 |
-
"chest_circumference": datasets.Image(),
|
86 |
-
"crotch_height": datasets.Image(),
|
87 |
-
"front_build": datasets.Image(),
|
88 |
-
"hips_circumference": datasets.Image(),
|
89 |
-
"leg_length": datasets.Image(),
|
90 |
-
"neck_circumference": datasets.Image(),
|
91 |
-
"neck_pelvis_length_front": datasets.Image(),
|
92 |
-
"neck_waist_length_back": datasets.Image(),
|
93 |
-
"neck_waist_length_front": datasets.Image(),
|
94 |
-
"pelvis_circumference": datasets.Image(),
|
95 |
-
"shoulder_length": datasets.Image(),
|
96 |
-
"shoulder_width": datasets.Image(),
|
97 |
-
"thigh_circumference": datasets.Image(),
|
98 |
-
"under_chest_circumference": datasets.Image(),
|
99 |
-
"upper_arm_length": datasets.Image(),
|
100 |
-
"waist_circumference": datasets.Image()
|
101 |
-
}),
|
102 |
-
supervised_keys=None,
|
103 |
-
homepage=_HOMEPAGE,
|
104 |
-
citation=_CITATION,
|
105 |
-
license=_LICENSE)
|
106 |
|
107 |
def _split_generators(self, dl_manager):
|
108 |
-
|
109 |
-
proofs = dl_manager.download_and_extract(f"{_DATA}proofs.zip")
|
110 |
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
111 |
-
|
112 |
-
proofs = dl_manager.iter_files(proofs)
|
113 |
return [
|
114 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
115 |
gen_kwargs={
|
116 |
-
"
|
117 |
-
'proofs': proofs,
|
118 |
'annotations': annotations
|
119 |
}),
|
120 |
]
|
121 |
|
122 |
-
def _generate_examples(self,
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
data = {}
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
data['
|
144 |
-
elif '
|
145 |
-
data['
|
146 |
-
elif '
|
147 |
-
data['
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
data['chest_circumference'] = proof
|
156 |
-
elif 'crotch_height' in proof:
|
157 |
-
data['crotch_height'] = proof
|
158 |
-
elif 'front_build' in proof:
|
159 |
-
data['front_build'] = proof
|
160 |
-
elif 'hips_circumference' in proof:
|
161 |
-
data['hips_circumference'] = proof
|
162 |
-
elif 'leg_length' in proof:
|
163 |
-
data['leg_length'] = proof
|
164 |
-
elif 'neck_circumference' in proof:
|
165 |
-
data['neck_circumference'] = proof
|
166 |
-
elif 'neck_pelvis_length_front' in proof:
|
167 |
-
data['neck_pelvis_length_front'] = proof
|
168 |
-
elif 'neck_waist_length_back' in proof:
|
169 |
-
data['neck_waist_length_back'] = proof
|
170 |
-
elif 'neck_waist_length_front' in proof:
|
171 |
-
data['neck_waist_length_front'] = proof
|
172 |
-
elif 'pelvis_circumference' in proof:
|
173 |
-
data['pelvis_circumference'] = proof
|
174 |
-
elif 'shoulder_length' in proof:
|
175 |
-
data['shoulder_length'] = proof
|
176 |
-
elif 'shoulder_width' in proof:
|
177 |
-
data['shoulder_width'] = proof
|
178 |
-
elif 'thigh_circumference' in proof:
|
179 |
-
data['thigh_circumference'] = proof
|
180 |
-
elif 'waist_circumference' in proof:
|
181 |
-
data['waist_circumference'] = proof
|
182 |
|
183 |
yield idx, data
|
|
|
9 |
|
10 |
_CITATION = """\
|
11 |
@InProceedings{huggingface:dataset,
|
12 |
+
title = {facial-emotion-recognition-dataset},
|
13 |
author = {TrainingDataPro},
|
14 |
year = {2023}
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
+
The dataset consists of images capturing people displaying 7 distinct emotions
|
20 |
+
(anger, contempt, disgust, fear, happiness, sadness and surprise).
|
21 |
+
Each image in the dataset represents one of these specific emotions,
|
22 |
+
enabling researchers and machine learning practitioners to study and develop
|
23 |
+
models for emotion recognition and analysis.
|
24 |
+
The images encompass a diverse range of individuals, including different
|
25 |
+
genders, ethnicities, and age groups*. The dataset aims to provide
|
26 |
+
a comprehensive representation of human emotions, allowing for a wide range of
|
27 |
+
use cases.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
"""
|
29 |
+
_NAME = 'facial-emotion-recognition-dataset'
|
30 |
|
31 |
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
32 |
|
|
|
35 |
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
|
36 |
|
37 |
|
38 |
+
class FacialEmotionRecognitionDataset(datasets.GeneratorBasedBuilder):
|
39 |
|
40 |
def _info(self):
|
41 |
+
return datasets.DatasetInfo(description=_DESCRIPTION,
|
42 |
+
features=datasets.Features({
|
43 |
+
'set_id': datasets.Value('int32'),
|
44 |
+
'neutral': datasets.Image(),
|
45 |
+
'anger': datasets.Image(),
|
46 |
+
'contempt': datasets.Image(),
|
47 |
+
'disgust': datasets.Image(),
|
48 |
+
"fear": datasets.Image(),
|
49 |
+
"happy": datasets.Image(),
|
50 |
+
"sad": datasets.Image(),
|
51 |
+
"surprised": datasets.Image(),
|
52 |
+
"age": datasets.Value('int8'),
|
53 |
+
"gender": datasets.Value('string'),
|
54 |
+
"country": datasets.Value('string')
|
55 |
+
}),
|
56 |
+
supervised_keys=None,
|
57 |
+
homepage=_HOMEPAGE,
|
58 |
+
citation=_CITATION,
|
59 |
+
license=_LICENSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
def _split_generators(self, dl_manager):
|
62 |
+
images = dl_manager.download_and_extract(f"{_DATA}images.zip")
|
|
|
63 |
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
64 |
+
images = dl_manager.iter_files(images)
|
|
|
65 |
return [
|
66 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
67 |
gen_kwargs={
|
68 |
+
"images": images,
|
|
|
69 |
'annotations': annotations
|
70 |
}),
|
71 |
]
|
72 |
|
73 |
+
def _generate_examples(self, images, annotations):
|
74 |
+
annotations_df = pd.read_csv(annotations, sep=';')
|
75 |
+
images = list(images)
|
76 |
+
images = [sorted(images)[i:i + 8] for i in range(0, len(images), 8)]
|
77 |
+
|
78 |
+
for idx, images_set in enumerate(images):
|
79 |
+
set_id = images_set.split('/')[-2]
|
80 |
+
data = {'set_id': set_id}
|
81 |
+
|
82 |
+
for file in images_set:
|
83 |
+
if 'neutral' in file.lower():
|
84 |
+
data['neutral'] = file
|
85 |
+
elif 'anger' in file.lower():
|
86 |
+
data['anger'] = file
|
87 |
+
elif 'contempt' in file.lower():
|
88 |
+
data['contempt'] = file
|
89 |
+
elif 'disgust' in file.lower():
|
90 |
+
data['disgust'] = file
|
91 |
+
elif 'fear' in file.lower():
|
92 |
+
data['fear'] = file
|
93 |
+
elif 'happy' in file.lower():
|
94 |
+
data['happy'] = file
|
95 |
+
elif 'sad' in file.lower():
|
96 |
+
data['sad'] = file
|
97 |
+
elif 'surprised' in file.lower():
|
98 |
+
data['surprised'] = file
|
99 |
+
|
100 |
+
data['age'] = annotations_df.loc[annotations_df['set_id'] ==
|
101 |
+
set_id]['age'].values[0]
|
102 |
+
data['gender'] = annotations_df.loc[annotations_df['set_id'] ==
|
103 |
+
set_id]['gender'].values[0]
|
104 |
+
data['country'] = annotations_df.loc[annotations_df['set_id'] ==
|
105 |
+
set_id]['country'].values[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
yield idx, data
|