python - Sort images based on age -
i'm using following code load imdb dataset , mat file isolate them based on ages. following code loads mat file , computes age subtracting data in photo taken date of birth
from scipy.io import loadmat datetime import datetime import os import numpy np shutil import copy db = "imdb" mat_path = "data/{}_crop/{}.mat".format(db, db) print (mat_path) dataset = loadmat(mat_path) face_score_treshold = 3 path_root = "data/{}_crop/".format(db) def calc_age(taken, dob): birth = datetime.fromordinal(max(int(dob) - 366, 1)) # assume photo taken in middle of year if birth.month < 7: return taken - birth.year else: return taken - birth.year - 1 image_names_array = dataset['imdb']['full_path'][0, 0][0] dob = dataset[db][0, 0]["dob"][0] # matlab serial date number photo_taken = dataset[db][0, 0]["photo_taken"][0] # year image_names = [] age = [calc_age(photo_taken[i], dob[i]) in range(len(dob))] print(age) image_name_arg in range(image_names_array.shape[0]): try: os.makedirs(str (age[image_name_arg])) except oserror: pass copy(path_root + "/" + str(image_names_array[image_name_arg][0]),str (age[image_name_arg])) image_name = image_names_array[image_name_arg][0] image_names.append(image_name) print( dict(zip(image_names, age)))
after calculating age, creates folder age folder name , copies image files folder.
however there lots of false negatives in resulting folder. how can able sort out?
Comments
Post a Comment