feat: script
Browse files- body-measurements-dataset.py +183 -0
body-measurements-dataset.py
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
import PIL.Image
|
8 |
+
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 |
+
|
41 |
+
_LICENSE = "cc-by-nc-nd-4.0"
|
42 |
+
|
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 |
+
annotations_df = pd.read_csv(annotations, sep=';')
|
124 |
+
files = list(files)
|
125 |
+
files = [files[i:i + 4] for i in range(0, len(files), 4)]
|
126 |
+
proofs = list(proofs)
|
127 |
+
proofs = [proofs[i:i + 20] for i in range(0, len(proofs), 20)]
|
128 |
+
|
129 |
+
for idx, (files_dir, proofs_dir) in enumerate(zip(files, proofs)):
|
130 |
+
data = {}
|
131 |
+
for file in files_dir:
|
132 |
+
if 'front_img' in file:
|
133 |
+
data['front_img'] = file
|
134 |
+
elif 'selfie_img' in file:
|
135 |
+
data['selfie_img'] = file
|
136 |
+
elif 'side_img' in file:
|
137 |
+
data['side_img'] = file
|
138 |
+
elif 'measurements' in file:
|
139 |
+
data.update(json.load(file))
|
140 |
+
|
141 |
+
for proof in proofs_dir:
|
142 |
+
if "arm_circumference" in proof:
|
143 |
+
data['arm_circumference'] = proof
|
144 |
+
elif 'arm_length' in proof:
|
145 |
+
data['arm_length'] = proof
|
146 |
+
elif 'back_build' in proof:
|
147 |
+
data['back_build'] = proof
|
148 |
+
elif 'calf_circumference' in proof:
|
149 |
+
data['calf_circumference'] = proof
|
150 |
+
elif 'chest_circumference' in proof:
|
151 |
+
data['chest_circumference'] = proof
|
152 |
+
elif 'crotch_height' in proof:
|
153 |
+
data['crotch_height'] = proof
|
154 |
+
elif 'front_build' in proof:
|
155 |
+
data['front_build'] = proof
|
156 |
+
elif 'hips_circumference' in proof:
|
157 |
+
data['hips_circumference'] = proof
|
158 |
+
elif 'leg_length' in proof:
|
159 |
+
data['leg_length'] = proof
|
160 |
+
elif 'neck_circumference' in proof:
|
161 |
+
data['neck_circumference'] = proof
|
162 |
+
elif 'neck_pelvis_length_front' in proof:
|
163 |
+
data['neck_pelvis_length_front'] = proof
|
164 |
+
elif 'neck_waist_length_back' in proof:
|
165 |
+
data['neck_waist_length_back'] = proof
|
166 |
+
elif 'neck_waist_length_front' in proof:
|
167 |
+
data['neck_waist_length_front'] = proof
|
168 |
+
elif 'pelvis_circumference' in proof:
|
169 |
+
data['pelvis_circumference'] = proof
|
170 |
+
elif 'shoulder_length' in proof:
|
171 |
+
data['shoulder_length'] = proof
|
172 |
+
elif 'shoulder_width' in proof:
|
173 |
+
data['shoulder_width'] = proof
|
174 |
+
elif 'thigh_circumference' in proof:
|
175 |
+
data['thigh_circumference'] = proof
|
176 |
+
elif 'under_chest_circumference' in proof:
|
177 |
+
data['under_chest_circumference'] = proof
|
178 |
+
elif 'upper_arm_length' in proof:
|
179 |
+
data['upper_arm_length'] = proof
|
180 |
+
elif 'waist_circumference' in proof:
|
181 |
+
data['waist_circumference'] = proof
|
182 |
+
|
183 |
+
yield idx, data
|