vkashko commited on
Commit
fbfc88b
1 Parent(s): 85a1b8d

feat: script

Browse files
Files changed (1) hide show
  1. facial-emotion-recognition-dataset.py +67 -143
facial-emotion-recognition-dataset.py CHANGED
@@ -9,32 +9,24 @@ import PIL.ImageOps
9
 
10
  _CITATION = """\
11
  @InProceedings{huggingface:dataset,
12
- title = {body-measurements-dataset},
13
  author = {TrainingDataPro},
14
  year = {2023}
15
  }
16
  """
17
 
18
  _DESCRIPTION = """\
19
- The dataset consists of a compilation of people's photos along with their
20
- corresponding body measurements. It is designed to provide information and
21
- insights into the physical appearances and body characteristics of individuals.
22
- The dataset includes a diverse range of subjects representing different age
23
- groups, genders, and ethnicities.
24
-
25
- The photos are captured in a standardized manner, depicting individuals in a
26
- front and side positions.
27
- The images aim to capture the subjects' physical appearance using appropriate
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 = 'body-measurements-dataset'
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 BodyMeasurementsDataset(datasets.GeneratorBasedBuilder):
47
 
48
  def _info(self):
49
- return datasets.DatasetInfo(
50
- description=_DESCRIPTION,
51
- features=datasets.Features({
52
- 'front_img': datasets.Image(),
53
- 'selfie_img': datasets.Image(),
54
- 'side_img': datasets.Image(),
55
- "arm_circumference_cm": datasets.Value('string'),
56
- "arm_length_cm": datasets.Value('string'),
57
- "back_build_cm": datasets.Value('string'),
58
- "calf_circumference_cm": datasets.Value('string'),
59
- "chest_circumference_cm": datasets.Value('string'),
60
- "crotch_height_cm": datasets.Value('string'),
61
- "front_build_cm": datasets.Value('string'),
62
- "hips_circumference_cm": datasets.Value('string'),
63
- "leg_length_cm": datasets.Value('string'),
64
- "neck_circumference_cm": datasets.Value('string'),
65
- "neck_pelvis_length_front_cm": datasets.Value('string'),
66
- "neck_waist_length_back_cm": datasets.Value('string'),
67
- "neck_waist_length_front_cm": datasets.Value('string'),
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
- files = dl_manager.download_and_extract(f"{_DATA}files.zip")
109
- proofs = dl_manager.download_and_extract(f"{_DATA}proofs.zip")
110
  annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
111
- files = dl_manager.iter_files(files)
112
- proofs = dl_manager.iter_files(proofs)
113
  return [
114
  datasets.SplitGenerator(name=datasets.Split.TRAIN,
115
  gen_kwargs={
116
- "files": files,
117
- 'proofs': proofs,
118
  'annotations': annotations
119
  }),
120
  ]
121
 
122
- def _generate_examples(self, files, proofs, annotations):
123
- files = list(files)
124
- files = [files[i:i + 4] for i in range(0, len(files), 4)]
125
- proofs = list(proofs)
126
- proofs = [proofs[i:i + 20] for i in range(0, len(proofs), 20)]
127
-
128
- for idx, (files_dir, proofs_dir) in enumerate(zip(files, proofs)):
129
- data = {}
130
- for file in files_dir:
131
- if 'front_img' in file:
132
- data['front_img'] = file
133
- elif 'selfie_img' in file:
134
- data['selfie_img'] = file
135
- elif 'side_img' in file:
136
- data['side_img'] = file
137
- elif 'measurements' in file:
138
- with open(file) as f:
139
- data.update(json.load(f))
140
-
141
- for proof in proofs_dir:
142
- if "arm_circumference" in proof:
143
- data['arm_circumference'] = proof
144
- elif 'upper_arm_length' in proof:
145
- data['upper_arm_length'] = proof
146
- elif 'arm_length' in proof:
147
- data['arm_length'] = proof
148
- elif 'back_build' in proof:
149
- data['back_build'] = proof
150
- elif 'calf_circumference' in proof:
151
- data['calf_circumference'] = proof
152
- elif 'under_chest_circumference' in proof:
153
- data['under_chest_circumference'] = proof
154
- elif 'chest_circumference' in proof:
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