|
import datasets |
|
import pandas as pd |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {portrait_and_26_photos}, |
|
author = {TrainingDataPro}, |
|
year = {2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Each set includes 27 photos of people. Each person provided |
|
two types of photos: one photo in profile (portrait_1), |
|
and 26 photos from their life (photo_1, photo_2, …, photo_26). |
|
""" |
|
_NAME = 'portrait_and_26_photos' |
|
|
|
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}" |
|
|
|
_LICENSE = "" |
|
|
|
_DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/" |
|
|
|
|
|
class PortraitAnd26Photos(datasets.GeneratorBasedBuilder): |
|
"""Small sample of image-text pairs""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({ |
|
'portrait_1': datasets.Image(), |
|
'photo_1': datasets.Image(), |
|
'photo_2': datasets.Image(), |
|
'photo_3': datasets.Image(), |
|
'photo_4': datasets.Image(), |
|
'photo_5': datasets.Image(), |
|
'photo_6': datasets.Image(), |
|
'photo_7': datasets.Image(), |
|
'photo_8': datasets.Image(), |
|
'photo_9': datasets.Image(), |
|
'photo_10': datasets.Image(), |
|
'photo_11': datasets.Image(), |
|
'photo_12': datasets.Image(), |
|
'photo_13': datasets.Image(), |
|
'photo_14': datasets.Image(), |
|
'photo_15': datasets.Image(), |
|
'photo_16': datasets.Image(), |
|
'photo_17': datasets.Image(), |
|
'photo_18': datasets.Image(), |
|
'photo_19': datasets.Image(), |
|
'photo_20': datasets.Image(), |
|
'photo_21': datasets.Image(), |
|
'photo_22': datasets.Image(), |
|
'photo_23': datasets.Image(), |
|
'photo_24': datasets.Image(), |
|
'photo_25': datasets.Image(), |
|
'photo_26': datasets.Image(), |
|
'worker_id': datasets.Value('string'), |
|
'age': datasets.Value('int8'), |
|
'country': datasets.Value('string'), |
|
'gender': datasets.Value('string') |
|
}), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
images = dl_manager.download(f"{_DATA}images.tar.gz") |
|
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv") |
|
images = dl_manager.iter_archive(images) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"images": images, |
|
'annotations': annotations |
|
}), |
|
] |
|
|
|
def _generate_examples(self, images, annotations): |
|
annotations_df = pd.read_csv(annotations, sep=',') |
|
images_data = pd.DataFrame(columns=['Link', 'Bytes']) |
|
for idx, (image_path, image) in enumerate(images): |
|
images_data.loc[idx] = {'Link': image_path, 'Bytes': image.read()} |
|
|
|
annotations_df = pd.merge(annotations_df, images_data) |
|
for idx, worker_id in enumerate(pd.unique(annotations_df['WorkerId'])): |
|
annotation = annotations_df.loc[annotations_df['WorkerId'] == |
|
worker_id] |
|
annotation = annotation.sort_values(['Type']) |
|
data = { |
|
row[5]: { |
|
'path': row[6], |
|
'bytes': row[7] |
|
} for row in annotation.itertuples() |
|
} |
|
|
|
age = annotation.loc[annotation['Type'] == |
|
'portrait_1']['Age'].values[0] |
|
country = annotation.loc[annotation['Type'] == |
|
'portrait_1']['Country'].values[0] |
|
gender = annotation.loc[annotation['Type'] == |
|
'portrait_1']['Gender'].values[0] |
|
|
|
data['worker_id'] = worker_id |
|
data['age'] = age |
|
data['country'] = country |
|
data['gender'] = gender |
|
|
|
yield idx, data |
|
|