forked from yu4u/age-gender-estimation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.py
64 lines (50 loc) · 2.02 KB
/
create_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import numpy as np
import cv2
import scipy.io
import argparse
from tqdm import tqdm
from utils import get_meta
def get_args():
parser = argparse.ArgumentParser(description="This script cleans-up noisy labels "
"and creates database for training.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--output", "-o", type=str, required=True,
help="path to output database mat file")
parser.add_argument("--db", type=str, default="wiki",
help="dataset; wiki or imdb")
parser.add_argument("--img_size", type=int, default=32,
help="output image size")
parser.add_argument("--min_score", type=float, default=1.0,
help="minimum face_score")
args = parser.parse_args()
return args
def main():
args = get_args()
output_path = args.output
db = args.db
img_size = args.img_size
min_score = args.min_score
root_path = "data/{}_crop/".format(db)
mat_path = root_path + "{}.mat".format(db)
full_path, dob, gender, photo_taken, face_score, second_face_score, age = get_meta(mat_path, db)
out_genders = []
out_ages = []
out_imgs = []
for i in tqdm(range(len(face_score))):
if face_score[i] < min_score:
continue
if (~np.isnan(second_face_score[i])) and second_face_score[i] > 0.0:
continue
if ~(0 <= age[i] <= 100):
continue
if np.isnan(gender[i]):
continue
out_genders.append(int(gender[i]))
out_ages.append(age[i])
img = cv2.imread(root_path + str(full_path[i][0]))
out_imgs.append(cv2.resize(img, (img_size, img_size)))
output = {"image": np.array(out_imgs), "gender": np.array(out_genders), "age": np.array(out_ages),
"db": db, "img_size": img_size, "min_score": min_score}
scipy.io.savemat(output_path, output)
if __name__ == '__main__':
main()