vkashko commited on
Commit
64d2476
·
1 Parent(s): e5572f0

refactor: script

Browse files
Files changed (1) hide show
  1. selfie_and_video.py +34 -43
selfie_and_video.py CHANGED
@@ -1,22 +1,22 @@
1
- import io
2
-
3
  import datasets
4
  import pandas as pd
5
 
6
  _CITATION = """\
7
  @InProceedings{huggingface:dataset,
8
- title = {portrait_and_26_photos},
9
  author = {TrainingDataPro},
10
  year = {2023}
11
  }
12
  """
13
 
14
  _DESCRIPTION = """\
15
- Each set includes 27 photos of people. Each person provided
16
- two types of photos: one photo in profile (portrait_1),
17
- and 26 photos from their life (photo_1, photo_2, …, photo_26).
 
 
18
  """
19
- _NAME = 'portrait_and_26_photos'
20
 
21
  _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
22
 
@@ -25,40 +25,22 @@ _LICENSE = ""
25
  _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
26
 
27
 
28
- class PortraitAnd26Photos(datasets.GeneratorBasedBuilder):
29
  """Small sample of image-text pairs"""
30
 
31
  def _info(self):
32
  return datasets.DatasetInfo(
33
  description=_DESCRIPTION,
34
  features=datasets.Features({
35
- 'portrait_1': datasets.Image(),
36
  'photo_1': datasets.Image(),
37
  'photo_2': datasets.Image(),
38
- 'photo_3': datasets.Image(),
39
- 'photo_4': datasets.Image(),
40
  'photo_5': datasets.Image(),
41
  'photo_6': datasets.Image(),
42
- 'photo_7': datasets.Image(),
43
- 'photo_8': datasets.Image(),
44
- 'photo_9': datasets.Image(),
45
- 'photo_10': datasets.Image(),
46
- 'photo_11': datasets.Image(),
47
- 'photo_12': datasets.Image(),
48
- 'photo_13': datasets.Image(),
49
- 'photo_14': datasets.Image(),
50
- 'photo_15': datasets.Image(),
51
- 'photo_16': datasets.Image(),
52
- 'photo_17': datasets.Image(),
53
- 'photo_18': datasets.Image(),
54
- 'photo_19': datasets.Image(),
55
- 'photo_20': datasets.Image(),
56
- 'photo_21': datasets.Image(),
57
- 'photo_22': datasets.Image(),
58
- 'photo_23': datasets.Image(),
59
- 'photo_24': datasets.Image(),
60
- 'photo_25': datasets.Image(),
61
- 'photo_26': datasets.Image(),
62
  'worker_id': datasets.Value('string'),
63
  'age': datasets.Value('int8'),
64
  'country': datasets.Value('string'),
@@ -85,30 +67,39 @@ class PortraitAnd26Photos(datasets.GeneratorBasedBuilder):
85
  annotations_df = pd.read_csv(annotations, sep=',')
86
  images_data = pd.DataFrame(columns=['Link', 'Bytes'])
87
  for idx, (image_path, image) in enumerate(images):
88
- images_data.loc[idx] = {'Link': image_path, 'Bytes': image.read()}
 
 
 
 
89
 
90
  annotations_df = pd.merge(annotations_df, images_data)
91
  for idx, worker_id in enumerate(pd.unique(annotations_df['WorkerId'])):
92
  annotation = annotations_df.loc[annotations_df['WorkerId'] ==
93
  worker_id]
94
- annotation = annotation.sort_values(['Type'])
95
  data = {
96
- row[5]: {
97
- 'path': row[6],
98
- 'bytes': row[7]
99
- } for row in annotation.itertuples()
 
 
100
  }
101
 
102
- age = annotation.loc[annotation['Type'] ==
103
- 'portrait_1']['Age'].values[0]
104
- country = annotation.loc[annotation['Type'] ==
105
- 'portrait_1']['Country'].values[0]
106
- gender = annotation.loc[annotation['Type'] ==
107
- 'portrait_1']['Gender'].values[0]
 
 
108
 
109
  data['worker_id'] = worker_id
110
  data['age'] = age
111
  data['country'] = country
112
  data['gender'] = gender
 
113
 
114
  yield idx, data
 
 
 
1
  import datasets
2
  import pandas as pd
3
 
4
  _CITATION = """\
5
  @InProceedings{huggingface:dataset,
6
+ title = {selfie_and_video},
7
  author = {TrainingDataPro},
8
  year = {2023}
9
  }
10
  """
11
 
12
  _DESCRIPTION = """\
13
+ 4000 people in this dataset. Each person took a selfie on a webcam,
14
+ took a selfie on a mobile phone. In addition, people recorded video from
15
+ the phone and from the webcam, on which they pronounced a given set of numbers.
16
+ Includes folders corresponding to people in the dataset. Each folder includes
17
+ 8 files (4 images and 4 videos).
18
  """
19
+ _NAME = 'selfie_and_video'
20
 
21
  _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}"
22
 
 
25
  _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/"
26
 
27
 
28
+ class SelfieAndVideo(datasets.GeneratorBasedBuilder):
29
  """Small sample of image-text pairs"""
30
 
31
  def _info(self):
32
  return datasets.DatasetInfo(
33
  description=_DESCRIPTION,
34
  features=datasets.Features({
 
35
  'photo_1': datasets.Image(),
36
  'photo_2': datasets.Image(),
37
+ 'video_3': datasets.Value('string'),
38
+ 'video_4': datasets.Value('string'),
39
  'photo_5': datasets.Image(),
40
  'photo_6': datasets.Image(),
41
+ 'video_7': datasets.Value('string'),
42
+ 'video_8': datasets.Value('string'),
43
+ 'set_id': datasets.Value('string'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  'worker_id': datasets.Value('string'),
45
  'age': datasets.Value('int8'),
46
  'country': datasets.Value('string'),
 
67
  annotations_df = pd.read_csv(annotations, sep=',')
68
  images_data = pd.DataFrame(columns=['Link', 'Bytes'])
69
  for idx, (image_path, image) in enumerate(images):
70
+ if image_path.lower().endswith('.jpg'):
71
+ images_data.loc[idx] = {
72
+ 'Link': image_path,
73
+ 'Bytes': image.read()
74
+ }
75
 
76
  annotations_df = pd.merge(annotations_df, images_data)
77
  for idx, worker_id in enumerate(pd.unique(annotations_df['WorkerId'])):
78
  annotation = annotations_df.loc[annotations_df['WorkerId'] ==
79
  worker_id]
80
+ annotation = annotation.sort_values(['Link'])
81
  data = {
82
+ (f'photo_{row[6][37]}' if row[6].lower().endswith('.jpg') else f'video_{row[6][37]}'):
83
+ ({
84
+ 'path': row[6],
85
+ 'bytes': row[7]
86
+ } if row[6].lower().endswith('.jpg') else row[6])
87
+ for row in annotation.itertuples()
88
  }
89
 
90
+ age = annotation.loc[annotation['Link'].endswith(
91
+ '1.jpg')]['Age'].values[0]
92
+ country = annotation.loc[annotation['Link'].endswith(
93
+ '1.jpg')]['Country'].values[0]
94
+ gender = annotation.loc[annotation['Link'].endswith(
95
+ '1.jpg')]['Gender'].values[0]
96
+ set_id = annotation.loc[annotation['Link'].endswith(
97
+ '1.jpg')]['SetId'].values[0]
98
 
99
  data['worker_id'] = worker_id
100
  data['age'] = age
101
  data['country'] = country
102
  data['gender'] = gender
103
+ data['set_id'] = set_id
104
 
105
  yield idx, data