def __build_model(auth_params, func_params): """ This script has been defined in order to build (or update) a face recognition model for a specific person based on a set of instances previously extracted and saved. The object representation of the model must already exist. """ token = auth_params.get('token', '1234') model_id = func_params.get('id', 0) # retrieve the entity model object if exists model = get_model(model_id, token) if model is None: raise Exception('The provided model id is not valid!') # retrieve all instances associated to the model instances = get_instances_by_model(model_id, token)['results'] inst_paths = [] for inst in instances: inst_paths.append(os.path.join(get_media_root(), inst['features'])) fm = FaceModels() model_file_path = fm.create_model_from_image_list(aligned_faces_list) tsm.set_model_file(model_id, model_file_path, token=token)
def update_face_model(auth_dict, param_dict): """ Function used to update global face models used as training set for people recognition. :param auth_dict: Input parameters provided by the trigger Action :param param_dict: Output parameters returned by the trigger Action """ # Get instances associated to model model_id = param_dict['id'] instances = tsm.get_instances_by_model(model_id, auth_params['token']) # Get aligned faces from instances aligned_faces_list = [] for instance in instances: aligned_face_path = instance['features'] aligned_faces_list.append(aligned_face_path) fm = FaceModels() model_file_path = fm.create_model_from_image_list(aligned_faces_list) tsm.set_model_file(model_id, model_file_path, auth_params['token'])