Example #1
0
File: utils.py Project: crs4/ACTIVE
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)
Example #2
0
File: utils.py Project: crs4/ACTIVE
def __build_model(auth_params, func_params):
    """
    Funzione utilizzata per costruire il modello di riconoscimento audio
    a partire da un insieme di istanze che vengono fornite dall'utente
    attraverso l'apposita GUI.
    In particolar ela funzione consente di :
    - ottenere la lista di istanze specificate dall'utente
    - recuperare il path completo associato a ciascuna istanza
    - unire le istanze in un unico file audio
    - effettuare la costruzione del modello di riconoscimento vocale
    - creare la persona e il modello sul database
    - associare i file creati alla persona e al modello
    - rimuovere tutti i file temporanei creati
    """
    try:
        token    = auth_params.get('token', '1234')
        f_name   = func_params.get('first_name', 'Pinco')
        s_name   = func_params.get('last_name',  'Pallino')
        inst_ids = func_params.get('inst_list', [])
        ubm      = os.path.join(get_media_root(), 'models', 'audio', 'globals', 'ubm.gmm')
        classpath= os.path.join(get_base_dir(), 'plugins_script', 'speaker_extractor' , 'lium_spkdiarization-8.4.1.jar')

        # crea un modello e una persona con i dati forniti
        person = create_person(f_name, s_name, token=token)
        model  = create_model(person['id'], 'audio', f_name + ' ' + s_name, last_update=None, token=token)
        #print person, model
        
        # recupera gli oggetti corrispondenti alle istanze
        #print inst_ids
        inst_paths = []
        for inst_id in inst_ids:
            inst = get_instance(inst_id, token=token)
            inst_paths.append(os.path.join(get_media_root(), inst['features']))
        #print inst_paths

        # concat all provided feature files
        temp = '/tmp/model_' + str(model['id']) + '.wav'
        concatena_multi(inst_paths, temp)
        #print temp

        # calcola e imposta il modello generato nel database
        model_path = create_new_model(classpath, ubm, temp, 0, None, None)
        set_model_file(model['id'], model_path, token=token)
        #print model_path

        # remove all created temporary files
        #os.remove(model_path)
        
    except Exception as e:
        print e
        return 'Error during entity model building'
Example #3
0
File: utils.py Project: crs4/ACTIVE
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'])