refactor: script
Browse files- face_masks.py +11 -20
face_masks.py
CHANGED
@@ -94,7 +94,6 @@ class FaceMasks(datasets.GeneratorBasedBuilder):
|
|
94 |
'photo_2': datasets.Image(),
|
95 |
'photo_3': datasets.Image(),
|
96 |
'photo_4': datasets.Image(),
|
97 |
-
'selfie_5': datasets.Image(),
|
98 |
'worker_id': datasets.Value('string'),
|
99 |
'age': datasets.Value('int8'),
|
100 |
'country': datasets.Value('string'),
|
@@ -121,8 +120,10 @@ class FaceMasks(datasets.GeneratorBasedBuilder):
|
|
121 |
annotations_df = pd.read_csv(annotations, sep=',')
|
122 |
images_data = pd.DataFrame(columns=['Link', 'Image'])
|
123 |
for idx, image_path in enumerate(images):
|
124 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
annotations_df = pd.merge(annotations_df,
|
128 |
images_data,
|
@@ -133,28 +134,18 @@ class FaceMasks(datasets.GeneratorBasedBuilder):
|
|
133 |
annotations_df['WorkerId'] == worker_id]
|
134 |
annotation = annotation.sort_values(['Link'])
|
135 |
data = {
|
136 |
-
f'photo_{row[
|
|
|
137 |
}
|
138 |
|
139 |
-
age = annotation.loc[annotation['
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
gender = annotation.loc[annotation['FName'] ==
|
144 |
-
'ID_1']['Gender'].values[0]
|
145 |
-
set_id = annotation.loc[annotation['FName'] ==
|
146 |
-
'ID_1']['SetId'].values[0]
|
147 |
-
user_race = annotation.loc[annotation['FName'] ==
|
148 |
-
'ID_1']['UserRace'].values[0]
|
149 |
-
name = annotation.loc[annotation['FName'] ==
|
150 |
-
'ID_1']['Name'].values[0]
|
151 |
|
152 |
data['user_id'] = worker_id
|
153 |
data['age'] = age
|
154 |
data['country'] = country
|
155 |
-
data['
|
156 |
-
data['set_id'] = set_id
|
157 |
-
data['user_race'] = user_race
|
158 |
-
data['name'] = name
|
159 |
|
160 |
yield idx, data
|
|
|
94 |
'photo_2': datasets.Image(),
|
95 |
'photo_3': datasets.Image(),
|
96 |
'photo_4': datasets.Image(),
|
|
|
97 |
'worker_id': datasets.Value('string'),
|
98 |
'age': datasets.Value('int8'),
|
99 |
'country': datasets.Value('string'),
|
|
|
120 |
annotations_df = pd.read_csv(annotations, sep=',')
|
121 |
images_data = pd.DataFrame(columns=['Link', 'Image'])
|
122 |
for idx, image_path in enumerate(images):
|
123 |
+
images_data.loc[idx] = {
|
124 |
+
'Link': '/'.join(image_path.split('/')[-2:]),
|
125 |
+
'Path': image_path
|
126 |
+
}
|
127 |
|
128 |
annotations_df = pd.merge(annotations_df,
|
129 |
images_data,
|
|
|
134 |
annotations_df['WorkerId'] == worker_id]
|
135 |
annotation = annotation.sort_values(['Link'])
|
136 |
data = {
|
137 |
+
f'photo_{row[5]}': load_image_file(row[7])
|
138 |
+
for row in annotation.itertuples()
|
139 |
}
|
140 |
|
141 |
+
age = annotation.loc[annotation['Type'] == '1']['Age'].values[0]
|
142 |
+
country = annotation.loc[annotation['Type'] ==
|
143 |
+
'1']['Country'].values[0]
|
144 |
+
sex = annotation.loc[annotation['Type'] == '1']['Sex'].values[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
data['user_id'] = worker_id
|
147 |
data['age'] = age
|
148 |
data['country'] = country
|
149 |
+
data['sex'] = sex
|
|
|
|
|
|
|
150 |
|
151 |
yield idx, data
|