def get_faces_with_ids(path_to_db, verbose=False): face_id_multiple_pattern = re.compile(".+[1-9]+\.[a-z]{3}") faces = [] for root, dirs, _ in os.walk(path_to_db): for dir in dirs: path_to_subject = os.path.join(path_to_db, dir) for _, _, imgs in os.walk(path_to_subject): for img_file in imgs: if verbose: print('Processing subject {} => {}'.format( dir, img_file)) if face_id_multiple_pattern.match(img_file) is not None: continue try: face = Face.from_image_path_with_id( os.path.join(path_to_subject, img_file), dir) except Exception as e: face = None if verbose: print(e.message) if face is not None: faces.append(face) break break return faces
def get_faces_with_ids(path_to_db, verbose=False): face_id_multiple_pattern = re.compile(".+[1-9]+\.[a-z]{3}") faces = [] identities = 0 faces_per_identity = [] for root, dirs, _ in os.walk(path_to_db): for dir in dirs: path_to_subject = os.path.join(path_to_db, dir) # we sample the data so that we take 30 photos from 3% of the faces in an random way so that the # distribution it is kept if random.random() <= 0.96: continue identities += 1 faces_taken = 0 for _, _, imgs in os.walk(path_to_subject): for img_file in imgs: if random.random() > 0.3: continue faces_taken += 1 if verbose: print("Processing subject {} => {}".format(dir, img_file)) if face_id_multiple_pattern.match(img_file) is not None: continue try: face = Face.from_image_path_with_id( os.path.join(path_to_subject, img_file), dir ) except Exception as e: face = None if verbose: print(e.message) if face is not None: faces.append(face) break faces_per_identity.append(faces_taken) break print("We randomly selected " + str(identities)) print( "With an average of faces per identity of: " + str(sum(faces_per_identity) / len(faces_per_identity)) ) print("With same identity faces {}".format(sum(faces_per_identity))) perechi_fete_identice = 0 for i in range(len(faces_per_identity)): perechi_fete_identice += faces_per_identity[i] * (faces_per_identity[i] - 1) / 2 print("Number of pairs same identity {}".format(perechi_fete_identice)) print("Number of faces {}".format(len(faces_per_identity))) print(faces_per_identity) print("Totalling {}".format(len(faces))) return faces