Datasets:
refactor: script and readme
Browse files- README.md +70 -0
- portrait_and_26_photos.py +61 -26
README.md
CHANGED
|
@@ -7,6 +7,76 @@ language:
|
|
| 7 |
tags:
|
| 8 |
- finance
|
| 9 |
- code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# The Portrait and 26 Photos (272 people)
|
|
|
|
| 7 |
tags:
|
| 8 |
- finance
|
| 9 |
- code
|
| 10 |
+
dataset_info:
|
| 11 |
+
features:
|
| 12 |
+
- name: portrait_1
|
| 13 |
+
dtype: image
|
| 14 |
+
- name: photo_1
|
| 15 |
+
dtype: image
|
| 16 |
+
- name: photo_2
|
| 17 |
+
dtype: image
|
| 18 |
+
- name: photo_3
|
| 19 |
+
dtype: image
|
| 20 |
+
- name: photo_4
|
| 21 |
+
dtype: image
|
| 22 |
+
- name: photo_5
|
| 23 |
+
dtype: image
|
| 24 |
+
- name: photo_6
|
| 25 |
+
dtype: image
|
| 26 |
+
- name: photo_7
|
| 27 |
+
dtype: image
|
| 28 |
+
- name: photo_8
|
| 29 |
+
dtype: image
|
| 30 |
+
- name: photo_9
|
| 31 |
+
dtype: image
|
| 32 |
+
- name: photo_10
|
| 33 |
+
dtype: image
|
| 34 |
+
- name: photo_11
|
| 35 |
+
dtype: image
|
| 36 |
+
- name: photo_12
|
| 37 |
+
dtype: image
|
| 38 |
+
- name: photo_13
|
| 39 |
+
dtype: image
|
| 40 |
+
- name: photo_14
|
| 41 |
+
dtype: image
|
| 42 |
+
- name: photo_15
|
| 43 |
+
dtype: image
|
| 44 |
+
- name: photo_16
|
| 45 |
+
dtype: image
|
| 46 |
+
- name: photo_17
|
| 47 |
+
dtype: image
|
| 48 |
+
- name: photo_18
|
| 49 |
+
dtype: image
|
| 50 |
+
- name: photo_19
|
| 51 |
+
dtype: image
|
| 52 |
+
- name: photo_20
|
| 53 |
+
dtype: image
|
| 54 |
+
- name: photo_21
|
| 55 |
+
dtype: image
|
| 56 |
+
- name: photo_22
|
| 57 |
+
dtype: image
|
| 58 |
+
- name: photo_23
|
| 59 |
+
dtype: image
|
| 60 |
+
- name: photo_24
|
| 61 |
+
dtype: image
|
| 62 |
+
- name: photo_25
|
| 63 |
+
dtype: image
|
| 64 |
+
- name: photo_26
|
| 65 |
+
dtype: image
|
| 66 |
+
- name: worker_id
|
| 67 |
+
dtype: string
|
| 68 |
+
- name: age
|
| 69 |
+
dtype: int8
|
| 70 |
+
- name: country
|
| 71 |
+
dtype: string
|
| 72 |
+
- name: gender
|
| 73 |
+
dtype: string
|
| 74 |
+
splits:
|
| 75 |
+
- name: train
|
| 76 |
+
num_bytes: 927211725
|
| 77 |
+
num_examples: 14
|
| 78 |
+
download_size: 923699881
|
| 79 |
+
dataset_size: 927211725
|
| 80 |
---
|
| 81 |
|
| 82 |
# The Portrait and 26 Photos (272 people)
|
portrait_and_26_photos.py
CHANGED
|
@@ -3,7 +3,7 @@ import pandas as pd
|
|
| 3 |
|
| 4 |
_CITATION = """\
|
| 5 |
@InProceedings{huggingface:dataset,
|
| 6 |
-
title = {
|
| 7 |
author = {TrainingDataPro},
|
| 8 |
year = {2023}
|
| 9 |
}
|
|
@@ -14,7 +14,7 @@ An example of a dataset that we've collected for a photo edit App.
|
|
| 14 |
The dataset includes 20 selfies of people (man and women)
|
| 15 |
in segmentation masks and their visualisations.
|
| 16 |
"""
|
| 17 |
-
_NAME = '
|
| 18 |
|
| 19 |
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
| 20 |
|
|
@@ -30,11 +30,37 @@ class FaceSegmentation(datasets.GeneratorBasedBuilder):
|
|
| 30 |
return datasets.DatasetInfo(
|
| 31 |
description=_DESCRIPTION,
|
| 32 |
features=datasets.Features({
|
| 33 |
-
'
|
| 34 |
-
'
|
| 35 |
-
'
|
| 36 |
-
'
|
| 37 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}),
|
| 39 |
supervised_keys=None,
|
| 40 |
homepage=_HOMEPAGE,
|
|
@@ -43,34 +69,43 @@ class FaceSegmentation(datasets.GeneratorBasedBuilder):
|
|
| 43 |
|
| 44 |
def _split_generators(self, dl_manager):
|
| 45 |
images = dl_manager.download(f"{_DATA}images.tar.gz")
|
| 46 |
-
masks = dl_manager.download(f"{_DATA}masks.tar.gz")
|
| 47 |
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
| 48 |
images = dl_manager.iter_archive(images)
|
| 49 |
-
masks = dl_manager.iter_archive(masks)
|
| 50 |
return [
|
| 51 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
| 52 |
gen_kwargs={
|
| 53 |
"images": images,
|
| 54 |
-
'masks': masks,
|
| 55 |
'annotations': annotations
|
| 56 |
}),
|
| 57 |
]
|
| 58 |
|
| 59 |
-
def _generate_examples(self, images,
|
| 60 |
-
annotations_df = pd.read_csv(annotations, sep='
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
},
|
| 73 |
-
'id': annotations_df['id'].iloc[idx],
|
| 74 |
-
'gender': annotations_df['gender'].iloc[idx],
|
| 75 |
-
'age': annotations_df['age'].iloc[idx]
|
| 76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
_CITATION = """\
|
| 5 |
@InProceedings{huggingface:dataset,
|
| 6 |
+
title = {portrait_and_26_photos},
|
| 7 |
author = {TrainingDataPro},
|
| 8 |
year = {2023}
|
| 9 |
}
|
|
|
|
| 14 |
The dataset includes 20 selfies of people (man and women)
|
| 15 |
in segmentation masks and their visualisations.
|
| 16 |
"""
|
| 17 |
+
_NAME = 'portrait_and_26_photos'
|
| 18 |
|
| 19 |
_HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
|
| 20 |
|
|
|
|
| 30 |
return datasets.DatasetInfo(
|
| 31 |
description=_DESCRIPTION,
|
| 32 |
features=datasets.Features({
|
| 33 |
+
'portrait_1': datasets.Image(),
|
| 34 |
+
'photo_1': datasets.Image(),
|
| 35 |
+
'photo_2': datasets.Image(),
|
| 36 |
+
'photo_3': datasets.Image(),
|
| 37 |
+
'photo_4': datasets.Image(),
|
| 38 |
+
'photo_5': datasets.Image(),
|
| 39 |
+
'photo_6': datasets.Image(),
|
| 40 |
+
'photo_7': datasets.Image(),
|
| 41 |
+
'photo_8': datasets.Image(),
|
| 42 |
+
'photo_9': datasets.Image(),
|
| 43 |
+
'photo_10': datasets.Image(),
|
| 44 |
+
'photo_11': datasets.Image(),
|
| 45 |
+
'photo_12': datasets.Image(),
|
| 46 |
+
'photo_13': datasets.Image(),
|
| 47 |
+
'photo_14': datasets.Image(),
|
| 48 |
+
'photo_15': datasets.Image(),
|
| 49 |
+
'photo_16': datasets.Image(),
|
| 50 |
+
'photo_17': datasets.Image(),
|
| 51 |
+
'photo_18': datasets.Image(),
|
| 52 |
+
'photo_19': datasets.Image(),
|
| 53 |
+
'photo_20': datasets.Image(),
|
| 54 |
+
'photo_21': datasets.Image(),
|
| 55 |
+
'photo_22': datasets.Image(),
|
| 56 |
+
'photo_23': datasets.Image(),
|
| 57 |
+
'photo_24': datasets.Image(),
|
| 58 |
+
'photo_25': datasets.Image(),
|
| 59 |
+
'photo_26': datasets.Image(),
|
| 60 |
+
'worker_id': datasets.Value('string'),
|
| 61 |
+
'age': datasets.Value('int8'),
|
| 62 |
+
'country': datasets.Value('string'),
|
| 63 |
+
'gender': datasets.Value('string')
|
| 64 |
}),
|
| 65 |
supervised_keys=None,
|
| 66 |
homepage=_HOMEPAGE,
|
|
|
|
| 69 |
|
| 70 |
def _split_generators(self, dl_manager):
|
| 71 |
images = dl_manager.download(f"{_DATA}images.tar.gz")
|
|
|
|
| 72 |
annotations = dl_manager.download(f"{_DATA}{_NAME}.csv")
|
| 73 |
images = dl_manager.iter_archive(images)
|
|
|
|
| 74 |
return [
|
| 75 |
datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
| 76 |
gen_kwargs={
|
| 77 |
"images": images,
|
|
|
|
| 78 |
'annotations': annotations
|
| 79 |
}),
|
| 80 |
]
|
| 81 |
|
| 82 |
+
def _generate_examples(self, images, annotations):
|
| 83 |
+
annotations_df = pd.read_csv(annotations, sep=',')
|
| 84 |
+
images_data = pd.DataFrame(columns=['Link', 'Bytes'])
|
| 85 |
+
for idx, (image_path, image) in enumerate(images):
|
| 86 |
+
images_data.loc[idx] = {'Link': image_path, 'Bytes': image.read()}
|
| 87 |
|
| 88 |
+
annotations_df = pd.merge(annotations_df, images_data)
|
| 89 |
+
for idx, worker_id in enumerate(pd.unique(annotations_df['WorkerId'])):
|
| 90 |
+
annotation = annotations_df.loc[annotations_df['WorkerId'] ==
|
| 91 |
+
worker_id]
|
| 92 |
+
annotation = annotation.sort_values(['Type'])
|
| 93 |
+
data = {
|
| 94 |
+
row[5]: {
|
| 95 |
+
'path': row[6],
|
| 96 |
+
'bytes': row[7]
|
| 97 |
+
} for row in annotation.itertuples()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
+
|
| 100 |
+
age = annotation.loc[annotation['Type'] ==
|
| 101 |
+
'portrait_1']['Age'].values[0]
|
| 102 |
+
country = annotation.loc[annotation['Type'] ==
|
| 103 |
+
'portrait_1']['Country'].values[0]
|
| 104 |
+
gender = annotation.loc[annotation['Type'] ==
|
| 105 |
+
'portrait_1']['Gender'].values[0]
|
| 106 |
+
|
| 107 |
+
data['worker_id'] = worker_id
|
| 108 |
+
data['age'] = age
|
| 109 |
+
data['country'] = country
|
| 110 |
+
data['gender'] = gender
|
| 111 |
+
yield idx, data
|