import json from pathlib import Path import datasets import numpy as np import pandas as pd import PIL.Image import PIL.ImageOps _CITATION = """\ @InProceedings{huggingface:dataset, title = {body-measurements-dataset}, author = {TrainingDataPro}, year = {2023} } """ _DESCRIPTION = """\ The dataset consists of a compilation of people's photos along with their corresponding body measurements. It is designed to provide information and insights into the physical appearances and body characteristics of individuals. The dataset includes a diverse range of subjects representing different age groups, genders, and ethnicities. The photos are captured in a standardized manner, depicting individuals in a front and side positions. The images aim to capture the subjects' physical appearance using appropriate lighting and angles that showcase their body proportions accurately. The dataset serves various purposes, including: - research projects - body measurement analysis - fashion or apparel industry applications - fitness and wellness studies - anthropometric studies for ergonomic design in various fields """ _NAME = 'body-measurements-dataset' _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}" _LICENSE = "cc-by-nc-nd-4.0" _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/" class BodyMeasurementsDataset(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features({ 'front_img': datasets.Image(), 'selfie_img': datasets.Image(), 'side_img': datasets.Image(), "arm_circumference_cm": datasets.Value('string'), "arm_length_cm": datasets.Value('string'), "back_build_cm": datasets.Value('string'), "calf_circumference_cm": datasets.Value('string'), "chest_circumference_cm": datasets.Value('string'), "crotch_height_cm": datasets.Value('string'), "front_build_cm": datasets.Value('string'), "hips_circumference_cm": datasets.Value('string'), "leg_length_cm": datasets.Value('string'), "neck_circumference_cm": datasets.Value('string'), "neck_pelvis_length_front_cm": datasets.Value('string'), "neck_waist_length_back_cm": datasets.Value('string'), "neck_waist_length_front_cm": datasets.Value('string'), "pelvis_circumference_cm": datasets.Value('string'), "shoulder_length_cm": datasets.Value('string'), "shoulder_width_cm": datasets.Value('string'), "thigh_circumference_cm": datasets.Value('string'), "under_chest_circumference_cm": datasets.Value('string'), "upper_arm_length_cm": datasets.Value('string'), "waist_circumference_cm": datasets.Value('string'), "height": datasets.Value('string'), "weight": datasets.Value('string'), "age": datasets.Value('string'), "gender": datasets.Value('string'), "race": datasets.Value('string'), "profession": datasets.Value('string'), "arm_circumference": datasets.Image(), "arm_length": datasets.Image(), "back_build": datasets.Image(), "calf_circumference": datasets.Image(), "chest_circumference": datasets.Image(), "crotch_height": datasets.Image(), "front_build": datasets.Image(), "hips_circumference": datasets.Image(), "leg_length": datasets.Image(), "neck_circumference": datasets.Image(), "neck_pelvis_length_front": datasets.Image(), "neck_waist_length_back": datasets.Image(), "neck_waist_length_front": datasets.Image(), "pelvis_circumference": datasets.Image(), "shoulder_length": datasets.Image(), "shoulder_width": datasets.Image(), "thigh_circumference": datasets.Image(), "under_chest_circumference": datasets.Image(), "upper_arm_length": datasets.Image(), "waist_circumference": datasets.Image() }), supervised_keys=None, homepage=_HOMEPAGE, citation=_CITATION, license=_LICENSE) def _split_generators(self, dl_manager): files = dl_manager.download_and_extract(f"{_DATA}files.zip") proofs = dl_manager.download_and_extract(f"{_DATA}proofs.zip") annotations = dl_manager.download(f"{_DATA}{_NAME}.csv") files = dl_manager.iter_files(files) proofs = dl_manager.iter_files(proofs) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={ "files": files, 'proofs': proofs, 'annotations': annotations }), ] def _generate_examples(self, files, proofs, annotations): files = list(files) files = [files[i:i + 4] for i in range(0, len(files), 4)] proofs = list(proofs) proofs = [proofs[i:i + 20] for i in range(0, len(proofs), 20)] for idx, (files_dir, proofs_dir) in enumerate(zip(files, proofs)): data = {} for file in files_dir: if 'front_img' in file: data['front_img'] = file elif 'selfie_img' in file: data['selfie_img'] = file elif 'side_img' in file: data['side_img'] = file elif 'measurements' in file: with open(file) as f: data.update(json.load(f)) for proof in proofs_dir: if "arm_circumference" in proof: data['arm_circumference'] = proof elif 'upper_arm_length' in proof: data['upper_arm_length'] = proof elif 'arm_length' in proof: data['arm_length'] = proof elif 'back_build' in proof: data['back_build'] = proof elif 'calf_circumference' in proof: data['calf_circumference'] = proof elif 'under_chest_circumference' in proof: data['under_chest_circumference'] = proof elif 'chest_circumference' in proof: data['chest_circumference'] = proof elif 'crotch_height' in proof: data['crotch_height'] = proof elif 'front_build' in proof: data['front_build'] = proof elif 'hips_circumference' in proof: data['hips_circumference'] = proof elif 'leg_length' in proof: data['leg_length'] = proof elif 'neck_circumference' in proof: data['neck_circumference'] = proof elif 'neck_pelvis_length_front' in proof: data['neck_pelvis_length_front'] = proof elif 'neck_waist_length_back' in proof: data['neck_waist_length_back'] = proof elif 'neck_waist_length_front' in proof: data['neck_waist_length_front'] = proof elif 'pelvis_circumference' in proof: data['pelvis_circumference'] = proof elif 'shoulder_length' in proof: data['shoulder_length'] = proof elif 'shoulder_width' in proof: data['shoulder_width'] = proof elif 'thigh_circumference' in proof: data['thigh_circumference'] = proof elif 'waist_circumference' in proof: data['waist_circumference'] = proof yield idx, data